Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

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