comparison xml/syslog2iptables.in @ 63:60f59936fabb

good authentication prevents ip blocking for awhile
author Carl Byington <carl@five-ten-sg.com>
date Sat, 19 Dec 2015 10:12:24 -0800
parents b45dddebe8fc
children 45e53c44c46c
comparison
equal deleted inserted replaced
62:c30df5975c49 63:60f59936fabb
17 17
18 </partintro> 18 </partintro>
19 19
20 <refentry id="@PACKAGE@.1"> 20 <refentry id="@PACKAGE@.1">
21 <refentryinfo> 21 <refentryinfo>
22 <date>2009-01-25</date> 22 <date>2015-12-18</date>
23 <author> 23 <author>
24 <firstname>Carl</firstname> 24 <firstname>Carl</firstname>
25 <surname>Byington</surname> 25 <surname>Byington</surname>
26 <affiliation> 26 <affiliation>
27 <orgname>510 Software Group</orgname> 27 <orgname>510 Software Group</orgname>
59 entries are typically generated by your hardware firewall, but they 59 entries are typically generated by your hardware firewall, but they
60 could come from any source. Any syslog entry that contains a host name 60 could come from any source. Any syslog entry that contains a host name
61 or ip address can be used as input to this package.</para> 61 or ip address can be used as input to this package.</para>
62 62
63 <para>The <citerefentry> <refentrytitle>@PACKAGE@.conf</refentrytitle> 63 <para>The <citerefentry> <refentrytitle>@PACKAGE@.conf</refentrytitle>
64 <manvolnum>5</manvolnum> </citerefentry> file specifies the syslog files 64 <manvolnum>5</manvolnum> </citerefentry> file specifies the syslog
65 to be monitored, and the regular expressions (<citerefentry> 65 files to be monitored, and the regular expressions (<citerefentry>
66 <refentrytitle>regex</refentrytitle> <manvolnum>7</manvolnum> 66 <refentrytitle>regex</refentrytitle> <manvolnum>7</manvolnum>
67 </citerefentry>) to be applied to new lines in those files. Each 67 </citerefentry>) to be applied to new lines in those files. Each
68 regular expression needs an index to specify the matching substring that 68 regular expression needs an INDEX to specify the matching substring
69 contains either an ip address or host name, and a bucket count which is 69 that contains either an ip address or host name, and a DELTA which is
70 added to the leaky bucket for that ip address when a matching line is 70 used to modify the leaky bucket count for that ip address when a
71 read from that syslog file.</para> 71 matching line is read from that syslog file. </para>
72
73 <para>If the DELTA is negative, the leaky bucket count is set to that
74 DELTA value, any existing blocking for that ip address is removed, and
75 new blocking is prevented until that bucket leaks upward to zero.
76 </para>
77
78 <para>If the DELTA is positive and the current leaky bucket count is
79 not negative, that DELTA value is added to the leaky bucket count for
80 that ip address. Once the bucket contains more than a configurable
81 THRESHOLD number of tokens, that ip address is added to the INPUT
82 chain with a DROP target.</para>
72 83
73 <para>Each ip address has an associated leaky bucket, which leaks one 84 <para>Each ip address has an associated leaky bucket, which leaks one
74 token per second. Once the bucket contains more than a configurable 85 token per second so the count moves toward zero. When the bucket is
75 threshold number of tokens, that ip address is added to the INPUT chain 86 drained to zero, that ip address is removed from the INPUT
76 with a DROP target. When the bucket is drained to zero, that ip address 87 chain.</para>
77 is removed from the INPUT chain.</para>
78 88
79 <para>The discussion has focused on syslog files, but any ascii text 89 <para>The discussion has focused on syslog files, but any ascii text
80 file can be used, so long as some other process appends lines to that 90 file can be used, so long as some other process appends lines to that
81 file, and those lines containing hostname or ip addresses can be matched 91 file, and those lines containing hostname or ip addresses can be matched
82 with some regular expression.</para> 92 with some regular expression.</para>
83 93
84 <para>Considering syslog files in particular, these are normally rotated 94 <para>Considering syslog files in particular, these are normally rotated
85 via logrotate. <command>@PACKAGE@</command> properly detects and 95 via logrotate. <command>@PACKAGE@</command> properly detects and
86 handles this case by closing the old file, and reopening the newly 96 handles this case by closing the old file, and reopening the newly
87 created file.</para> 97 created file.</para>
98
99 <para>With the default config file, you can manually unblock an ip
100 address with <command>logger -p authpriv.info "manual unblock
101 1.2.3.4"</command> </para>
102
88 </refsect1> 103 </refsect1>
89 104
90 <refsect1 id='options.1'> 105 <refsect1 id='options.1'>
91 <title>Options</title> 106 <title>Options</title>
92 <variablelist> 107 <variablelist>
164 </refentry> 179 </refentry>
165 180
166 181
167 <refentry id="@PACKAGE@.conf.5"> 182 <refentry id="@PACKAGE@.conf.5">
168 <refentryinfo> 183 <refentryinfo>
169 <date>2009-01-25</date> 184 <date>2015-12-18</date>
170 </refentryinfo> 185 </refentryinfo>
171 186
172 <refmeta> 187 <refmeta>
173 <refentrytitle>@PACKAGE@.conf</refentrytitle> 188 <refentrytitle>@PACKAGE@.conf</refentrytitle>
174 <manvolnum>5</manvolnum> 189 <manvolnum>5</manvolnum>
203 REM-CMD := "remove_command" IPT-CMD 218 REM-CMD := "remove_command" IPT-CMD
204 IGNORE := "ignore" "{" IG-SINGLE+ "}" 219 IGNORE := "ignore" "{" IG-SINGLE+ "}"
205 IG-SINGLE := IP-ADDRESS "/" CIDR-BITS 220 IG-SINGLE := IP-ADDRESS "/" CIDR-BITS
206 FILE := "file" FILENAME "{" PATTERN+ "}" 221 FILE := "file" FILENAME "{" PATTERN+ "}"
207 PATTERN := "pattern" REGULAR-EXPRESSION "{" {INDEX | BUCKET | MESSAGE}+ "};" 222 PATTERN := "pattern" REGULAR-EXPRESSION "{" {INDEX | BUCKET | MESSAGE}+ "};"
208 INDEX := "index" REGEX-INTEGER-VALUE ";" 223 INDEX := "index" REGEX-INTEGER ";"
209 BUCKET := "bucket" BUCKET-ADD-INTEGER-VALUE ";" 224 DELTA := "bucket" BUCKET-DELTA-INTEGER ";"
210 MESSAGE := "message" REASON ";" 225 MESSAGE := "message" REASON ";"
211 REASON := string to appear in syslog messages 226 REASON := string to appear in syslog messages
212 IPT-CMD := string containing exactly one %s replacement token for 227 IPT-CMD := string containing exactly one %s replacement token for
213 the ip address]]></literallayout> 228 the ip address]]></literallayout>
214 </refsect1> 229 </refsect1>
215 230
216 <refsect1 id='sample.5'> 231 <refsect1 id='sample.5'>
217 <title>Sample</title> 232 <title>Sample</title>
218 <literallayout class="monospaced"><![CDATA[ 233 <literallayout class="monospaced"><![CDATA[
219 context dns { 234 context general {
220 threshold 1100; 235 threshold 550;
221 236
222 add_command "/sbin/iptables -I INPUT --protocol udp --destination-port 53 --src %s --jump DROP"; 237 add_command "/sbin/iptables -I INPUT --src %s --jump DROP";
223 remove_command "/sbin/iptables -D INPUT --protocol udp --destination-port 53 --src %s --jump DROP"; 238 remove_command "/sbin/iptables -D INPUT --src %s --jump DROP";
224 239
225 ignore { 240 ignore {
226 127.0.0.0/8; // localhost 241 127.0.0.0/8; // localhost
227 }; 242 };
228 243
244 file "/var/log/secure" {
245 pattern "manual unblock (.*)" {
246 index 1; // zero based
247 bucket -5000;
248 message "manual unblock";
249 };
250 pattern "sshd.*Failed password .* from ::ffff:(.*) port" {
251 index 1; // zero based
252 bucket 400;
253 message "ssh failed password";
254 };
255 pattern "sshd.*Failed password .* from (.*) port" {
256 index 1; // zero based
257 bucket 400;
258 message "ssh failed password";
259 };
260 pattern "sshd.*authentication failure; .* rhost=(.*) " {
261 index 1; // zero based
262 bucket 400;
263 message "ssh failed password";
264 };
265 pattern "sshd.*Did not receive identification string from (.*)" {
266 index 1; // zero based
267 bucket 400;
268 message "ssh failed password";
269 };
270 pattern "proftpd.*no such user found from (.*) \[" {
271 index 1; // zero based
272 bucket 400;
273 message "ftp failed password";
274 };
275 pattern "proftpd.* authentication failure; .* rhost=(.*) " {
276 index 1; // zero based
277 bucket 400;
278 message "ftp failed password";
279 };
280 pattern "vsftpd.* authentication failure; .* rhost=(.*) " {
281 index 1; // zero based
282 bucket 400;
283 message "ftp failed password";
284 };
285 pattern "dovecot.* authentication failure; .* rhost=::ffff:(.*) " {
286 index 1; // zero based
287 bucket 100;
288 message "dovecot failed password";
289 };
290 pattern "dovecot.* authentication failure; .* rhost=(.*) " {
291 index 1; // zero based
292 bucket 100;
293 message "dovecot failed password";
294 };
295 };
296
229 file "/var/log/messages" { 297 file "/var/log/messages" {
230 pattern "named.*client (.*)#.*query.*cache.*denied" { 298 pattern "dovecot.* authentication failure; .* rhost=(.*) " {
231 index 1; // zero based 299 index 1; // zero based
232 bucket 400; 300 bucket 100;
233 message "DNS attack"; 301 message "dovecot failed password";
302 };
303 pattern "kernel.*local-net-to.*SRC=(.*) DST=.*DPT=" {
304 index 1; // zero based
305 bucket 400;
306 message "kernel firewall blocked packet";
307 };
308 pattern "kernel.*outside-net-from.*SRC=(.*) DST=.*DPT=" {
309 index 1; // zero based
310 bucket 400;
311 message "kernel firewall blocked packet";
234 }; 312 };
235 }; 313 };
236 };
237
238
239 context general {
240 threshold 550;
241
242 add_command "/sbin/iptables -I INPUT --src %s --jump DROP";
243 remove_command "/sbin/iptables -D INPUT --src %s --jump DROP";
244
245 ignore {
246 127.0.0.0/8; // localhost
247 };
248
249 file "/var/log/secure" {
250 pattern "sshd.*Failed password .* from ::ffff:(.*) port" {
251 index 1; // zero based
252 bucket 400;
253 message "ssh failed password";
254 };
255 pattern "sshd.*Failed password .* from (.*) port" {
256 index 1; // zero based
257 bucket 400;
258 message "ssh failed password";
259 };
260 pattern "proftpd.*no such user found from (.*) \[" {
261 index 1; // zero based
262 bucket 400;
263 message "ftp failed password";
264 };
265 };
266
267 file "/var/log/messages" {
268 pattern "ipop3d.* Login failed .* \[(.*)\]" {
269 index 1; // zero based
270 bucket 400;
271 message "pop3 failed password";
272 };
273 };
274
275 file "/var/log/httpd/access_log" {
276 // of course you cannot use this if you actually use cgi-bin directories
277 pattern "(.*) - - .* /cgi-bin" {
278 index 1; // zero based
279 bucket 400;
280 message "apache cgi-bin reference";
281 };
282 // or if you actually have an index2.php script
283 pattern "(.*) - - .*/index2.php" {
284 index 1; // zero based
285 bucket 400;
286 message "apache index2.php reference";
287 };
288 // or if you have a main.php script
289 pattern "(.*) - - .*/main.php" {
290 index 1; // zero based
291 bucket 400;
292 message "apache main.php reference";
293 };
294 pattern "(.*) - - .*/awstats.pl" {
295 index 1; // zero based
296 bucket 400;
297 message "apache awstats.pl reference";
298 };
299 pattern "(.*) - - .*/adxmlrpc" {
300 index 1; // zero based
301 bucket 400;
302 message "apache adxmlrpc reference";
303 };
304 };
305 314
306 file "/var/log/maillog" { 315 file "/var/log/maillog" {
307 pattern "lost input channel from .* \[(.*)\] .* after (mail|rcpt|auth)" { 316 pattern "lost input channel from.* \[(.*)\] .* after (mail|rcpt|auth)" {
308 index 1; // zero based 317 index 1; // zero based
309 bucket 200; 318 bucket 100;
310 message "sendmail spammer dropping connection"; 319 message "sendmail spammer dropping connection";
311 }; 320 };
312 pattern " \[(.*)\]: possible SMTP attack" { 321 pattern " \[(.*)\].* possible SMTP attack" {
313 index 1; // zero based 322 index 1; // zero based
314 bucket 600; 323 bucket 100;
315 message "sendmail authentication attack"; 324 message "sendmail authentication attack";
316 }; 325 };
317 pattern "rejecting commands from .* \[(.*)\] due to pre-greeting traffic" { 326 pattern "rejecting commands from.* \[(.*)\] due to pre-greeting traffic" {
318 index 1; // zero based 327 index 1; // zero based
319 bucket 200; 328 bucket 1800;
320 message "sendmail pre-greeting"; 329 message "sendmail pre-greeting";
321 }; 330 };
322 pattern "dovecot.*Aborted login.*rip=(.*)," { 331 pattern "authentication failure: checkpass failed, .*\[(.*)\]" {
332 index 1; // zero based
333 bucket 100;
334 message "sendmail authentication failed";
335 };
336 pattern "dovecot.*Aborted login .* rip=(.*)," {
323 index 1; // zero based 337 index 1; // zero based
324 bucket 100; 338 bucket 100;
325 message "dovecot failed password"; 339 message "dovecot failed password";
326 }; 340 };
327 pattern "dovecot: pop3-login: Disconnected: Shutting down.*rip=(.*)," { 341 pattern "dovecot.*Login: .* rip=(.*)," {
328 index 1; // zero based 342 index 1; // zero based
329 bucket 100; 343 bucket -5000;
330 message "dovecot failed password"; 344 message "dovecot good authentication";
331 }; 345 };
332 346 pattern "sendmail.*AUTH=server, .*\[(.*)\]," {
333 // make sure your upstream MX servers are listed in the 347 index 1; // zero based
334 // ignore block above, otherwise you will kill them off 348 bucket -5000;
335 // when they try to forward such mail to you. 349 message "sendmail good authentication";
336 pattern "sendmail.*from=<>,.*nrcpts=0,.*\[(.*)\]" {
337 index 1; // zero based
338 bucket 200;
339 message "sendmail rejected bounce";
340 }; 350 };
341 }; 351 };
342 };]]></literallayout> 352 };]]></literallayout>
343 </refsect1> 353 </refsect1>
344 354