Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
192 - 1
# Fail2Ban configuration file
2
#
3
# Author: Russell Odom <russ@gloomytrousers.co.uk>
4
# Submits attack reports to DShield (http://www.dshield.org/)
5
#
6
# You MUST configure at least:
7
# <port> (the port that's being attacked - use number not name).
8
#
9
# You SHOULD also provide:
10
# <myip> (your public IP address, if it's not the address of eth0)
11
# <userid> (your DShield userID, if you have one - recommended, but reports will
12
# be used anonymously if not)
13
# <protocol> (the protocol in use - defaults to tcp)
14
#
15
# Best practice is to provide <port> and <protocol> in jail.conf like this:
16
# action = dshield[port=1234,protocol=tcp]
17
#
18
# ...and create "dshield.local" with contents something like this:
19
# [Init]
20
# myip = 10.0.0.1
21
# userid = 12345
22
#
23
# Other useful configuration values are <mailargs> (you can use for specifying
24
# a different sender address for the report e-mails, which should match what is
25
# configured at DShield), and <lines>/<minreportinterval>/<maxbufferage> (to
26
# configure how often the buffer is flushed).
27
#
28
 
29
[Definition]
30
 
31
# bypass ban/unban for restored tickets
32
norestored = 1
33
 
34
# Option:  actionstart
35
# Notes.:  command executed on demand at the first ban (or at the start of Fail2Ban if actionstart_on_demand is set to false).
36
# Values:  CMD
37
#
38
actionstart =
39
 
40
# Option:  actionstop
41
# Notes.:  command executed at the stop of jail (or at the end of Fail2Ban)
42
# Values:  CMD
43
#
44
actionstop = if [ -f <tmpfile>.buffer ]; then
45
                 cat <tmpfile>.buffer | <mailcmd> "FORMAT DSHIELD USERID <userid> TZ `date +%%z | sed 's/\([+-]..\)\(..\)/\1:\2/'` Fail2Ban" <mailargs> <dest>
46
                 date +%%s > <tmpfile>.lastsent
47
             fi
48
             rm -f <tmpfile>.buffer <tmpfile>.first
49
 
50
# Option:  actioncheck
51
# Notes.:  command executed once before each actionban command
52
# Values:  CMD
53
#
54
actioncheck =
55
 
56
# Option:  actionban
57
# Notes.:  command executed when banning an IP. Take care that the
58
#          command is executed with Fail2Ban user rights.
59
# Tags:    See jail.conf(5) man page
60
# Values:  CMD
61
#
62
# See http://www.dshield.org/specs.html for more on report format/notes
63
#
64
# Note: We are currently using <time> for the timestamp because no tag is
65
# available to indicate the timestamp of the log message(s) which triggered the
66
# ban. Therefore the timestamps we are using in the report, whilst often only a
67
# few seconds out, are incorrect. See
68
# http://sourceforge.net/tracker/index.php?func=detail&aid=2017795&group_id=121032&atid=689047
69
#
70
actionban = TZONE=`date +%%z | sed 's/\([+-]..\)\(..\)/\1:\2/'`
71
            DATETIME="`perl -e '@t=localtime(<time>);printf "%%4d-%%02d-%%02d %%02d:%%02d:%%02d",1900+$t[5],$t[4]+1,$t[3],$t[2],$t[1],$t[0]'` $TZONE"
72
	    PROTOCOL=`awk '{IGNORECASE=1;if($1=="<protocol>"){print $2;exit}}' /etc/protocols`
73
	    if [ -z "$PROTOCOL" ]; then PROTOCOL=<protocol>; fi
74
            printf %%b "$DATETIME\t<userid>\t<failures>\t<ip>\t<srcport>\t<myip>\t<port>\t$PROTOCOL\t<tcpflags>\n" >> <tmpfile>.buffer
75
            NOW=`date +%%s`
76
            if [ ! -f <tmpfile>.first ]; then
77
                echo <time> | cut -d. -f1 > <tmpfile>.first
78
            fi
79
            if [ ! -f <tmpfile>.lastsent ]; then
80
                echo 0 > <tmpfile>.lastsent
81
            fi
82
            LOGAGE=$(($NOW - `cat <tmpfile>.first`))
83
            LASTREPORT=$(($NOW - `cat <tmpfile>.lastsent`))
84
            LINES=$( wc -l <tmpfile>.buffer | awk '{ print $1 }' )
85
            if [ $LINES -ge <lines> && $LASTREPORT -gt <minreportinterval> ] || [ $LOGAGE -gt <maxbufferage> ]; then
86
                cat <tmpfile>.buffer | <mailcmd> "FORMAT DSHIELD USERID <userid> TZ $TZONE Fail2Ban" <mailargs> <dest>
87
                rm -f <tmpfile>.buffer <tmpfile>.first
