diff options
| author | Connor Carr | 2017-10-08 17:06:55 +0100 |
|---|---|---|
| committer | jvoisin | 2017-10-08 18:06:55 +0200 |
| commit | 21e6837c1c8442eb01e069b87a01e5996d41f2e9 (patch) | |
| tree | f97931aef6ea060a9d761c4acb62d6d3e9a6eaa2 /doc/source/features.rst | |
| parent | 99f18f7818f8f3ee354c78276d7cd981312c7d43 (diff) | |
Grammar/Punctuation changes (#29)
Diffstat (limited to 'doc/source/features.rst')
| -rw-r--r-- | doc/source/features.rst | 73 |
1 files changed, 36 insertions, 37 deletions
diff --git a/doc/source/features.rst b/doc/source/features.rst index c0fade3..3aab1a0 100644 --- a/doc/source/features.rst +++ b/doc/source/features.rst | |||
| @@ -3,8 +3,8 @@ Features | |||
| 3 | 3 | ||
| 4 | Snuffleupagus has a lot of features that can be divided in two main categories: bug-classes | 4 | Snuffleupagus has a lot of features that can be divided in two main categories: bug-classes |
| 5 | killers and virtual-patching. The first category provides primitives to kill various | 5 | killers and virtual-patching. The first category provides primitives to kill various |
| 6 | bug families (like arbitrary code execution via ``unserialize`` for example) or rise the | 6 | bug families (like arbitrary code execution via ``unserialize`` for example) or raise the |
| 7 | cost of exploitation, the second one is a highly configurable system to patch functions in php itself. | 7 | cost of exploitation. The second category is a highly configurable system to patch functions in php itself. |
| 8 | 8 | ||
| 9 | Bug classes killed or mitigated | 9 | Bug classes killed or mitigated |
| 10 | ------------------------------- | 10 | ------------------------------- |
| @@ -12,9 +12,9 @@ Bug classes killed or mitigated | |||
| 12 | ``system`` injections | 12 | ``system`` injections |
| 13 | ^^^^^^^^^^^^^^^^^^^^^ | 13 | ^^^^^^^^^^^^^^^^^^^^^ |
| 14 | 14 | ||
| 15 | The ``system`` function execute an external program and displays the output. | 15 | The ``system`` function executes an external program and displays the output. |
| 16 | It's used to interract with various external tools, like file-format converters for example. | 16 | It is used to interact with various external tools, like file-format converters. |
| 17 | Unfortunately, passing user-controlled parameters to it often leads to an arbitrary command execution. | 17 | Unfortunately, passing user-controlled parameters to it often leads to arbitrary command execution. |
| 18 | 18 | ||
| 19 | When allowing user-supplied data to be passed to this function, | 19 | When allowing user-supplied data to be passed to this function, |
| 20 | use `escapeshellarg()` or `escapeshellcmd()` to ensure that users cannot trick | 20 | use `escapeshellarg()` or `escapeshellcmd()` to ensure that users cannot trick |
| @@ -25,7 +25,7 @@ Unfortunately, passing user-controlled parameters to it often leads to an arbitr | |||
| 25 | We're mitigating it by filtering the ``$``, ``|``, ``;``, `````, ``\n`` and ``&`` chars in our | 25 | We're mitigating it by filtering the ``$``, ``|``, ``;``, `````, ``\n`` and ``&`` chars in our |
| 26 | default configuration, making it a lot harder for an attacker to inject arbitrary commands. | 26 | default configuration, making it a lot harder for an attacker to inject arbitrary commands. |
| 27 | 27 | ||
| 28 | This family of vulnerabilities lead to various CVE, like: | 28 | This family of vulnerabilities lead to various CVE entries, like: |
| 29 | 29 | ||
| 30 | - `CVE-2017-7981 <https://tuleap.net/plugins/tracker/?aid=10159>`_: Authenticated remote code execution on Tuleap | 30 | - `CVE-2017-7981 <https://tuleap.net/plugins/tracker/?aid=10159>`_: Authenticated remote code execution on Tuleap |
| 31 | - `CVE-2014-4688 <https://www.pfsense.org/security/advisories/pfSense-SA-14_10.webgui.asc>`_: Authenticated remote code execution on pfSense | 31 | - `CVE-2014-4688 <https://www.pfsense.org/security/advisories/pfSense-SA-14_10.webgui.asc>`_: Authenticated remote code execution on pfSense |
| @@ -37,10 +37,10 @@ This family of vulnerabilities lead to various CVE, like: | |||
| 37 | ``mail``-related injections | 37 | ``mail``-related injections |
| 38 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 38 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 39 | 39 | ||
| 40 | This vulnerability is known `since 2011 <http://esec-pentest.sogeti.com/posts/2011/11/03/using-mail-for-remote-code-execution.html>`_, | 40 | This vulnerability has been known `since 2011 <http://esec-pentest.sogeti.com/posts/2011/11/03/using-mail-for-remote-code-execution.html>`_ |
| 41 | and was popularized by `RIPS <https://www.ripstech.com/blog/2016/roundcube-command-execution-via-email/>`_ in 2016. | 41 | and was popularized by `RIPS <https://www.ripstech.com/blog/2016/roundcube-command-execution-via-email/>`_ in 2016. |
| 42 | The last flag of the `mail` function can be used to pass various parameters to | 42 | The last flag of the `mail` function can be used to pass various parameters to |
| 43 | the underlying binary used to send emails: this can lead to an arbitrary file write, | 43 | the underlying binary used to send emails; this can lead to an arbitrary file write, |
| 44 | often meaning an arbitrary code execution. | 44 | often meaning an arbitrary code execution. |
| 45 | 45 | ||
| 46 | The ``additional_parameters`` parameter can be used to pass additional flags | 46 | The ``additional_parameters`` parameter can be used to pass additional flags |
| @@ -63,7 +63,7 @@ Session-cookie stealing via XSS | |||
| 63 | The goto payload for XSS is often to steal cookies. | 63 | The goto payload for XSS is often to steal cookies. |
| 64 | Like *Suhosin*, we are encrypting the cookies with a secret key, | 64 | Like *Suhosin*, we are encrypting the cookies with a secret key, |
| 65 | an environment variable (usually the IP of the user) | 65 | an environment variable (usually the IP of the user) |
| 66 | and its user-agent. This means that an attacker with an XSS won't be able to use | 66 | and the user's user-agent. This means that an attacker with an XSS won't be able to use |
| 67 | the stolen cookie, since he can't spoof the content of the value of the environment | 67 | the stolen cookie, since he can't spoof the content of the value of the environment |
| 68 | variable for the user. Please do read the :ref:`documentation about this feature <cookie-encryption_config>` | 68 | variable for the user. Please do read the :ref:`documentation about this feature <cookie-encryption_config>` |
| 69 | if you're planning to use it. | 69 | if you're planning to use it. |
| @@ -81,10 +81,9 @@ library because of its portability, simplicity and reduced size (a single `.h` a | |||
| 81 | Remote code execution via file-upload | 81 | Remote code execution via file-upload |
| 82 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 82 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 83 | 83 | ||
| 84 | Some PHP applications allows users to upload contents, like avatars for a forum. | 84 | Some PHP applications allows users to upload content like avatars to a forum. |
| 85 | Unfortunately, sometimes, content validation isn't implemented properly (if at all), | 85 | Unfortunately, content validation often isn't implemented properly (if at all), |
| 86 | meaning arbitrary file upload, often leading, contrary to what the documentation is saying, | 86 | meaning arbitrary file upload often leads to an arbitrary code execution, contrary to the documentation. |
| 87 | to an arbitrary code execution. | ||
| 88 | 87 | ||
| 89 | Not validating which file you operate on may mean that users can *access sensitive information* in other directories. | 88 | Not validating which file you operate on may mean that users can *access sensitive information* in other directories. |
| 90 | 89 | ||
| @@ -105,11 +104,11 @@ Unserialize-related magic | |||
| 105 | ^^^^^^^^^^^^^^^^^^^^^^^^^ | 104 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 106 | 105 | ||
| 107 | PHP is able to *serialize* arbitrary objects, to easily store them. | 106 | PHP is able to *serialize* arbitrary objects, to easily store them. |
| 108 | Unfortunately, it's often possible to gain arbitrary code execution upon deserialization | 107 | Unfortunately, it is often possible to gain arbitrary code execution upon deserialization |
| 109 | of user-supplied serialized objects. | 108 | of user-supplied serialized objects. |
| 110 | 109 | ||
| 111 | Do not pass untrusted user input to ``unserialize()`` regardless of the options value of allowed_classes. | 110 | Do not pass untrusted user input to ``unserialize()`` regardless of the options value of allowed_classes. |
| 112 | Unserialization can result in code being loaded and executed due to object instantiation and autoloading, | 111 | Unserialization can result in code being loaded and executed due to object instantiation and autoloading |
| 113 | and a malicious user may be able to exploit this. | 112 | and a malicious user may be able to exploit this. |
| 114 | 113 | ||
| 115 | --- `The PHP documentation about serialize <https://secure.php.net/manual/en/function.serialize.php>`_ | 114 | --- `The PHP documentation about serialize <https://secure.php.net/manual/en/function.serialize.php>`_ |
| @@ -117,25 +116,25 @@ of user-supplied serialized objects. | |||
| 117 | We're killing it by exploiting the fact that PHP will discard any garbage found at the end of a serialized object, | 116 | We're killing it by exploiting the fact that PHP will discard any garbage found at the end of a serialized object, |
| 118 | allowing us to simply append a `HMAC <https://en.wikipedia.org/wiki/Hash-based_message_authentication_code>`_ | 117 | allowing us to simply append a `HMAC <https://en.wikipedia.org/wiki/Hash-based_message_authentication_code>`_ |
| 119 | at the end of strings generated by the ``serialize``, | 118 | at the end of strings generated by the ``serialize``, |
| 120 | hence guaranteeing that any object deserialized came from the application, | 119 | hence guaranteeing that any object deserialized came from the application |
| 121 | and wasn't tampered with, | 120 | and wasn't tampered with. |
| 122 | 121 | ||
| 123 | We're not encrypting it, like we do with the cookies, | 122 | We aren't encrypting it, like we do with the cookies, |
| 124 | allowing this feature to be disabled (or switch into leaning mode) | 123 | allowing this feature to be disabled (or switch into leaning mode) |
| 125 | without the need to invalidate any data. | 124 | without the need to invalidate any data. |
| 126 | 125 | ||
| 127 | .. warning:: | 126 | .. warning:: |
| 128 | 127 | ||
| 129 | This feature can't be deployed on websites that already stored serialized | 128 | This feature can't be deployed on websites that already stored serialized |
| 130 | objects (ie. in database), since they are missing the HMAC, and thus will be detected as | 129 | objects (ie. in database), since they are missing the HMAC and thus will be detected as |
| 131 | an attack. If you're in this situation, you should use this feature with the | 130 | an attack. If you're in this situation, you should use this feature with the |
| 132 | ``simulation`` mode, and switch it off once you don't have any messages in your | 131 | ``simulation`` mode, and switch it off once you don't have any messages in your |
| 133 | logs. | 132 | logs. |
| 134 | 133 | ||
| 135 | A nice side-effect of this feature is that it'll defeat various memory corruption | 134 | A nice side-effect of this feature is that it will defeat various memory corruption |
| 136 | issues related to the complexity of ``unserialize``'s implementation, | 135 | issues related to the complexity of ``unserialize``'s implementation, |
| 137 | and the amount of control if provides to an attacker, like `CVE-2016-9137, CVE-2016-9138 <https://bugs.php.net/bug.php?id=73147>`_, | 136 | and the amount of control if provides to an attacker, like `CVE-2016-9137, CVE-2016-9138 <https://bugs.php.net/bug.php?id=73147>`_, |
| 138 | `2016-7124 <https://bugs.php.net/bug.php?id=72663>`_, `CVE-2016-5771 and CVE-2016-5773 <https://www.evonide.com/how-we-broke-php-hacked-pornhub-and-earned-20000-dollar/>`_, … | 137 | `2016-7124 <https://bugs.php.net/bug.php?id=72663>`_, `CVE-2016-5771 and CVE-2016-5773 <https://www.evonide.com/how-we-broke-php-hacked-pornhub-and-earned-20000-dollar/>`_. |
| 139 | 138 | ||
| 140 | This family of vulnerabilities lead to various CVE, like: | 139 | This family of vulnerabilities lead to various CVE, like: |
| 141 | 140 | ||
| @@ -155,8 +154,8 @@ Weak-PRNG via rand/mt_rand | |||
| 155 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | 154 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 156 | 155 | ||
| 157 | The functions ``rand`` and ``mt_rand`` are often used to generate random numbers used | 156 | The functions ``rand`` and ``mt_rand`` are often used to generate random numbers used |
| 158 | in sensitive context, like password generation, token creation, … | 157 | in sensitive context, like password generation, token creation. |
| 159 | Unfortunately, as said in the documentation, the quality of their entropy is low, | 158 | Unfortunately, as stated in the documentation, the quality of their entropy is low, |
| 160 | leading to the generation of guessable values. | 159 | leading to the generation of guessable values. |
| 161 | 160 | ||
| 162 | This function does not generate cryptographically secure values, and should not be used for cryptographic purposes. | 161 | This function does not generate cryptographically secure values, and should not be used for cryptographic purposes. |
| @@ -195,16 +194,16 @@ XXE | |||
| 195 | ^^^ | 194 | ^^^ |
| 196 | 195 | ||
| 197 | Despite the documentation saying nothing about this class of vulnerabilities, | 196 | Despite the documentation saying nothing about this class of vulnerabilities, |
| 198 | `XML eXternal Entitiy <https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Processing>`_ (XXE) are often leading to arbitrary file reading, SSRF, and sometimes even arbitrary | 197 | `XML eXternal Entity <https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Processing>`_ (XXE) often leads to arbitrary file reading, `SSRF <https://www.owasp.org/index.php/Server_Side_Request_Forgery>`_ and sometimes even arbitrary |
| 199 | code execution. | 198 | code execution. |
| 200 | 199 | ||
| 201 | XML documents can contain a `Document Type Definition <https://www.w3.org/TR/REC-xml/#sec-prolog-dtd>`_ (DTD), | 200 | XML documents can contain a `Document Type Definition <https://www.w3.org/TR/REC-xml/#sec-prolog-dtd>`_ (DTD), |
| 202 | enabling definition of XML entities. It's possible to define an (external) entity by an | 201 | enabling definition of XML entities. It is possible to define an (external) entity by a |
| 203 | URI, that the parser will access, and embed its content back into the document | 202 | URI, that the parser will access and embed its content back into the document |
| 204 | for further processing. | 203 | for further processing. |
| 205 | 204 | ||
| 206 | For example, providing an url like ``file:///etc/passwd`` will read | 205 | For example, providing an url like ``file:///etc/passwd`` will read |
| 207 | this file's content, and since it's not valid XML, the application | 206 | the file's content. Since the file is not valid XML, the application |
| 208 | will spit it out in an error message, thus leaking its content. | 207 | will spit it out in an error message, thus leaking its content. |
| 209 | 208 | ||
| 210 | We're killing this class of vulnerabilities by calling | 209 | We're killing this class of vulnerabilities by calling |
| @@ -212,7 +211,7 @@ the `libxml_disable_entity_loader <https://secure.php.net/manual/en/function.lib | |||
| 212 | function with its parameter set to ``true`` at startup, | 211 | function with its parameter set to ``true`` at startup, |
| 213 | and then *nop'ing* it, so it won't do anything if ever called again. | 212 | and then *nop'ing* it, so it won't do anything if ever called again. |
| 214 | 213 | ||
| 215 | This family of vulnerabilities lead to various CVE, like: | 214 | This family of vulnerabilities lead to various CVE vulnerabilities, like: |
| 216 | 215 | ||
| 217 | - `CVE-2015-5161 <https://legalhackers.com/advisories/eBay-Magento-XXE-Injection-Vulnerability.html>`_: Unauthenticated arbitrary file disclosure on Magento | 216 | - `CVE-2015-5161 <https://legalhackers.com/advisories/eBay-Magento-XXE-Injection-Vulnerability.html>`_: Unauthenticated arbitrary file disclosure on Magento |
| 218 | - `CVE-2014-8790 <https://github.com/GetSimpleCMS/GetSimpleCMS/issues/944>`_: Unauthenticated remote code execution in GetSimple CMS | 217 | - `CVE-2014-8790 <https://github.com/GetSimpleCMS/GetSimpleCMS/issues/944>`_: Unauthenticated remote code execution in GetSimple CMS |
| @@ -245,14 +244,14 @@ Virtual-patching | |||
| 245 | ^^^^^^^^^^^^^^^^ | 244 | ^^^^^^^^^^^^^^^^ |
| 246 | 245 | ||
| 247 | PHP itself exposes a number of functions that might be considered **dangerous** and that have limited legitimate use cases. | 246 | PHP itself exposes a number of functions that might be considered **dangerous** and that have limited legitimate use cases. |
| 248 | ``system()``, ``exec()``, ``dlopen()`` - for example - fall into this category. By default, PHP only allows to globally disable some functions. | 247 | ``system()``, ``exec()``, ``dlopen()`` - for example - fall into this category. By default, PHP only allows us to globally disable some functions. |
| 249 | 248 | ||
| 250 | 249 | ||
| 251 | However, (ie. ``system()``) they might have legitimate use cases in processes such as self upgrade etc., making it impossible to effectively | 250 | However, (ie. ``system()``) they might have legitimate use cases in processes such as self upgrade etc., making it impossible to effectively |
| 252 | disable them - at the risk of breaking critical features. | 251 | disable them - at the risk of breaking critical features. |
| 253 | 252 | ||
| 254 | SnuffleuPagus allows the user to restrict usage of specific functions per files, or per | 253 | Snuffleupagus allows the user to restrict usage of specific functions per file, or per |
| 255 | files with a matching (sha256) hash, thus allowing the use of such functions **only** in the intended places. | 254 | file with a matching (sha256) hash, thus allowing the use of such functions **only** in the intended places. |
| 256 | 255 | ||
| 257 | Furthermore, running the `following script <FIXME>`_ will generate an hash and line-based whitelist | 256 | Furthermore, running the `following script <FIXME>`_ will generate an hash and line-based whitelist |
| 258 | of dangerous functions, droping them everywhere else: | 257 | of dangerous functions, droping them everywhere else: |
| @@ -283,7 +282,7 @@ since every internal function from php has them. | |||
| 283 | 282 | ||
| 284 | This option provide a switch to globally activate this strict mode, | 283 | This option provide a switch to globally activate this strict mode, |
| 285 | helping to uncover vulnerabilities like the classical | 284 | helping to uncover vulnerabilities like the classical |
| 286 | `strcmp bypass <https://danuxx.blogspot.fr/2013/03/unauthorized-access-bypassing-php-strcmp.html>`_, | 285 | `strcmp bypass <https://danuxx.blogspot.fr/2013/03/unauthorized-access-bypassing-php-strcmp.html>`_ |
| 287 | and various other types mismatch. | 286 | and various other types mismatch. |
| 288 | 287 | ||
| 289 | This feature is largely inspired from the | 288 | This feature is largely inspired from the |
| @@ -297,7 +296,7 @@ If an attacker manages to upload an arbitrary file or to modify an existing one, | |||
| 297 | odds are that (thanks to the default `umask <https://en.wikipedia.org/wiki/Umask>`_) | 296 | odds are that (thanks to the default `umask <https://en.wikipedia.org/wiki/Umask>`_) |
| 298 | this file is writable by the PHP process. | 297 | this file is writable by the PHP process. |
| 299 | 298 | ||
| 300 | Snuffleupagus can prevent the execution of this kind of files. A good practise | 299 | Snuffleupagus can prevent the execution of this kind of file. A good practice |
| 301 | would be to use a different user to run PHP than for administrating the website, | 300 | would be to use a different user to run PHP than for administrating the website, |
| 302 | and using this feature to lock this up. | 301 | and using this feature to lock this up. |
| 303 | 302 | ||
| @@ -321,9 +320,9 @@ various examples and ideas of things that you might want to enable (or not). | |||
| 321 | Available functions recon | 320 | Available functions recon |
| 322 | """"""""""""""""""""""""" | 321 | """"""""""""""""""""""""" |
| 323 | 322 | ||
| 324 | After compromising a website, most of the time, the attacker does some recon | 323 | Usually after compromising a website the attacker does some recon |
| 325 | within its webshell, to check which functions are available to execute arbitrary code, | 324 | within its webshell, to check which functions are available to execute arbitrary code. |
| 326 | since it's not uncommon for some web-hoster to disable things like ``system`` or ``passthru``, | 325 | Since it's not uncommon for some web-hosts to disable things like ``system`` or ``passthru``, |
| 327 | or to check if mitigations are enabled, like ``open_basedir``. | 326 | or to check if mitigations are enabled, like ``open_basedir``. |
| 328 | This behaviour can be detected by preventing the execution of functions like ``ini_get`` | 327 | This behaviour can be detected by preventing the execution of functions like ``ini_get`` |
| 329 | or ``is_callable`` with *suspicious* parameters. | 328 | or ``is_callable`` with *suspicious* parameters. |
| @@ -352,6 +351,6 @@ queries that contains some. The same filtering idea can be used against | |||
| 352 | SQL functions that are frequently used in SQL injections, like ``sleep``, ``benchmark`` | 351 | SQL functions that are frequently used in SQL injections, like ``sleep``, ``benchmark`` |
| 353 | or strings like ``version_info``. | 352 | or strings like ``version_info``. |
| 354 | 353 | ||
| 355 | Still about SQL injections, if a function performing a query returns ``FALSE`` | 354 | On the topic of SQL injections, if a function performing a query returns ``FALSE`` |
| 356 | (indicating an error), it might be useful to dump the request for further analysis. | 355 | (indicating an error), it might be useful to dump the request for further analysis. |
| 357 | 356 | ||
