| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD module mod_delay</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center> |
| 11 | <h2><b>ProFTPD module <code>mod_delay</code></b></h2> |
| 12 | </center> |
| 13 | <hr><br> |
| 14 | |
| 15 | <p> |
| 16 | The <code>mod_delay</code> module is designed to make a certain type of |
| 17 | information leak, known as a "timing attack", harder. |
| 18 | |
| 19 | <p> |
| 20 | When <code>proftpd</code> processes the <code>USER</code> and <code>PASS</code> |
| 21 | FTP commands from a client, it has to perform checks against configured |
| 22 | ACLs, look up user and group information, etc. These checks are not done |
| 23 | if the given username is known to not exist for the server, in order to |
| 24 | not tie up system resources needlessly. However, this does mean that more |
| 25 | work is done when handling "good" users than when handling |
| 26 | "bad" users. This difference can be detected in the time it takes |
| 27 | for <code>proftpd</code> to send a response to the <code>USER</code> and |
| 28 | <code>PASS</code> commands. This means it is possible for an attacker |
| 29 | to look for these statistical timing differences, and determine which |
| 30 | users are "good" and which are "bad". From there, |
| 31 | a determined attacker can focus their attention on the known good usernames. |
| 32 | Note that the timings will vary depending on server load, number of |
| 33 | users in the user base, type of storage of user data (<i>e.g.</i> |
| 34 | LDAP directories, SQL tables, RADIUS servers, flat files, <i>etc</i>). |
| 35 | |
| 36 | <p> |
| 37 | The <code>mod_delay</code> module attempts to prevent such timing differences |
| 38 | by keeping track of the time taken to process the <code>USER</code> and |
| 39 | <code>PASS</code> commands. It does this for the most recent |
| 40 | <code>USER</code> and <code>PASS</code> commands. The timing data are |
| 41 | stored in the module's <code>DelayTable</code>. If the module detects |
| 42 | that <code>proftpd</code> has not taken enough time to handle one of these |
| 43 | commands, compared to its past response times, a small delay will be added |
| 44 | to the response cycle. The amount of delay is determined by the difference |
| 45 | between the current time spent handling the command and the median time |
| 46 | spent handling the same command in the past. |
| 47 | |
| 48 | <p> |
| 49 | The most current version of <code>mod_delay</code> can be found in the |
| 50 | ProFTPD source distribution: |
| 51 | <pre> |
| 52 | <a href="http://www.proftpd.org/">http://www.proftpd.org/</a> |
| 53 | </pre> |
| 54 | |
| 55 | <h2>Thanks</h2> |
| 56 | <p> |
| 57 | <i>2004-10-18</i>: Thanks to Michael Renner for testing out various versions |
| 58 | of the module as it was developed. |
| 59 | |
| 60 | <h2>Directives</h2> |
| 61 | <ul> |
| 62 | <li><a href="#DelayControlsACLs">DelayControlsACLs</a> |
| 63 | <li><a href="#DelayEngine">DelayEngine</a> |
| 64 | <li><a href="#DelayOnEvent">DelayOnEvent</a> |
| 65 | <li><a href="#DelayTable">DelayTable</a> |
| 66 | </ul> |
| 67 | |
| 68 | <h2>Control Actions</h2> |
| 69 | <ul> |
| 70 | <li><a href="#delay_info"><code>delay info</code></a> |
| 71 | <li><a href="#delay_reset"><code>delay reset</code></a> |
| 72 | </ul> |
| 73 | |
| 74 | <hr> |
| 75 | <h3><a name="DelayControlsACLs">DelayControlsACLs</a></h3> |
| 76 | <strong>Syntax:</strong> DelayControlsACLs <em>actions|"all" "allow"|"deny" "user"|"group" list</em><br> |
| 77 | <strong>Default:</strong> None<br> |
| 78 | <strong>Context:</strong> server config<br> |
| 79 | <strong>Module:</strong> mod_delay<br> |
| 80 | <strong>Compatibility:</strong> 1.3.1rc1 and later |
| 81 | |
| 82 | <p> |
| 83 | The <code>DelayControlsACLs</code> directive configures access lists of |
| 84 | <em>users</em> or <em>groups</em> who are allowed (or denied) the ability to |
| 85 | use the <em>actions</em> implemented by <code>mod_delay</code>. The default |
| 86 | behavior is to deny everyone unless an ACL allowing access has been explicitly |
| 87 | configured. |
| 88 | |
| 89 | <p> |
| 90 | If "allow" is used, then <em>list</em>, a comma-delimited list |
| 91 | of <em>users</em> or <em>groups</em>, can use the given <em>actions</em>; all |
| 92 | others are denied. If "deny" is used, then the <em>list</em> of |
| 93 | <em>users</em> or <em>groups</em> cannot use <em>actions</em> all others are |
| 94 | allowed. Multiple <code>DelayControlsACLs</code> directives may be used to |
| 95 | configure ACLs for different control actions, and for both users and groups. |
| 96 | |
| 97 | <p> |
| 98 | <hr> |
| 99 | <h3><a name="DelayEngine">DelayEngine</a></h3> |
| 100 | <strong>Syntax:</strong> DelayEngine <em>on|off</em><br> |
| 101 | <strong>Default:</strong> DelayEngine on<br> |
| 102 | <strong>Context:</strong> server config<br> |
| 103 | <strong>Module:</strong> mod_delay<br> |
| 104 | <strong>Compatibility:</strong> 1.2.10rc1 and later |
| 105 | |
| 106 | <p> |
| 107 | The <code>DelayEngine</code> directive enables or disables the module's |
| 108 | runtime delaying calculations. If it is set to <em>off</em> this module |
| 109 | does no delaying. Use this directive to disable the module. |
| 110 | |
| 111 | <p> |
| 112 | Example: |
| 113 | <pre> |
| 114 | <IfModule mod_delay.c> |
| 115 | DelayEngine off |
| 116 | </IfModule> |
| 117 | </pre> |
| 118 | |
| 119 | <p> |
| 120 | <hr> |
| 121 | <h3><a name="DelayOnEvent">DelayOnEvent</a></h3> |
| 122 | <strong>Syntax:</strong> DelayOnEvent <em>event</em> <em>delay-ms</em><br> |
| 123 | <strong>Default:</strong> None<br> |
| 124 | <strong>Context:</strong> server config<br> |
| 125 | <strong>Module:</strong> mod_delay<br> |
| 126 | <strong>Compatibility:</strong> 1.3.6rc1 and later |
| 127 | |
| 128 | <p> |
| 129 | The <code>DelayOnEvent</code> directive configures an explicit |
| 130 | <em>delay-ms</em>, in milliseconds, for the given <em>event</em>. The |
| 131 | supported values for the <em>event</em> parameter are: |
| 132 | <ul> |
| 133 | <li>USER |
| 134 | <li>PASS |
| 135 | <li>FailedLogin |
| 136 | <li>Connect |
| 137 | </ul> |
| 138 | The <em>delay-ms</em> parameter can be a number (in which case the units are |
| 139 | assumed to be milliseconds), or using a suffix. In addition, the <em>delay-ms</em> parameter can provide a <i>range</i>, from minium to maximum (but only |
| 140 | for <code>Connect</code> events currently). |
| 141 | |
| 142 | <p> |
| 143 | To help illustrate the usage of <code>DelayOnEvent</code>, here are some |
| 144 | examples: |
| 145 | <pre> |
| 146 | DelayOnEvent PASS 2000ms |
| 147 | </pre> |
| 148 | This configures <code>mod_delay</code> to always add a delay of 2000 |
| 149 | milliseconds for every PASS command. Alternatively, to add a delay <i>only |
| 150 | on failed logins</i>, you might use: |
| 151 | <pre> |
| 152 | DelayOnEvent FailedLogin 5s |
| 153 | </pre> |
| 154 | which adds a delay of 5 seconds after the login has failed. |
| 155 | |
| 156 | <p> |
| 157 | And to inject delays at connect time, to "spread out" the processing of |
| 158 | many connections that occur with a short span of time, you can use: |
| 159 | <pre> |
| 160 | DelayOnEvent Connect 100-3000ms |
| 161 | </pre> |
| 162 | to inject a minimum 100ms delay to the start of a session, with a randomly |
| 163 | selected additional <em>jitter</em> delay for a maximum possible delay of |
| 164 | 3000ms (3 sec). |
| 165 | |
| 166 | <p> |
| 167 | <hr> |
| 168 | <h3><a name="DelayTable">DelayTable</a></h3> |
| 169 | <strong>Syntax:</strong> DelayTable <em>path</em>|<em>"none"</em><br> |
| 170 | <strong>Default:</strong> DelayTable /var/proftpd/proftpd.delay<br> |
| 171 | <strong>Context:</strong> server config<br> |
| 172 | <strong>Module:</strong> mod_delay<br> |
| 173 | <strong>Compatibility:</strong> 1.2.10rc1 and later |
| 174 | |
| 175 | <p> |
| 176 | The <code>DelayTable</code> directive configures a <em>path</em> to a file |
| 177 | that <code>mod_delay</code> uses for storing its timing data. The given |
| 178 | <em>path</em> must be an absolute path. It is recommended that this file |
| 179 | <b>not</b> be on an NFS mounted partition. |
| 180 | |
| 181 | <p> |
| 182 | Note that timing data is kept across daemon stop/starts. When new |
| 183 | <code><VirtualHost></code>s are added to the configuration, though, |
| 184 | <code>mod_delay</code> will detect that it does not have a suitable |
| 185 | <code>DelayTable</code> for the new configuration, and will clear all |
| 186 | stored data. |
| 187 | |
| 188 | <p> |
| 189 | If the <code>DelayTable</code> parameter is <em>"none"</em>, then the |
| 190 | <code>mod_delay</code> module will <b>not</b> store timing data. This |
| 191 | configuration is used, in conjunction with |
| 192 | <a href="#DelayOnEvent"><code>DelayOnEvent</code></a>, for setting explicit |
| 193 | delays, rather than learning/adapting the delays dynamically. |
| 194 | |
| 195 | <p> |
| 196 | <hr> |
| 197 | <h2>Control Actions</h2> |
| 198 | |
| 199 | <p> |
| 200 | <hr> |
| 201 | <h3><a name="delay_info"><code>delay info</code></a></h3> |
| 202 | <strong>Syntax:</strong> ftpdctl delay info<br> |
| 203 | <strong>Purpose:</strong> Display data from the DelayTable<br> |
| 204 | |
| 205 | <p> |
| 206 | The <code>delay info</code> control action can be used to view the timing |
| 207 | data currently stored in the <code>DelayTable</code> file. This can help |
| 208 | to determine why the <code>mod_delay</code> module might be adding |
| 209 | longer-than-expected delays to the login sequence for FTP sessions. |
| 210 | |
| 211 | <p> |
| 212 | <hr> |
| 213 | <h3><a name="delay_reset"><code>delay reset</code></a></h3> |
| 214 | <strong>Syntax:</strong> ftpdctl delay reset<br> |
| 215 | <strong>Purpose:</strong> Reset the DelayTable, clearing all data<br> |
| 216 | |
| 217 | <p> |
| 218 | The <code>delay reset</code> control action can be used to clear the |
| 219 | <code>DelayTable</code> of all timing information, resetting the table. |
| 220 | This can be used if the table starts to collect delays that are too long |
| 221 | to be useful. |
| 222 | |
| 223 | <p> |
| 224 | <hr> |
| 225 | <h2><a name="Usage">Usage</a></h2> |
| 226 | The <code>mod_delay</code> module provides protection against a very specific |
| 227 | problem. However, the module may not be appropriate for all situations. |
| 228 | |
| 229 | <p> |
| 230 | For some sites, the delay added by <code>mod_delay</code> is not |
| 231 | helpful, and in fact can annoy users. To disable <code>mod_delay</code>, |
| 232 | simply add the following to your <code>proftpd.conf</code> file: |
| 233 | <pre> |
| 234 | <IfModule mod_delay.c> |
| 235 | DelayEngine off |
| 236 | </IfModule> |
| 237 | </pre> |
| 238 | |
| 239 | <p> |
| 240 | For other sites, malicious users may notice that they can add arbitrarily |
| 241 | long delays to <i>all</i> users' sessions by "poisoning" |
| 242 | <code>mod_delay</code>'s cache of timing information. For example, a |
| 243 | malicious client might connect, send a <code>USER</code> command, and then |
| 244 | not disconnect for long time. After a few such clients have connected, |
| 245 | <code>mod_delay</code> will add a delay for <i>all</i> clients, such that |
| 246 | some legitimate clients may time out. In effect, this may look like a sort |
| 247 | of denial of service (DoS). |
| 248 | |
| 249 | <p> |
| 250 | To guard against the above situation, there are two possible solutions. |
| 251 | First, you can disable the <code>mod_delay</code> module entirely (see above); |
| 252 | if the timing information leak is not of concern for your FTP site, this is |
| 253 | the recommended approach. Second, you can use the |
| 254 | <a href="../contrib/mod_ifsession.html"><code>mod_ifsession</code></a> module |
| 255 | and its <code><IfClass></code> sections so that the |
| 256 | <code>mod_delay</code> module applies only to certain DNS names and |
| 257 | IP address ranges. For example: |
| 258 | <pre> |
| 259 | # Define a class which identifies trusted clients |
| 260 | <Class trusted> |
| 261 | From a.b.c.d |
| 262 | From e.f.g.h |
| 263 | </Class> |
| 264 | |
| 265 | <IfModule mod_delay.c> |
| 266 | <IfClass trusted> |
| 267 | DelayEngine off |
| 268 | </IfClass> |
| 269 | |
| 270 | <IfClass !trusted> |
| 271 | DelayEngine on |
| 272 | </IfClass> |
| 273 | </IfModule> |
| 274 | </pre> |
| 275 | More information on defining classes can be found <a href="../howto/Classes.html">here</a>. |
| 276 | |
| 277 | <p> |
| 278 | <b>Logging</b><br> |
| 279 | The <code>mod_delay</code> module supports <a href="../howto/Tracing.html">trace logging</a>, via the module-specific log channels: |
| 280 | <ul> |
| 281 | <li>delay |
| 282 | </ul> |
| 283 | Thus for trace logging, to aid in debugging, you would use the following in |
| 284 | your <code>proftpd.conf</code>: |
| 285 | <pre> |
| 286 | TraceLog /path/to/ftpd/trace.log |
| 287 | Trace delay:20 |
| 288 | </pre> |
| 289 | This trace logging can generate large files; it is intended for debugging use |
| 290 | only, and should be removed from any production configuration. |
| 291 | |
| 292 | <p><a name="FAQ"> |
| 293 | <b>Frequently Asked Questions</b><br> |
| 294 | |
| 295 | <p> |
| 296 | <font color=red>Question</font>: My client times out, after a couple of minutes, |
| 297 | after sending the <code>USER</code> command. After disabling <code>mod_delay</code>, the login succeeds quickly. Isn't this a bug in <code>mod_delay</code>?<br> |
| 298 | <font color=blue>Answer</font>: No. |
| 299 | |
| 300 | <p> |
| 301 | The <code>DelayTable</code> file can, over time, build up a store of long |
| 302 | delay values. A series of logins which take a while (<i>e.g.</i> SSL/TLS |
| 303 | handshakes over slow network connections) can cause this sort of behavior. |
| 304 | You can delete the <code>DelayTable</code> file or use the <a href="#delay_reset"><code>delay reset</code></a> ftpdctl action to clear the stored data. |
| 305 | |
| 306 | <p> |
| 307 | <font color=red>Question</font>: Shouldn't <code>mod_delay</code> have some |
| 308 | sort of maximum delay value, so that it doesn't cause timeouts?<br> |
| 309 | <font color=blue>Answer</font>: No. There is no single value, hardcoded |
| 310 | or configurable, that will work well for all sites <i>and</i> achieve |
| 311 | <code>mod_delay</code>'s purpose at the same time. What seems like a normal |
| 312 | delay time for one site will be unacceptably long for another site. |
| 313 | |
| 314 | <p> |
| 315 | <font color=red>Question</font>: Is it OK to configure my |
| 316 | <code>DelayTable</code> on some ephemeral storage like <code>tmpfs</code>?<br> |
| 317 | <font color=blue>Answer</font>: Yes, this is fine. |
| 318 | |
| 319 | <p> |
| 320 | The <code>mod_delay</code> module is designed to create and populate a new |
| 321 | <code>DelayTable</code> when one is not present. So if your |
| 322 | <code>DelayTable</code> is stored on something like <code>tmpfs</code> such |
| 323 | that it goes away when your host is restarted, <code>mod_delay</code> will |
| 324 | create a new one. This <i>does</i> mean that the previously stored timing |
| 325 | data will be lost, and that <code>mod_delay</code> will start calculating and |
| 326 | storing new timing data; the functional impact should be negligible. |
| 327 | |
| 328 | <p> |
| 329 | <hr> |
| 330 | <h2><a name="Installation">Installation</a></h2> |
| 331 | The <code>mod_delay</code> module is compiled by default. |
| 332 | |
| 333 | <p> |
| 334 | <br><hr> |
| 335 | |
| 336 | <font size=2><b><i> |
| 337 | © Copyright 2004-2023 The ProFTPD Project<br> |
| 338 | All Rights Reserved<br> |
| 339 | </i></b></font> |
| 340 | |
| 341 | <hr><br> |
| 342 | |
| 343 | </body> |
| 344 | </html> |