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 September 13, 2017
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.Bd -literal
41#
42# pf(4) configuration.
43#
44
45# in /etc/pf.conf
46#
47table <lockout> persist { }
48
49# and later in /etc/pf.conf - see below
50#
51block in quick on $ext_if proto tcp from <lockout> to any port 22
52
53# in /etc/syslog.conf
54#
55auth.info;authpriv.info          |exec /usr/sbin/sshlockout -pf "lockout"
56
57# in root's crontab
58#
593 3 * * *       pfctl -tlockout -T expire 86400
60
61#
62# ipfw(8) configuration.
63#
64ipfw table 0 create
65ipfw add deny ip from '<0>' to any
66
67# in /etc/syslog.conf
68#
69auth.info;authpriv.info         |exec /usr/sbin/sshlockout -ipfwtbl 0
70
71# in root's crontab
72#
733 3 * * *       ipfw -fq table 0 expire 86400
74.Ed
75.Sh DESCRIPTION
76This program is generally installed in
77.Pa /etc/syslog.conf
78as a pipe to parse the
79.Xr sshd 8
80demons error log in realtime.
81In addition, a root crontab entry should generally be created to clean
82out stale entries in the
83.Xr pf 4
84or
85.Xr ipfw 8
86.Ar table
87at least once a day.
88Using expire instead of flush will maintain a rolling window of locked out
89IPs.
90The
91.Xr pf 4
92or
93.Xr ipfw 8
94module must be loaded and running with the table and rules properly
95configured.
96.Pp
97This program will monitor the ssh syslog output and keep track of attempts
98to login to unknown users as well as preauth failures.
99If 5 attempts fail in any one hour period, a permanent entry is added to the
100.Xr pf 4
101or
102.Xr ipfw 8
103.Ar table
104for the associated IP address.
105You still have to add a rule to
106.Xr pf.conf 5
107or use
108.Xr ipfw 8
109to block IP addresses listed in this table.
110The cron entry you create cleans the block list out typically once a day.
111.Pp
112This program generally limits brute-force attempts to break into a machine
113via ssh.
114.Pp
115When setting up the
116.Xr pf 4
117or
118.Xr ipfw 8
119rules,
120note that the table will be filled based on failed ssh connections destined
121to that particular machine.
122If the machine is acting as a router you can decide whether you want the
123.Xr pf 4
124or
125.Xr ipfw 8
126rule to lockout that suspect IP to just the machine,
127or to everything it routes to.
128We usually recommend an unconditional blocking rule.
129.Sh NOTICE
130This program is still a work in progress.
131.Sh SEE ALSO
132.Xr ssh 1 ,
133.Xr pf 4 ,
134.Xr syslog.conf 5 ,
135.Xr ipfw 8 ,
136.Xr sshd 8
137.Sh HISTORY
138The
139.Nm
140utility first appeared in
141.Dx 4.1 .
142.Sh AUTHORS
143.An Matthew Dillon Aq Mt dillon@backplane.com
144