1.\" Copyright (c) 2015 The DragonFly Project. All rights reserved. 2.\" 3.\" This code is derived from software contributed to The DragonFly Project 4.\" by Matthew Dillon <dillon@backplane.com> 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in 14.\" the documentation and/or other materials provided with the 15.\" distribution. 16.\" 3. Neither the name of The DragonFly Project nor the names of its 17.\" contributors may be used to endorse or promote products derived 18.\" from this software without specific, prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 26.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 30.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" SUCH DAMAGE. 32.\" 33.Dd January 1, 2015 34.Dt SSHLOCKOUT 8 35.Os 36.Sh NAME 37.Nm sshlockout 38.Nd utility to block port 22 on preauth failures 39.Sh SYNOPSIS 40.Cd # in /etc/pf.conf 41.Cd # 42.Cd table <lockout> persist { } 43.Pp 44.Cd # and later in /etc/pf.conf - see below 45.Cd # 46.Cd block in quick on $ext_if proto tcp from <lockout> to any port 22 47.Cd block in quick on $ext_if proto tcp from <lockout> to any port 22 48.Pp 49.Cd # in /etc/syslog.conf 50.Cd # 51.Cd auth.info;authpriv.info |exec /usr/sbin/sshlockout -pf "lockout" 52.Pp 53.Cd # in root's crontab 54.Cd # 55.Cd 3 3 * * * pfctl -tlockout -T expire 86400 56.Sh DESCRIPTION 57This program is generally installed in 58.Pa /etc/syslog.conf 59as a pipe to parse the 60.Xr sshd 8 61demons error log in realtime. 62In addition, a root crontab entry should generally be created to clean 63out stale entries in the 64.Xr pf 4 65.Ar table 66at least once a day. 67Using expire instead of flush will maintain a rolling window of locked out 68IPs. 69The 70.Xr pf 4 71module must be loaded and running with the table and rules properly 72configured. 73.Pp 74This program will monitor the ssh syslog output and keep track of attempts 75to login to unknown users as well as preauth failures. 76If 5 attempts fail in any one hour period, a permanent entry is added to the 77.Xr pf 4 78.Ar table 79for the associated IP address. 80You still have to add a rule to 81.Xr pf.conf 5 82to block IP addresses listed in this table. 83The cron entry you create cleans the block list out typically once a day. 84.Pp 85This program generally limits brute-force attempts to break into a machine 86via ssh. 87.Pp 88When setting up the PF rules, note that the table will be filled based on 89failed ssh connections destined to that particular machine. If the machine 90is acting as a router you can decide whether you want the PF rule to lockout 91that suspect IP to just the machine, or to everything it routes to. We 92usually recommend an unconditional blocking rule. 93.Sh NOTICE 94This program is still a work in progress. 95.Sh SEE ALSO 96.Xr ssh 1 , 97.Xr pf 4 , 98.Xr syslog.conf 5 , 99.Xr sshd 8 100.Sh HISTORY 101The 102.Nm 103utility first appeared in 104.Dx 4.1 . 105.Sh AUTHORS 106.An Matthew Dillon Aq Mt dillon@backplane.com 107