summaryrefslogtreecommitdiff
path: root/doc/source/features.rst
diff options
context:
space:
mode:
Diffstat (limited to 'doc/source/features.rst')
-rw-r--r--doc/source/features.rst73
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
4Snuffleupagus has a lot of features that can be divided in two main categories: bug-classes 4Snuffleupagus has a lot of features that can be divided in two main categories: bug-classes
5killers and virtual-patching. The first category provides primitives to kill various 5killers and virtual-patching. The first category provides primitives to kill various
6bug families (like arbitrary code execution via ``unserialize`` for example) or rise the 6bug families (like arbitrary code execution via ``unserialize`` for example) or raise the
7cost of exploitation, the second one is a highly configurable system to patch functions in php itself. 7cost of exploitation. The second category is a highly configurable system to patch functions in php itself.
8 8
9Bug classes killed or mitigated 9Bug 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
15The ``system`` function execute an external program and displays the output. 15The ``system`` function executes an external program and displays the output.
16It's used to interract with various external tools, like file-format converters for example. 16It is used to interact with various external tools, like file-format converters.
17Unfortunately, passing user-controlled parameters to it often leads to an arbitrary command execution. 17Unfortunately, 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
25We're mitigating it by filtering the ``$``, ``|``, ``;``, `````, ``\n`` and ``&`` chars in our 25We're mitigating it by filtering the ``$``, ``|``, ``;``, `````, ``\n`` and ``&`` chars in our
26default configuration, making it a lot harder for an attacker to inject arbitrary commands. 26default configuration, making it a lot harder for an attacker to inject arbitrary commands.
27 27
28This family of vulnerabilities lead to various CVE, like: 28This 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
40This vulnerability is known `since 2011 <http://esec-pentest.sogeti.com/posts/2011/11/03/using-mail-for-remote-code-execution.html>`_, 40This vulnerability has been known `since 2011 <http://esec-pentest.sogeti.com/posts/2011/11/03/using-mail-for-remote-code-execution.html>`_
41and was popularized by `RIPS <https://www.ripstech.com/blog/2016/roundcube-command-execution-via-email/>`_ in 2016. 41and was popularized by `RIPS <https://www.ripstech.com/blog/2016/roundcube-command-execution-via-email/>`_ in 2016.
42The last flag of the `mail` function can be used to pass various parameters to 42The last flag of the `mail` function can be used to pass various parameters to
43the underlying binary used to send emails: this can lead to an arbitrary file write, 43the underlying binary used to send emails; this can lead to an arbitrary file write,
44often meaning an arbitrary code execution. 44often 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
63The goto payload for XSS is often to steal cookies. 63The goto payload for XSS is often to steal cookies.
64Like *Suhosin*, we are encrypting the cookies with a secret key, 64Like *Suhosin*, we are encrypting the cookies with a secret key,
65an environment variable (usually the IP of the user) 65an environment variable (usually the IP of the user)
66and its user-agent. This means that an attacker with an XSS won't be able to use 66and the user's user-agent. This means that an attacker with an XSS won't be able to use
67the stolen cookie, since he can't spoof the content of the value of the environment 67the stolen cookie, since he can't spoof the content of the value of the environment
68variable for the user. Please do read the :ref:`documentation about this feature <cookie-encryption_config>` 68variable for the user. Please do read the :ref:`documentation about this feature <cookie-encryption_config>`
69if you're planning to use it. 69if you're planning to use it.
@@ -81,10 +81,9 @@ library because of its portability, simplicity and reduced size (a single `.h` a
81Remote code execution via file-upload 81Remote code execution via file-upload
82^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 82^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
83 83
84Some PHP applications allows users to upload contents, like avatars for a forum. 84Some PHP applications allows users to upload content like avatars to a forum.
85Unfortunately, sometimes, content validation isn't implemented properly (if at all), 85Unfortunately, content validation often isn't implemented properly (if at all),
86meaning arbitrary file upload, often leading, contrary to what the documentation is saying, 86meaning arbitrary file upload often leads to an arbitrary code execution, contrary to the documentation.
87to 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
107PHP is able to *serialize* arbitrary objects, to easily store them. 106PHP is able to *serialize* arbitrary objects, to easily store them.
108Unfortunately, it's often possible to gain arbitrary code execution upon deserialization 107Unfortunately, it is often possible to gain arbitrary code execution upon deserialization
109of user-supplied serialized objects. 108of 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.
117We're killing it by exploiting the fact that PHP will discard any garbage found at the end of a serialized object, 116We're killing it by exploiting the fact that PHP will discard any garbage found at the end of a serialized object,
118allowing us to simply append a `HMAC <https://en.wikipedia.org/wiki/Hash-based_message_authentication_code>`_ 117allowing us to simply append a `HMAC <https://en.wikipedia.org/wiki/Hash-based_message_authentication_code>`_
119at the end of strings generated by the ``serialize``, 118at the end of strings generated by the ``serialize``,
120hence guaranteeing that any object deserialized came from the application, 119hence guaranteeing that any object deserialized came from the application
121and wasn't tampered with, 120and wasn't tampered with.
122 121
123We're not encrypting it, like we do with the cookies, 122We aren't encrypting it, like we do with the cookies,
124allowing this feature to be disabled (or switch into leaning mode) 123allowing this feature to be disabled (or switch into leaning mode)
125without the need to invalidate any data. 124without 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
135A nice side-effect of this feature is that it'll defeat various memory corruption 134A nice side-effect of this feature is that it will defeat various memory corruption
136issues related to the complexity of ``unserialize``'s implementation, 135issues related to the complexity of ``unserialize``'s implementation,
137and the amount of control if provides to an attacker, like `CVE-2016-9137, CVE-2016-9138 <https://bugs.php.net/bug.php?id=73147>`_, 136and 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
140This family of vulnerabilities lead to various CVE, like: 139This family of vulnerabilities lead to various CVE, like:
141 140
@@ -155,8 +154,8 @@ Weak-PRNG via rand/mt_rand
155^^^^^^^^^^^^^^^^^^^^^^^^^^ 154^^^^^^^^^^^^^^^^^^^^^^^^^^
156 155
157The functions ``rand`` and ``mt_rand`` are often used to generate random numbers used 156The functions ``rand`` and ``mt_rand`` are often used to generate random numbers used
158in sensitive context, like password generation, token creation, … 157in sensitive context, like password generation, token creation.
159Unfortunately, as said in the documentation, the quality of their entropy is low, 158Unfortunately, as stated in the documentation, the quality of their entropy is low,
160leading to the generation of guessable values. 159leading 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
197Despite the documentation saying nothing about this class of vulnerabilities, 196Despite 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
199code execution. 198code execution.
200 199
201XML documents can contain a `Document Type Definition <https://www.w3.org/TR/REC-xml/#sec-prolog-dtd>`_ (DTD), 200XML documents can contain a `Document Type Definition <https://www.w3.org/TR/REC-xml/#sec-prolog-dtd>`_ (DTD),
202enabling definition of XML entities. It's possible to define an (external) entity by an 201enabling definition of XML entities. It is possible to define an (external) entity by a
203URI, that the parser will access, and embed its content back into the document 202URI, that the parser will access and embed its content back into the document
204for further processing. 203for further processing.
205 204
206For example, providing an url like ``file:///etc/passwd`` will read 205For example, providing an url like ``file:///etc/passwd`` will read
207this file's content, and since it's not valid XML, the application 206the file's content. Since the file is not valid XML, the application
208will spit it out in an error message, thus leaking its content. 207will spit it out in an error message, thus leaking its content.
209 208
210We're killing this class of vulnerabilities by calling 209We'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
212function with its parameter set to ``true`` at startup, 211function with its parameter set to ``true`` at startup,
213and then *nop'ing* it, so it won't do anything if ever called again. 212and then *nop'ing* it, so it won't do anything if ever called again.
214 213
215This family of vulnerabilities lead to various CVE, like: 214This 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
247PHP itself exposes a number of functions that might be considered **dangerous** and that have limited legitimate use cases. 246PHP 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
251However, (ie. ``system()``) they might have legitimate use cases in processes such as self upgrade etc., making it impossible to effectively 250However, (ie. ``system()``) they might have legitimate use cases in processes such as self upgrade etc., making it impossible to effectively
252disable them - at the risk of breaking critical features. 251disable them - at the risk of breaking critical features.
253 252
254SnuffleuPagus allows the user to restrict usage of specific functions per files, or per 253Snuffleupagus allows the user to restrict usage of specific functions per file, or per
255files with a matching (sha256) hash, thus allowing the use of such functions **only** in the intended places. 254file with a matching (sha256) hash, thus allowing the use of such functions **only** in the intended places.
256 255
257Furthermore, running the `following script <FIXME>`_ will generate an hash and line-based whitelist 256Furthermore, running the `following script <FIXME>`_ will generate an hash and line-based whitelist
258of dangerous functions, droping them everywhere else: 257of dangerous functions, droping them everywhere else:
@@ -283,7 +282,7 @@ since every internal function from php has them.
283 282
284This option provide a switch to globally activate this strict mode, 283This option provide a switch to globally activate this strict mode,
285helping to uncover vulnerabilities like the classical 284helping 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>`_
287and various other types mismatch. 286and various other types mismatch.
288 287
289This feature is largely inspired from the 288This 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,
297odds are that (thanks to the default `umask <https://en.wikipedia.org/wiki/Umask>`_) 296odds are that (thanks to the default `umask <https://en.wikipedia.org/wiki/Umask>`_)
298this file is writable by the PHP process. 297this file is writable by the PHP process.
299 298
300Snuffleupagus can prevent the execution of this kind of files. A good practise 299Snuffleupagus can prevent the execution of this kind of file. A good practice
301would be to use a different user to run PHP than for administrating the website, 300would be to use a different user to run PHP than for administrating the website,
302and using this feature to lock this up. 301and 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).
321Available functions recon 320Available functions recon
322""""""""""""""""""""""""" 321"""""""""""""""""""""""""
323 322
324After compromising a website, most of the time, the attacker does some recon 323Usually after compromising a website the attacker does some recon
325within its webshell, to check which functions are available to execute arbitrary code, 324within its webshell, to check which functions are available to execute arbitrary code.
326since it's not uncommon for some web-hoster to disable things like ``system`` or ``passthru``, 325Since it's not uncommon for some web-hosts to disable things like ``system`` or ``passthru``,
327or to check if mitigations are enabled, like ``open_basedir``. 326or to check if mitigations are enabled, like ``open_basedir``.
328This behaviour can be detected by preventing the execution of functions like ``ini_get`` 327This behaviour can be detected by preventing the execution of functions like ``ini_get``
329or ``is_callable`` with *suspicious* parameters. 328or ``is_callable`` with *suspicious* parameters.
@@ -352,6 +351,6 @@ queries that contains some. The same filtering idea can be used against
352SQL functions that are frequently used in SQL injections, like ``sleep``, ``benchmark`` 351SQL functions that are frequently used in SQL injections, like ``sleep``, ``benchmark``
353or strings like ``version_info``. 352or strings like ``version_info``.
354 353
355Still about SQL injections, if a function performing a query returns ``FALSE`` 354On 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