| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD: Connection ACLs</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center><h2><b>ProFTPD: Connection ACLs</b></h2></center> |
| 11 | <hr> |
| 12 | |
| 13 | <p> |
| 14 | Many sites running <code>proftpd</code> have the need to limit/reject |
| 15 | connections from known bad addresses, or to accept connections only from |
| 16 | known good addresses. ProFTPD supports several different mechanisms for |
| 17 | implementing FTP connection ACLs. |
| 18 | |
| 19 | <p> |
| 20 | However, there is one important thing to note: <b>ProFTPD is not a firewall.</b> |
| 21 | Never forget this. You <b>cannot</b> <i>prevent</i> TCP connections from ever |
| 22 | reaching <code>proftpd</code> in the first place by using <code>proftpd</code> |
| 23 | itself. This means that for many sites with connection ACL needs, their |
| 24 | system's firewall capabilities may be a better mechanism for implementing ACLs. |
| 25 | |
| 26 | <p> |
| 27 | <b><code><Limit LOGIN></code>, and Whitelists versus Blacklists</b><br> |
| 28 | The easiest way of accepting/rejecting connections is to use ProFTPD's |
| 29 | <a href="Limit.html"><code><Limit></code></a> syntax, particularly |
| 30 | <code><Limit LOGIN></code>. |
| 31 | |
| 32 | <p> |
| 33 | For example, you can simply reject all connections to your <code>proftpd</code> |
| 34 | instance by using: |
| 35 | <pre> |
| 36 | <Limit LOGIN> |
| 37 | DenyAll |
| 38 | </Limit> |
| 39 | </pre> |
| 40 | A more practical example would look like: |
| 41 | <pre> |
| 42 | <Limit LOGIN> |
| 43 | # These are trusted addresses |
| 44 | Allow from 1.2.3.4 5.6.7.8 |
| 45 | Allow from trusted-domain.com |
| 46 | |
| 47 | # Everyone else is denied |
| 48 | DenyAll |
| 49 | </Limit> |
| 50 | </pre> |
| 51 | |
| 52 | <p> |
| 53 | The above configuration demonstrates the concept of a <i>whitelist</i>: known |
| 54 | trusted (<i>i.e.</i> "white") addresses are explicitly listed and allowed, and |
| 55 | all others are denied. Conversely, you might use a <i>blacklist</i>, where |
| 56 | known bad/malicious/untrusted (<i>i.e.</i> "black") addresses are explicitly |
| 57 | listed and denied, and all others are allowed: |
| 58 | <pre> |
| 59 | <Limit LOGIN> |
| 60 | Order deny,allow |
| 61 | |
| 62 | # These are known bad addresses |
| 63 | Deny from 1.2.3.4 5.6.7.8 |
| 64 | Deny from evil-domain.com |
| 65 | |
| 66 | # Everyone else is allowed |
| 67 | AllowAll |
| 68 | </Limit> |
| 69 | </pre> |
| 70 | |
| 71 | <p> |
| 72 | It is useful to know about whitelists versus blacklists, as it can affect |
| 73 | how large your ACLs become. Sites which run publicly available FTP servers |
| 74 | but which need to weed out bad clients tend to use blacklists; over time, |
| 75 | these blacklists can become quite large. Sites which know who will be using |
| 76 | their FTP server and only want those people to be able to connect will use |
| 77 | whitelists; these whitelists tend to remain fairly small/short. |
| 78 | |
| 79 | <p> |
| 80 | <b>Large Blacklists</b><br> |
| 81 | Let's assume that you are running a public FTP server, and that you are using |
| 82 | a <code><Limit LOGIN></code> section to make a blacklist. Your site |
| 83 | may even have some script which detects bad clients, and automatically adds |
| 84 | them to your blacklist, <i>e.g.</i>: |
| 85 | <pre> |
| 86 | <Limit LOGIN> |
| 87 | Order deny,allow |
| 88 | |
| 89 | # -- Add blacklisted addresses here -- |
| 90 | Deny from ... |
| 91 | Deny from ... |
| 92 | # <b>Many</b> more <code>Deny from</code> lines |
| 93 | |
| 94 | # Allow everyone not explicitly blacklisted |
| 95 | AllowAll |
| 96 | </Limit> |
| 97 | </pre> |
| 98 | Over time, your number of blacklisted IP addresses starts to become large |
| 99 | and unwieldy. You might have thousands of such addresses; you notice that |
| 100 | <code>proftpd</code> starts acting strangely, and starts slowing down. |
| 101 | |
| 102 | <p> |
| 103 | When this happens, you should start looking for ways to make your list shorter. |
| 104 | If your list is comprised of entries for each individual IP address, you |
| 105 | should think about using glob expressions and netmasks to reduce the number |
| 106 | of entries. For example, rather than using something like |
| 107 | this: |
| 108 | <pre> |
| 109 | Deny from 1.2.3.4 |
| 110 | Deny from 1.2.3.5 |
| 111 | Deny from 1.2.3.6 |
| 112 | Deny from 1.2.3.7 |
| 113 | Deny from 1.2.3.8 |
| 114 | Deny from 1.2.3.9 |
| 115 | </pre> |
| 116 | you could (as of <code>proftpd-1.3.4rc1</code> and later) use a range: |
| 117 | <pre> |
| 118 | Deny 1.2.3.[4-9] |
| 119 | </pre> |
| 120 | or even use a glob wildcard such as this, which makes for even fewer entries |
| 121 | in your address lists: |
| 122 | <pre> |
| 123 | Deny 1.2.3.* |
| 124 | </pre> |
| 125 | Or you could use netmasks such as: |
| 126 | <pre> |
| 127 | Deny 1.2.3.0/8 |
| 128 | </pre> |
| 129 | |
| 130 | <p> |
| 131 | <b>Using Classes</b><br> |
| 132 | Now let's assume that at this point you have used glob ranges and wildcards |
| 133 | and netmasks to make your ACL shorter, but it is still large, and |
| 134 | <code>proftpd</code> is still slow. It is time for you to use ProFTPD's |
| 135 | connection <a href="Classes.html">classes</a>. |
| 136 | |
| 137 | <p> |
| 138 | To do this, you would rewrite your large <code><Limit LOGIN></code> |
| 139 | section to look something like this: |
| 140 | <pre> |
| 141 | <Class blacklist> |
| 142 | # Put all of your blacklisted address/range lines here, as <code>From</code> lines |
| 143 | From ... |
| 144 | From ... |
| 145 | From ... |
| 146 | </Class> |
| 147 | |
| 148 | <Limit LOGIN> |
| 149 | Order deny,allow |
| 150 | |
| 151 | # Rejected blacklisted clients |
| 152 | DenyClass blacklist |
| 153 | |
| 154 | # Allow everyone else |
| 155 | AllowAll |
| 156 | </Limit> |
| 157 | </pre> |
| 158 | |
| 159 | <p> |
| 160 | Why does using classes like this make things faster? When using classes, the |
| 161 | label (<i>i.e.</i> the class name in the <code><Class></code> section, |
| 162 | like "blacklist" in the above example) is determined when the client |
| 163 | <i>first</i> connects to <code>proftpd</code>, before any comands are sent. |
| 164 | That is when all of the various netmasks and such are checked -- and |
| 165 | <i>only</i> at that time. After that, all of the configuration-based ACLs |
| 166 | are evaluated just using that label. |
| 167 | |
| 168 | <p> |
| 169 | When you do not use classes, then proftpd scans each configuration, each |
| 170 | netmask/address <b><i>for each command</i></b>. That's why things slow down so |
| 171 | much. |
| 172 | |
| 173 | <p> |
| 174 | <b>Alternatives</b><br> |
| 175 | There are a couple of other ways in which to implement connection ACLs; these |
| 176 | alternatives may be more efficient and/or better suited to your site's needs. |
| 177 | |
| 178 | <p> |
| 179 | You can use a module like |
| 180 | <a href="../contrib/mod_wrap2.html"><code>mod_wrap2</code></a>, particular its |
| 181 | support for storing ACLs in SQL tables. SQL lookups can be very quick, and |
| 182 | can easily support large numbers of addresses efficiently. |
| 183 | |
| 184 | <p> |
| 185 | And if you find yourself starting to block large blocks of addresses from |
| 186 | countries/regions, you should start thinking about connection ACLs in terms of |
| 187 | geolocation information. For this, the <a href="../contrib/mod_geoip.html"><code>mod_geoip</code></a> module for ProFTPD is quite useful. |
| 188 | |
| 189 | <p><a name="FAQ"> |
| 190 | <b>Frequently Asked Questions</b><br> |
| 191 | |
| 192 | <p> |
| 193 | <font color=red>Question</font>: Is there a limit to how many addresses can |
| 194 | appear in a single line in the config file?<br> |
| 195 | <font color=blue>Answer</font>: No. However, there <i>is</i> a maximum line |
| 196 | length, which is determined by the buffer size used by the configuration file |
| 197 | parser. That buffer size is usually 1024 bytes (1K). |
| 198 | |
| 199 | <p> |
| 200 | This 1024 byte length limitation can be worked around, however, by breaking |
| 201 | a single line in the configuration file into multiple lines using the |
| 202 | line continuation syntax, <i>e.g.</i>: |
| 203 | <pre> |
| 204 | Allow 1.2.3.4 5.6.7.8 9.10.11.12 |
| 205 | </pre> |
| 206 | can also appear as: |
| 207 | <pre> |
| 208 | Allow \ |
| 209 | 1.2.3.4 \ |
| 210 | 5.6.7.8 \ |
| 211 | 9.10.11.12 |
| 212 | </pre> |
| 213 | |
| 214 | <p> |
| 215 | <hr> |
| 216 | <font size=2><b><i> |
| 217 | © Copyright 2017 The ProFTPD Project<br> |
| 218 | All Rights Reserved<br> |
| 219 | </i></b></font> |
| 220 | <hr> |
| 221 | |
| 222 | </body> |
| 223 | </html> |