Debian Codegraph @

doc/contrib/mod_ban.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>ProFTPD module mod_ban</title>
5 </head>
6
7 <body bgcolor=white>
8
9 <hr>
10 <center>
11 <h2><b>ProFTPD module <code>mod_ban</code></b></h2>
12 </center>
13 <hr><br>
14
15 <p>
16 The <code>mod_ban</code> module is designed to add dynamic &quot;ban&quot;
17 lists to <code>proftpd</code>. A ban prevents the banned user, host, or
18 class from logging in to the server; it <b>does not</b> prevent the banned
19 user, host, or class from <i>connecting</i> to the server.
20 <b><code>mod_ban</code> is not a firewall</b>. The module also provides
21 automatic bans that are triggered based on configurable criteria.
22
23 <p>
24 This module is contained in the <code>mod_ban.c</code> file for
25 ProFTPD 1.2.<i>x</i>/1.3.<i>x</i>, and is not compiled by default.
26 Installation instructions are discussed <a href="#Installation">here</a>.
27 Detailed documentation on <code>mod_ban</code> usage can be found
28 <a href="#Usage">here</a>.
29
30 <p>
31 The most current version of <code>mod_ban</code> is distributed with the
32 proftpd source.
33
34 <h2>Author</h2>
35 <p>
36 Please contact TJ Saunders &lt;tj <i>at</i> castaglia.org&gt; with any
37 questions, concerns, or suggestions regarding this module.
38
39 <h2>Directives</h2>
40 <ul>
41 <li><a href="#BanCache">BanCache</a>
42 <li><a href="#BanCacheOptions">BanCacheOptions</a>
43 <li><a href="#BanControlsACLs">BanControlsACLs</a>
44 <li><a href="#BanEngine">BanEngine</a>
45 <li><a href="#BanLog">BanLog</a>
46 <li><a href="#BanMessage">BanMessage</a>
47 <li><a href="#BanOnEvent">BanOnEvent</a>
48 <li><a href="#BanOptions">BanOptions</a>
49 <li><a href="#BanTable">BanTable</a>
50 </ul>
51
52 <h2>Control Actions</h2>
53 <ul>
54 <li><a href="#ban"><code>ban</code></a>
55 <li><a href="#permit"><code>permit</code></a>
56 </ul>
57
58 <p>
59 <hr>
60 <h3><a name="BanCache">BanCache</a></h3>
61 <strong>Syntax:</strong> BanCache <em>driver</em><br>
62 <strong>Default:</strong> None<br>
63 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
64 <strong>Module:</strong> mod_ban<br>
65 <strong>Compatibility:</strong> 1.3.4rc2 and later
66
67 <p>
68 The <code>BanCache</code> directive configures a <em>driver</em> to use for
69 caching ban entries. Depending on the compile-time options, the following
70 drivers are supported:
71 <ul>
72 <li>memcache
73 <li>redis
74 </ul>
75
76 <p>
77 <hr>
78 <h3><a name="BanCacheOptions">BanCacheOptions</a></h3>
79 <strong>Syntax:</strong> BanCacheOptions <em>opt1 ... optN</em><br>
80 <strong>Default:</strong> None<br>
81 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
82 <strong>Module:</strong> mod_ban<br>
83 <strong>Compatibility:</strong> 1.3.4rc2 and later
84
85 <p>
86 The <code>BanCacheOptions</code> directive is used to configure various optional
87 caching behavior of <code>mod_ban</code>. <b>Note</b>: all of the configured
88 <code>BanCacheOptions</code> parameters <b>must</b> appear on the same line in
89 the configuration; only the first <code>BanCacheOptions</code> directive that
90 appears in the configuration is used.
91
92 <p>
93 Example:
94 <pre>
95 BanCacheOptions UseJSON
96 </pre>
97
98 <p>
99 The currently implemented options are:
100 <ul>
101 <li><code>MatchServer</code><br>
102 <p>
103 This option tells <code>mod_ban</code> to ignore cached entries unless
104 they <b>match</b> the IP address/port of the server handling the FTP
105 session. There might be other servers adding their own entries to
106 a common cache, for example; it is for these situations that the
107 <code>MatchServer</code> option should be used, to avoid false positives.
108 </li>
109
110 <p>
111 <li><code>UseJSON</code><br>
112 <p>
113 This option tells <code>mod_ban</code> to store the ban rules in the
114 cache as JSON-formatted data. This makes it possible for other tools
115 to discover/display the cached ban rules.
116
117 <p>
118 <b>Note</b> that this option first appeared in
119 <code>proftpd-1.3.6rc2</code>.
120 </li>
121 </ul>
122
123 <p>
124 <hr>
125 <h3><a name="BanControlsACLs">BanControlsACLs</a></h3>
126 <strong>Syntax:</strong> BanControlsACLs <em>actions|&quot;all&quot; &quot;allow&quot;|&quot;deny&quot; &quot;user&quot;|&quot;group&quot; list</em><br>
127 <strong>Default:</strong> None<br>
128 <strong>Context:</strong> server config<br>
129 <strong>Module:</strong> mod_ban<br>
130 <strong>Compatibility:</strong> 1.2.10rc1 and later
131
132 <p>
133 The <code>BanControlsACLs</code> directive configures access lists of
134 <em>users</em> or <em>groups</em> who are allowed (or denied) the ability to
135 use the <em>actions</em> implemented by <code>mod_ban</code>. The default
136 behavior is to deny everyone unless an ACL allowing access has been explicitly
137 configured.
138
139 <p>
140 If &quot;allow&quot; is used, then <em>list</em>, a comma-delimited list
141 of <em>users</em> or <em>groups</em>, can use the given <em>actions</em>; all
142 others are denied. If &quot;deny&quot; is used, then the <em>list</em> of
143 <em>users</em> or <em>groups</em> cannot use <em>actions</em> all others are
144 allowed. Multiple <code>BanControlsACLs</code> directives may be used to
145 configure ACLs for different control actions, and for both users and groups.
146
147 <p>
148 The <em>actions</em> provided by <code>mod_ban</code> are &quot;ban&quot;
149 and &quot;permit&quot;.
150
151 <p>
152 Examples:
153 <pre>
154 # Allow only user root to ban and permit users
155 BanControlsACLs all allow user root
156 </pre>
157
158 <p>
159 <hr>
160 <h3><a name="BanEngine">BanEngine</a></h3>
161 <strong>Syntax:</strong> BanEngine <em>on|off</em><br>
162 <strong>Default:</strong> off<br>
163 <strong>Context:</strong> server config<br>
164 <strong>Module:</strong> mod_ban<br>
165 <strong>Compatibility:</strong> 1.2.10rc1 and later
166
167 <p>
168 The <code>BanEngine</code> directive enables or disables the banning of
169 sessions by <code>mod_ban</code>. If it is set to <em>off</em> this module
170 does no banning. Use this directive to disable the module instead of
171 commenting out all <code>mod_ban</code> directives.
172
173 <p>
174 <hr>
175 <h3><a name="BanLog">BanLog</a></h3>
176 <strong>Syntax:</strong> BanLog <em>path|&quot;none&quot;</em><br>
177 <strong>Default:</strong> None<br>
178 <strong>Context:</strong> server config, <code>&lt;Global&gt;</code><br>
179 <strong>Module:</strong> mod_ban<br>
180 <strong>Compatibility:</strong> 1.2.10rc1 and later
181
182 <p>
183 The <code>BanLog</code> directive is used to specify a log file for
184 <code>mod_ban</code> reporting and debugging. The <em>path</em> parameter
185 must be the full path to the file to use for logging. Note that this path must
186 <b>not</b> be to a world-writeable directory and, unless
187 <code>AllowLogSymlinks</code> is explicitly set to <em>on</em>
188 (generally a bad idea), the path must <b>not</b> be a symbolic link.
189
190 <p>
191 If <em>path</em> is &quot;none&quot;, no logging will be done at all.
192
193 <p>
194 <hr>
195 <h3><a name="BanMessage">BanMessage</a></h3>
196 <strong>Syntax:</strong> BanMessage <em>mesg</em><br>
197 <strong>Default:</strong> None<br>
198 <strong>Context:</strong> server config, <code>&lt;Global&gt;</code><br>
199 <strong>Module:</strong> mod_ban<br>
200 <strong>Compatibility:</strong> 1.2.10rc1 and later
201
202 <p>
203 The <code>BanMessage</code> directive configures a message that will be
204 sent to clients that have been banned. This message may contain the
205 following variables:
206 <ul>
207 <li><code>%a</code>: client IP address
208 <li><code>%c</code>: client class (if none, will be empty)
209 <li><code>%u</code>: USER name (if none, will be empty)
210 </ul>
211
212 <p>
213 Example:
214 <pre>
215 BanMessage "Host %a has been banned"
216 </pre>
217
218 <p>
219 <hr>
220 <h3><a name="BanOnEvent">BanOnEvent</a></h3>
221 <strong>Syntax:</strong> BanOnEvent <em>event freq expires [mesg]</em><br>
222 <strong>Default:</strong> None<br>
223 <strong>Context:</strong> server config, <code>&lt;Global&gt;</code><br>
224 <strong>Module:</strong> mod_ban<br>
225 <strong>Compatibility:</strong> 1.2.10rc1 and later
226
227 <p>
228 The <code>BanOnEvent</code> directive is used to configure a &quot;rule&quot;
229 that is triggered whenever the named <em>event</em> occurs. The currently
230 supported events are:
231 <p>
232 <table border=1 summary="Ban Events">
233 <tr>
234 <td><b>Directive</b></td>
235 <td><b>Class/Host/User Ban</b></td>
236 </tr>
237
238 <tr>
239 <td><code>AnonRejectPasswords</code></td>
240 <td>Host ban</td>
241 </tr>
242
243 <tr>
244 <td><code>BadProtocol</code></td>
245 <td>Host ban</td>
246 </tr>
247
248 <tr>
249 <td><code>ClientConnectRate</code></td>
250 <td>Host ban</td>
251 </tr>
252
253 <tr>
254 <td><code>EmptyPassword</code></td>
255 <td>Host ban</td>
256 </tr>
257
258 <tr>
259 <td><code>MaxClientsPerClass</code></td>
260 <td>Class ban</td>
261 </tr>
262
263 <tr>
264 <td><code>MaxClientsPerHost</code></td>
265 <td>Host ban</td>
266 </tr>
267
268 <tr>
269 <td><code>MaxClientsPerUser</code></td>
270 <td>User ban</td>
271 </tr>
272
273 <tr>
274 <td><code>MaxCommandRate</code></td>
275 <td>Host ban</td>
276 </tr>
277
278 <tr>
279 <td><code>MaxConnectionsPerHost</code></td>
280 <td>Host ban</td>
281 </tr>
282
283 <tr>
284 <td><code>MaxHostsPerUser</code></td>
285 <td>User ban</td>
286 </tr>
287
288 <tr>
289 <td><code>MaxLoginAttempts</code></td>
290 <td>Host ban</td>
291 </tr>
292
293 <tr>
294 <td><code>MaxLoginAttemptsFromUser</code></td>
295 <td>User@Host ban</td>
296 </tr>
297
298 <tr>
299 <td><code>RootLogin</code></td>
300 <td>Host ban</td>
301 </tr>
302
303 <tr>
304 <td><code>TimeoutIdle</code></td>
305 <td>Host ban</td>
306 </tr>
307
308 <tr>
309 <td><code>TimeoutLogin</code></td>
310 <td>Host ban</td>
311 </tr>
312
313 <tr>
314 <td><code>TimeoutNoTransfer</code></td>
315 <td>Host ban</td>
316 </tr>
317
318 <tr>
319 <td><code>TLSHandshake</code></td>
320 <td>Host ban</td>
321 </tr>
322
323 <tr>
324 <td><code>UnhandledCommand</code></td>
325 <td>Host ban</td>
326 </tr>
327 </table>
328
329 <p>
330 An event is generated whenever one of these limits is reached by a client.
331
332 <p>
333 The <em>freq</em> parameter should be formatted as:
334 <pre>
335 <i>N</i>/hh:mm:ss
336 </pre>
337 where <i>N</i> is the number of occurrences, and <code>hh:mm:ss</code>
338 specifies a number of hours, minutes, and seconds. This parameter says
339 that if <i>N</i> occurrences of <em>event</em> happen within the given
340 time interval, then a ban is automatically added. The IP address of
341 the connecting client is banned when the following event rules are
342 triggered: <code>AnonRejectPasswords</code>, <code>BadProtocol</code>,
343 <code>MaxCommandRate</code>, <code>MaxClientsPerHost</code>,
344 <code>MaxConnectionsPerHost</code>, <code>MaxLoginAttempts</code>,
345 <code>TimeoutIdle</code>, <code>TimeoutNoTransfer</code>, and
346 <code>UnhandledCommand</code>. The class of the connected client, if any, is
347 banned when a rule for <code>MaxClientsPerClass</code> is triggered. Rules for
348 <code>MaxClientsPerUser</code> and <code>MaxHostsPerUser</code> will cause
349 the connected username to be banned.
350
351 <p>
352 The <em>duration</em> should be formatted as:
353 <pre>
354 hh:mm:ss
355 </pre>
356 and specifies the numbers of hours, minutes, and seconds that the automatic
357 ban generated a <code>BanOnEvent</code> rule lasts. Unlike bans added via the
358 <a href="#ban">ban</a> <code>ftpdctl</code> control action, automatic bans do
359 <b>not</b> have infinite lifetimes.
360
361 <p>
362 An optional message, to be displayed to banned clients, can be configured.
363 If no such optional message is configured using the <code>BanOnEvent</code>
364 directive, then any <code>BanMessage</code> message will be displayed.
365
366 <p>
367 For example:
368 <pre>
369 # Configure a rule to automatically ban scripts looking for anonymous
370 # servers to which they can upload
371 BanOnEvent AnonRejectPasswords 1/01:00:00 99:99:99
372
373 # Ban clients which connect too frequently. This rule bans clients
374 # which connect more than 5 times within one minute. Include a special
375 # message just for them.
376 BanOnEvent ClientConnectRate 5/00:01:00 04:00:00 "Stop connecting frequently"
377 </pre>
378
379 <p>
380 See also: <a href="#BanMessage"><code>BanMessage</code></a>
381
382 <p>
383 <hr>
384 <h3><a name="BanOptions">BanOptions</a></h3>
385 <strong>Syntax:</strong> BanOptions <em>opt1 ...</em><br>
386 <strong>Default:</strong> None<br>
387 <strong>Context:</strong> server config, <code>&lt;VirtualHost&gt;</code>, <code>&lt;Global&gt;</code><br>
388 <strong>Module:</strong> mod_ban<br>
389 <strong>Compatibility:</strong> 1.3.7rc4 and later
390
391 <p>
392 The <code>BanOptions</code> directive is used to configure various optional
393 behavior of <code>mod_ban</code>.
394
395 <p>
396 Example:
397 <pre>
398 BanOptions MatchAnyServer
399 </pre>
400
401 <p>
402 The currently implemented options are:
403 <ul>
404 <li><code>MatchAnyServer</code><br>
405 <p>
406 By default, any ban entries are valid only for the
407 <code>&lt;VirtualHost&gt;</code> handling the banned clients. This is
408 intentional; the assumption is that there will be different clients,
409 different use cases for the different <code>&lt;VirtualHost&gt;</code>
410 sections.
411
412 <p>
413 However, some sites would like ban entries to be valid across
414 <code>&lt;VirtualHost&gt;</code>, to <em>match</em>, or apply to
415 <b>any server</b>. Use this option to enable this behavior.
416 </ul>
417
418 <p>
419 <hr>
420 <h3><a name="BanTable">BanTable</a></h3>
421 <strong>Syntax:</strong> BanTable <em>path</em><br>
422 <strong>Default:</strong> None<br>
423 <strong>Context:</strong> server config<br>
424 <strong>Module:</strong> mod_ban<br>
425 <strong>Compatibility:</strong> 1.2.10rc1 and later
426
427 <p>
428 The <code>BanTable</code> directive configures a <em>path</em> to a file
429 that <code>mod_ban</code> uses for handling its ban data. The given
430 <em>path</em> must be an absolute path. <b>Note</b>: this directive is
431 <b>required</b> for <code>mod_ban</code> to function. It is recommended
432 that this file <b>not</b> be on an NFS mounted partition.
433
434 <p>
435 Note that ban data <b>is not</b> kept across daemon stop/starts. That is,
436 once <code>proftpd</code> is shutdown, all current ban data is lost.
437
438 <p>
439 <hr>
440 <h2>Control Actions</h2>
441
442 <p>
443 <hr>
444 <h3><a name="ban"><code>ban</code></a></h3>
445 <strong>Syntax:</strong> ftpdctl ban <em>class|host|info|user|user@host [-s address#port] name1 [name2 ...]</em><br>
446 <strong>Purpose:</strong> Add a ban or display ban information<br>
447
448 <p>
449 The <code>ban</code> action is used to add bans to the <code>mod_ban</code>
450 lists. For example, to ban a user:
451 <pre>
452 ftpdctl ban user dave
453 </pre>
454 This will create a ban rule for user 'dave' for <i>all</i> virtual servers in
455 your <code>proftpd.conf</code>. If you want to create such a ban rule, but
456 only for one specific <code>&lt;VirtualHost&gt;</code>, use the <code>-s</code>
457 command-line option, <i>e.g.</i>:
458 <pre>
459 ftpdctl ban user -s 1.2.3.4#21 dave
460 </pre>
461 This example will create the user 'dave' ban rule for the
462 <code>&lt;VirtualHost&gt;</code> handling IP address 1.2.3.4, port 21.
463 The <code>-s</code> command-line option applies to <em>host</em> and
464 <em>class</em> bans as well.
465
466 <p>
467 To ban specific hosts, you can use either IP addresses or DNS names:
468 <pre>
469 ftpdctl ban host 1.2.3.4 5.6.7.8
470 ftpdctl ban host gw.evil.com
471 </pre>
472 Banning a class works the same way:
473 <pre>
474 ftpdctl ban class anonftp
475 </pre>
476
477 <p>
478 The <em>info</em> parameter is used to view information on current bans.
479 Example listing:
480 <pre>
481 # ftpdctl ban info
482 ftpdctl: Banned Hosts:
483 ftpdctl: 127.0.0.1
484 </pre>
485 Or, if you wish to see more information, use the <code>-v</code> option:
486 <pre>
487 # ftpdctl ban info -v
488 ftpdctl: Banned Hosts:
489 ftpdctl: 127.0.0.1
490 ftpdctl: Reason: MaxLoginAttempts autoban at Wed May 19 14:59:25 2004
491 ftpdctl: Expires: Wed May 19 14:59:55 2004 (in 24 seconds)
492 ftpdctl: &lt;VirtualHost&gt; <i>ServerName</i> (1.2.3.4#21)
493 </pre>
494 It is also possible to see the state of ban event rules, using the
495 <code>-e</code> option:
496 <pre>
497 # ftpdctl ban info -e
498 ftpdctl: No bans
499 ftpdctl:
500 ftpdctl: Ban Event Entries:
501 ftpdctl: Event: MaxLoginAttempts
502 ftpdctl: Source: 127.0.0.1
503 ftpdctl: Occurrences: 1/2
504 ftpdctl: Entry Expires: 589 seconds
505 </pre>
506 This shows that no bans are currently in effect, and that a
507 <code>BanOnEvent</code> has been configured for the
508 <code>MaxLoginAttempts</code> event. That event has occurred once, and
509 will need to happen one more time within 589 seconds in order for an
510 automatic ban to be added.
511
512 <p>
513 See also: <a href="#permit"><code>permit</code></a>
514
515 <p>
516 <hr>
517 <h3><a name="permit"><code>permit</code></a></h3>
518 <strong>Syntax:</strong> ftpdctl permit <em>class|host|user|user@host [-s address#port] name1 [name2 ...]</em><br>
519 <strong>Purpose:</strong> Permit banned clients to connect<br>
520
521 <p>
522 The <code>permit</code> action is used to remove a ban for users, hosts,
523 and classes:
524 <pre>
525 # ftpdctl permit user dave
526 # ftpdctl permit user -s 1.2.3.4#21 dave
527 # ftpdctl permit host 1.2.3.4 gw.evil.com
528 # ftpdctl permit class anonftp
529 </pre>
530
531 <p>
532 See also: <a href="#ban"><code>ban</code></a>
533
534 <p>
535 <hr>
536 <h2><a name="Installation">Installation</a></h2>
537 The <code>mod_ban</code> module is distributed with ProFTPD. Simply follow
538 the normal steps for using third-party modules in ProFTPD, making sure to
539 include the <code>--enable-ctrls</code> configure option, which
540 <code>mod_ban</code> requires:
541 <pre>
542 $ ./configure --enable-ctrls --with-modules=mod_ban
543 </pre>
544 To build <code>mod_ban</code> as a DSO module:
545 <pre>
546 $ ./configure --enable-ctrls --enable-dso --with-shared=mod_ban
547 </pre>
548 Then follow the usual steps:
549 <pre>
550 $ make
551 $ make install
552 </pre>
553
554 <p>
555 For those with an existing ProFTPD installation, you can use the
556 <code>prxs</code> tool to add <code>mod_ban</code>, as a DSO module, to
557 your existing server:
558 <pre>
559 $ prxs -c -i -d mod_ban.c
560 </pre>
561
562 <p>
563 <hr>
564 <h2><a name="Usage">Usage</a></h2>
565 The <code>mod_ban</code> module implements its bans by checking if a client
566 is banned, either by <i>host</i> or by <i>class</i>, when that client
567 <i>connects to the server</i>. Banned clients are immediately disconnected.
568 Banned <i>users</i> are checked after the client has sent the <code>USER</code>
569 and <code>PASS</code> commands; if that user has been banned, the client is
570 immediately disconnected.
571
572 <p>
573 Here is an example <code>mod_ban</code> configuration, demonstrating how
574 to configure an automatic ban for <code>MaxLoginAttempts</code>:
575 <pre>
576 MaxLoginAttempts 1
577
578 &lt;IfModule mod_ban.c&gt;
579 BanEngine on
580 BanLog /var/log/proftpd/ban.log
581 BanTable /var/data/proftpd/ban.tab
582
583 # If the same client reaches the MaxLoginAttempts limit 2 times
584 # within 10 minutes, automatically add a ban for that client that
585 # will expire after one hour.
586 BanOnEvent MaxLoginAttempts 2/00:10:00 01:00:00
587
588 # Allow the FTP admin to manually add/remove bans
589 BanControlsACLs all allow user ftpadm
590 &lt;/IfModule&gt;
591 </pre>
592
593 <p>
594 By default, the <code>mod_ban</code> module allocate size for 512 bans.
595 In practice, this has seemed to work well. However, if you need to allocate
596 space for more bans, you will need to recompile proftpd, and use the
597 <code>CFLAGS</code> environment variable like so:
598 <pre>
599 ./configure CFLAGS="-DBAN_LIST_MAXSZ=<em>1024</em>" ...
600 </pre>
601 or whatever your necessary ban list size is.
602
603 <p>
604 <b>Logging</b><br>
605 The <code>mod_ban</code> module supports <a href="../howto/Tracing.html">trace logging</a>, via the module-specific log channels:
606 <ul>
607 <li>ban
608 </ul>
609 Thus for trace logging, to aid in debugging, you would use the following in
610 your <code>proftpd.conf</code>:
611 <pre>
612 TraceLog /path/to/ftpd/trace.log
613 Trace ban:20
614 </pre>
615 This trace logging can generate large files; it is intended for debugging use
616 only, and should be removed from any production configuration.
617
618 <p><a name="FAQ"></a>
619 <b>Frequently Asked Questions</b><br>
620 <font color=red>Question</font>: Why does <code>mod_ban</code> not store ban
621 data across daemon stop/starts?<br>
622 <font color=blue>Answer</font>: The <code>mod_ban</code> module was not
623 designed to add yet another ACL mechanism to <code>proftpd</code>. For
624 persistent access control, there is the <code>&lt;Limit LOGIN&gt;</code>
625 section, the <code>mod_wrap</code> module, the <code>/etc/ftpusers</code>
626 file, and various other mechanisms. The purpose of <code>mod_ban</code>
627 is to provide dynamic, short-lived bans.
628
629 <p>
630 <font color=red>Question</font>: What about having <code>proftpd</code> delay
631 sending responses to clients, say by 30 seconds or so?<br>
632 <font color=blue>Answer</font>: This is a bad idea. It would allow
633 malicious clients, who <i>knew</i> they were banned, to tie up your
634 <code>proftpd</code> processes, since those processes would be taking up
635 space, waiting before sending responses back to the client. This makes it
636 possible for those clients to use the delaying as a Denial of Service attack,
637 eventually tying up your available system resources with waiting
638 <code>proftpd</code> processes.
639
640 <p><a name="BanMaxLoginAttempts">
641 <font color=red>Question</font>: I have the following, taken from
642 the example config above, configured for <code>mod_ban</code>, but it does not
643 appear to be working. Why not?<br>
644 <pre>
645 # If the same client reaches the MaxLoginAttempts limit 2 times
646 # within 10 minutes, automatically add a ban for that client that
647 # will expire after one hour.
648 BanOnEvent MaxLoginAttempts 2/00:10:00 01:00:00
649 </pre>
650 <font color=blue>Answer</font>: The most common reason is that the
651 <code>MaxLoginAttempts</code> directive does not function the way that many
652 assume it does.
653
654 <p>
655 The above <code>BanOnEvent</code> rule says that the same client (<i>i.e.</i>
656 source IP address) which reaches the <code>MaxLoginAttempts</code> limit
657 2 times within 10 minutes will be banned. If you test by connecting to
658 <code>proftpd</code>, trying a bad password once, disconnecting, then
659 connecting again and trying the same bad password again, you will <b>not</b>
660 be hitting the <code>MaxLoginAttempts</code> limit. Remember that the
661 <code>MaxLoginAttempts</code> directive configures a limit to the number
662 of bad login attempts <i>for the same connection</i>; it does <b>not</b>
663 configure limit on the number of bad login attempts across multiple
664 connections.
665
666 <p>
667 The default <code>MaxLoginAttempts</code> value for <code>proftpd</code>
668 is 3. Which means that simply connecting, trying a bad login attempt once,
669 then disconnecting, will not trigger the <code>MaxLoginAttempts</code> limit.
670 This is why the example configuration given above explicitly configures
671 the <code>MaxLoginAttempts</code> limit to be lower:
672 <pre>
673 MaxLoginAttempts 1
674 </pre>
675 in order to make <code>mod_ban</code> behave the way that most administrators
676 assume it will. If you have not explicitly configured
677 <code>MaxLoginAttempts</code> lower, then this is probably why your
678 <code>BanOnEvent</code> rule is not taking effect as you expect.
679
680 <p>
681 <font color=red>Question</font>: It looks like the <code>BanTable</code> file
682 I configured is untouched:
683 <pre>
684 -rw-r--r-- 1 ftp ftp 0 2007-01-13 23:18 ban.table
685 </pre>
686 Does this mean that something is wrong, or that <code>mod_ban</code> is not
687 using that file?<br>
688 <p>
689 <font color=blue>Answer</font>: A <code>BanTable</code> file <i>is</i> needed,
690 just not in an obvious way. The <code>mod_ban</code> module stores its ban
691 information in a SysV shared memory segment. The configured
692 <code>BanTable</code> file is used <i>a)</i> to generate a unique name/ID for
693 the shared memory segment to use (and to see if a segment for that name/ID
694 already exists), and <i>b)</i> for locking, as when multiple sessions are
695 trying to update the shared memory segment at the same time. But
696 <code>mod_ban</code> does not write any data into that file itself, and hence
697 the last-modified-time of the file, and the file size, does not change much.
698
699 <p><a name="BanWhitelist">
700 <font color=red>Question</font>: How can I configure a whitelist of IP
701 addresses, to be excluded from the effects of <code>mod_ban</code>?<br>
702 <font color=blue>Answer</font>: This can be done using a combination of
703 <a href="../howto/Classes.html">Classes</a> and the <a href="mod_ifsession.html"><code>mod_ifsession</code></a> module. For example:
704 <pre>
705 &lt;Class whitelist&gt;
706 From ...
707 &lt;/Class&gt;
708
709 &lt;IfClass whitelist&gt;
710 # Turn the mod_ban module off for whitelisted clients
711 BanEngine off
712 &lt;/IfClass&gt;
713
714 &lt;IfClass !whitelist&gt;
715 # Make sure the mod_ban module is on for clients that are not whitelisted
716 BanEngine on
717 &lt;/IfClass&gt;
718 </pre>
719 Note that it is <b>important</b> to have <i>both</i>
720 <code>&lt;IfClass&gt;</code> sections in your configuration.
721
722 <p>
723 It is <b>also important</b> that for the above to work, when using shared/DSO
724 modules, that <code>mod_ban</code> be loaded in your configuration
725 <i>before</i> <code>mod_ifsession</code>:
726 <pre>
727 LoadModule mod_ban.c
728 ...
729 LoadModule mod_ifsession.c
730 </pre>
731 Otherwise, when parsing the configuration, <code>mod_ban</code> might not
732 set all of the proper internal state for implementing the whitelists.
733
734 <p><a name="BanRootLogins">
735 <font color=red>Question</font>: I would like to ban clients which try to
736 login as root. How would I do this?<br>
737 <font color=blue>Answer</font>: You would use the
738 <a href="#BanOnEvent"><code>BanOnEvent</code></a> directive, with an
739 <em>event name</em> of "mod_auth.root-login", thus:
740 <pre>
741 # Ban clients which try to login as root. This bans clients which
742 # try root logins twice within 10 minutes, banning them for 6 hours.
743 BanOnEvent mod_auth.root-login 2/00:10:00 06:00:00
744 </pre>
745
746 <br><hr>
747
748 <font size=2><b><i>
749 &copy; Copyright 2004-2022 TJ Saunders<br>
750 All Rights Reserved<br>
751 </i></b></font>
752
753 <hr><br>
754
755 </body>
756 </html>