| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD: Globbing</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center><h2><b>ProFTPD: Globbing</b></h2></center> |
| 11 | <hr> |
| 12 | |
| 13 | <p> |
| 14 | <b>What is Globbing?</b><br> |
| 15 | Globbing is a common Unix shell mechanism for expanding wildcard patterns, |
| 16 | for matching multiple filenames. From the <code>glob(7)</code> man page: |
| 17 | <pre> |
| 18 | A string is a wildcard pattern if it contains one of the characters |
| 19 | `?', `*' or `['. Globbing is the operation that expands a wildcard pattern |
| 20 | into the list of pathnames matching the pattern. Matching is defined by: |
| 21 | |
| 22 | A `?' (not between brackets) matches any single character. |
| 23 | |
| 24 | A `*' (not between brackets) matches any string, including the empty |
| 25 | string. |
| 26 | </pre> |
| 27 | The RFCs that define FTP do not explicitly mention globbing; this means that |
| 28 | FTP servers are <i>not</i> required to support globbing in order to be |
| 29 | compliant. However, many FTP servers <i>do</i> support globbing (including |
| 30 | ProFTPD), as a measure of convenience for FTP clients and users. |
| 31 | |
| 32 | <p> |
| 33 | The <code>mget</code> <code>ftp(1)</code> command commonly uses globbing |
| 34 | to retrieve multiple files, <i>e.g.</i>: |
| 35 | <pre> |
| 36 | ftp> mget *.gz |
| 37 | </pre> |
| 38 | or: |
| 39 | <pre> |
| 40 | ftp> mget pub/music/*.mp3 |
| 41 | </pre> |
| 42 | Other FTP clients may have similar client-side commands for listing and |
| 43 | retrieiving multiple files based on globbing expressions. |
| 44 | |
| 45 | <p> |
| 46 | <b>Why Globbing is an Issue</b><br> |
| 47 | In order to search for and match the given globbing expression, the code |
| 48 | has to search (possibly) many directories, examine each contained filename, |
| 49 | and build a list of matching files in memory. This operation can be quite |
| 50 | intensive, both CPU- and memory-wise. This intense use of resources led |
| 51 | to the original posting of possible Denial of Service (DoS) attacks |
| 52 | against <code>proftpd</code> (later, when the culprit was tracked to the |
| 53 | underlying library globbing code, other applications were found to be |
| 54 | vulnerable as well): |
| 55 | <pre> |
| 56 | <a href="http://bugs.proftpd.org/show_bug.cgi?id=1066">http://bugs.proftpd.org/show_bug.cgi?id=1066</a> |
| 57 | </pre> |
| 58 | The above bug report shows an example of a globbing expression that was |
| 59 | used to attempt a DoS by means of many directory levels. |
| 60 | |
| 61 | <p> |
| 62 | Some servers (<i>e.g.</i> <code>wu-ftpd</code>) come with their own custom code |
| 63 | for handling globs; others (including <code>proftpd</code>) make use of the |
| 64 | system's C library routines for globbing. The GNU globbing code, bundled |
| 65 | with <code>proftpd</code>, was updated to match the current GNU implementation |
| 66 | of globbing in their C library (<code>glibc</code>), and <code>proftpd</code> |
| 67 | was changed to always use that bundled GNU code, rather than the host system's |
| 68 | globbing functions (as the host code might possibly be unsafe). |
| 69 | |
| 70 | <p> |
| 71 | Every now and then, this issue is reported on various mailing lists. As |
| 72 | <i>some</i> system resources are needed when handling globbing expression, |
| 73 | some users report this as a DoS possibility. Which is why <code>proftpd</code> |
| 74 | supports a few ways to restrict how globbing is handled, according to the |
| 75 | needs of the site. |
| 76 | |
| 77 | <p> |
| 78 | <b>Globbing Restrictions</b><br> |
| 79 | ProFTPD has several mechanisms in place for limiting, or disabling entirely, |
| 80 | support for globbing. If your site does not require globbing, it is highly |
| 81 | recommended that globbing be disabled altogether, by adding this to your |
| 82 | <code>proftpd.conf</code>: |
| 83 | <pre> |
| 84 | UseGlobbing off |
| 85 | </pre> |
| 86 | |
| 87 | <p> |
| 88 | If, on the other hand, your site <i>does</i> need to support globbing (many |
| 89 | FTP users will assume that globbing is supported), there are other ways of |
| 90 | limiting the amount of resources used when globbing: the |
| 91 | <a href="../modules/mod_rlimit.html#RLimitCPU"><code>RLimitCPU</code></a> and |
| 92 | <a href="../modules/mod_rlimit.html#RLimitMemory"><code>RLimitMemory</code></a> |
| 93 | configuration directives. In <code>proftpd-1.2.7</code>, these directives were enhanced so that they could be applied |
| 94 | strictly to session processes (rather than the daemon process): |
| 95 | <pre> |
| 96 | RLimitCPU session ... |
| 97 | RLimitMemory session ... |
| 98 | </pre> |
| 99 | And, for the paranoid system administrator, a way of limiting the number |
| 100 | of directories supported in a globbing expression was added in <code>1.2.8rc1</code>: <code>PR_TUNABLE_GLOBBING_MAX_RECURSION</code>. By default, the maximum |
| 101 | number of levels supported is 8 (this is the hardcoded default in the GNU |
| 102 | library implementation of globbing). To change this to a lower number, compile |
| 103 | <code>proftpd</code> using a <code>configure</code> line that looks |
| 104 | something like this: |
| 105 | <pre> |
| 106 | $ ./configure CFLAGS="-DPR_TUNABLE_GLOBBING_MAX_RECURSION=3" ... |
| 107 | </pre> |
| 108 | A globbing expression that contains more than the maximum number of supported |
| 109 | levels is not executed, but instead an error code signalling |
| 110 | "out of memory" is immediately returned, which is GNU's way of saying |
| 111 | that it will not handle the expression. |
| 112 | |
| 113 | <p> |
| 114 | There is a similar limit on the maximum number of files that will be checked |
| 115 | for a glob expression. By default, this limit is 100000 (the hardcoded default |
| 116 | in the GNU library <code>glob(3)</code> implementation). In the |
| 117 | <code>1.3.3rc1</code> ProFTPD release, a way of altering this limit was |
| 118 | added: <code>PR_TUNABLE_GLOBBING_MAX_MATCHES</code>. For sites which really |
| 119 | do require a higher number of files to be matched for their glob expressions, |
| 120 | the following <code>configure</code> command can be used: |
| 121 | <pre> |
| 122 | $ ./configure CFLAGS="-DPR_TUNABLE_GLOBBING_MAX_MATCHES=200000UL" ... |
| 123 | </pre> |
| 124 | A globbing expression that needs to examine more files than this limit will |
| 125 | have the number of matches silently truncated to the limit (or just below). |
| 126 | |
| 127 | <p> |
| 128 | <hr> |
| 129 | <font size=2><b><i> |
| 130 | © Copyright 2017 The ProFTPD Project<br> |
| 131 | All Rights Reserved<br> |
| 132 | </i></b></font> |
| 133 | <hr> |
| 134 | |
| 135 | </body> |
| 136 | </html> |