88
                echo $NOW > <tmpfile>.lastsent
89
            fi
90
 
91
# Option:  actionunban
92
# Notes.:  command executed when unbanning an IP. Take care that the
93
#          command is executed with Fail2Ban user rights.
94
# Tags:    See jail.conf(5) man page
95
# Values:  CMD
96
#
97
actionunban = if [ -f <tmpfile>.first ]; then
98
                  NOW=`date +%%s`
99
                  LOGAGE=$(($NOW - `cat <tmpfile>.first`))
100
                  if [ $LOGAGE -gt <maxbufferage> ]; then
101
                      cat <tmpfile>.buffer | <mailcmd> "FORMAT DSHIELD USERID <userid> TZ `date +%%z | sed 's/\([+-]..\)\(..\)/\1:\2/'` Fail2Ban" <mailargs> <dest>
102
                      rm -f <tmpfile>.buffer <tmpfile>.first
103
                      echo $NOW > <tmpfile>.lastsent
104
                  fi
105
              fi
106
 
107
 
108
[Init]
109
# Option:  port
110
# Notes.:  The target port for the attack (numerical). MUST be provided in the
111
#          jail config, as it cannot be detected here.
112
# Values:  [ NUM ]
113
#
114
port = ???
115
 
116
# Option:  userid
117
# Notes.:  Your DShield user ID. Should be provided either in the jail config or
118
#          in a .local file.
119
#          Register at https://secure.dshield.org/register.html
120
# Values:  [ NUM ]
121
#
122
userid = 0
123
 
124
# Option:  myip
125
# Notes.:  The target IP for the attack (your public IP). Should be provided
126
#          either in the jail config or in a .local file unless your PUBLIC IP
127
#          is the first IP assigned to eth0
128
# Values:  [ an IP address ]  Default: Tries to find the IP address of eth0,
129
#          which in most cases will be a private IP, and therefore incorrect
130
#
131
myip = `ip -4 addr show dev eth0 | grep inet | head -n 1 | sed -r 's/.*inet ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}).*/\1/'`
132
 
133
# Option:  protocol
134
# Notes.:  The protocol over which the attack is happening
135
# Values:  [ tcp | udp | icmp | (any other protocol name from /etc/protocols) | NUM ] Default: tcp
136
#
137
protocol = tcp
138
 
139
# Option:  lines
140
# Notes.:  How many lines to buffer before making a report. Regardless of this,
141
#          reports are sent a minimum of <minreportinterval> apart, or if the
142
#          buffer contains an event over <maxbufferage> old, or on shutdown
143
# Values:  [ NUM ]
144
#
145
lines = 50
146
 
147
# Option:  minreportinterval
148
# Notes.:  Minimum period (in seconds) that must elapse before we submit another
149
#          batch of reports. DShield request a minimum of 1 hour (3600 secs)
150
#          between reports.
151
# Values:  [ NUM ]
152
#
153
minreportinterval = 3600
154
 
155
# Option:  maxbufferage
156
# Notes.:  Maximum age (in seconds) of the oldest report in the buffer before we
157
#          submit the batch, even if we haven't reached <lines> yet. Note that
158
#          this is only checked on each ban/unban, and that we always send
159
#          anything in the buffer on shutdown. Must be greater than
160
# Values:  [ NUM ]
161
#
162
maxbufferage = 21600
163
 
164
# Option:  srcport
165
# Notes.:  The source port of the attack. You're unlikely to have this info, so
166
#          you can leave the default
167
# Values:  [ NUM ]
168
#
169
srcport = ???
170
 
171
# Option:  tcpflags
172
# Notes.:  TCP flags on attack. You're unlikely to have this info, so you can
173
#          leave empty
174
# Values:  [ STRING ]
175
#
176
tcpflags =
177
 
178
# Option:  mailcmd
179
# Notes.:  Your system mail command. Is passed 2 args: subject and recipient
180
# Values:  CMD
181
#
182
mailcmd = mail -s
183
 
184
# Option:  mailargs
185
# Notes.:  Additional arguments to mail command. e.g. for standard Unix mail:
186
#          CC reports to another address:
187
#              -c me@example.com
188
#          Appear to come from a different address (the From address must match
189
#          the one configured at DShield - the '--' indicates arguments to be
190
#          passed to Sendmail):
191
#              -- -f me@example.com
192
# Values:  [ STRING ]
193
#
194
mailargs =
195
 
196
# Option:  dest
197
# Notes.:  Destination e-mail address for reports
198
# Values:  [ STRING ]
199
#
200
dest = reports@dshield.org
201
 
202
# Option:  tmpfile
203
# Notes.:  Base name of temporary files used for buffering
204
# Values:  [ STRING ]
205
#
206
tmpfile = /var/run/fail2ban/tmp-dshield
207