summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor Carr2017-10-08 17:06:55 +0100
committerjvoisin2017-10-08 18:06:55 +0200
commit21e6837c1c8442eb01e069b87a01e5996d41f2e9 (patch)
treef97931aef6ea060a9d761c4acb62d6d3e9a6eaa2
parent99f18f7818f8f3ee354c78276d7cd981312c7d43 (diff)
Grammar/Punctuation changes (#29)
-rw-r--r--doc/source/config.rst74
-rw-r--r--doc/source/faq.rst34
-rw-r--r--doc/source/features.rst73
-rw-r--r--doc/source/index.rst9
-rw-r--r--doc/source/installation.rst6
5 files changed, 97 insertions, 99 deletions
diff --git a/doc/source/config.rst b/doc/source/config.rst
index 7170385..1b2ed09 100644
--- a/doc/source/config.rst
+++ b/doc/source/config.rst
@@ -2,33 +2,33 @@ Configuration
2============= 2=============
3 3
4Since PHP *ini-like* configuration model isn't flexible enough, 4Since PHP *ini-like* configuration model isn't flexible enough,
5Snuffleupagus is using its own format, in the file specified by 5Snuffleupagus is using its own format in the file specified by
6the directive ``sp.configuration_file`` (in your ``php.ini`` file), 6the directive ``sp.configuration_file`` (in your ``php.ini`` file),
7like ``sp.configuration_file=/etc/php/conf.d/snuffleupagus.ini``. 7like ``sp.configuration_file=/etc/php/conf.d/snuffleupagus.ini``.
8 8
9Options are chainable by using dots (``.``), and string parameters 9Options are chainable by using dots (``.``) and string parameters
10**must** be quoted, while booleans and integers aren't. 10**must** be quoted, while booleans and integers aren't.
11 11
12Comments are prefixed either with ``#``, or ``;``. 12Comments are prefixed either with ``#``, or ``;``.
13 13
14Some rules applies in a specific ``function`` (context), on a specific ``variable`` 14Some rules apply in a specific ``function`` (context) on a specific ``variable``
15(data), like ``disable_functions``, others can only be enabled/disabled, like 15(data), like ``disable_functions``. Others can only be enabled/disabled, like
16``harden_random``. 16``harden_random``.
17 17
18 18
19.. warning:: 19.. warning::
20 20
21 Careful, a wrongly configured Snuffleupagus might break your website. 21 If you configure Snuffleupagus incorrectly, you could break your website.
22 It's up to you to understand its :doc:`features <features>`, 22 It's up to you to understand the :doc:`features <features>`,
23 read the present documentation about how to configure them, 23 read the present documentation about how to configure them,
24 evaluate your threat model, and write your configuration file accordingly. 24 evaluate your threat model and write your configuration file accordingly.
25 25
26Most of the features can be used in ``simulation`` mode by appending the 26Most of the features can be used in ``simulation`` mode by appending the
27``.simulation()`` option to them (eg. ``sp.readonly_exec.simulation()enable();``) to see 27``.simulation()`` option to them (eg. ``sp.readonly_exec.simulation()enable();``) to see
28if they might break your website. The simulation mode won't block the request, 28whether or not they could break your website. The simulation mode won't block the request,
29but will write a warning in the log. 29but will write a warning in the log.
30 30
31The rules are evaluated in the order that they are written, and the **first** one 31The rules are evaluated in the order that they are written, the **first** one
32to match will terminate the evaluation (except for rules in simulation mode). 32to match will terminate the evaluation (except for rules in simulation mode).
33 33
34Bugclass-killer features 34Bugclass-killer features
@@ -70,12 +70,12 @@ It can either be ``enabled`` or ``disabled``.
70global 70global
71^^^^^^ 71^^^^^^
72 72
73This configuration variable contain parameters that are used by other ones: 73This configuration variable contains parameters that are used by multiple functions:
74 74
75- ``secret_key``: A secret key used by various cryptographic features, 75- ``secret_key``: A secret key used by various cryptographic features,
76 like `cookies protection <features.html#session-cookie-stealing-via-xss>`__ or `unserialize protection <features.html#unserialize-related-magic>`__, 76 like `cookies protection <features.html#session-cookie-stealing-via-xss>`__ or `unserialize protection <features.html#unserialize-related-magic>`__,
77 so do make sure that it's random and long enough. 77 please ensure the length and complexity is sufficient.
78 You can generate it with something like this: ``head -c 256 /dev/urandom | tr -dc 'a-zA-Z0-9'``. 78 You can generate it with functions such as: ``head -c 256 /dev/urandom | tr -dc 'a-zA-Z0-9'``.
79 79
80:: 80::
81 81
@@ -86,10 +86,10 @@ unserialize_hmac
86 * `default: disabled` 86 * `default: disabled`
87 * `more <features.html#unserialize-related-magic>`__ 87 * `more <features.html#unserialize-related-magic>`__
88 88
89``unserialize_hmac`` will add integrity check to ``unserialize`` calls, preventing 89``unserialize_hmac`` will add an integrity check to ``unserialize`` calls, preventing
90abritrary code execution in their context. 90abritrary code execution in their context.
91 91
92It can either be ``enabled`` or ``disabled``, and used in ``simulation`` mode. 92It can either be ``enabled`` or ``disabled`` and can be used in ``simulation`` mode.
93 93
94:: 94::
95 95
@@ -120,15 +120,15 @@ cookie_encryption
120 120
121.. warning:: 121.. warning::
122 122
123 To use this feature, you **must** set the :ref:`global.secret_key <config_global>` and 123 To use this feature, you **must** set the :ref:`global.secret_key <config_global>`
124 and the :ref:`global.cookie_env_var <config_global>` variables. 124 and the :ref:`global.cookie_env_var <config_global>` variables.
125 This design decision prevents attacker from 125 This design decision prevents an attacker from
126 `trivially bruteforcing <https://www.idontplaydarts.com/2011/11/decrypting-suhosin-sessions-and-cookies/>`_ 126 `trivially bruteforcing <https://www.idontplaydarts.com/2011/11/decrypting-suhosin-sessions-and-cookies/>`_
127 or re-using session cookies. 127 or re-using session cookies.
128 128
129``cookie_secure`` will activate transparent encryption of specific cookies. 129``cookie_secure`` will activate transparent encryption of specific cookies.
130 130
131It can either be ``enabled`` or ``disabled``, and used in ``simulation`` mode. 131It can either be ``enabled`` or ``disabled`` and can be used in ``simulation`` mode.
132 132
133:: 133::
134 134
@@ -138,22 +138,22 @@ It can either be ``enabled`` or ``disabled``, and used in ``simulation`` mode.
138Choosing the proper environment variable 138Choosing the proper environment variable
139"""""""""""""""""""""""""""""""""""""""" 139""""""""""""""""""""""""""""""""""""""""
140 140
141It's up to you to chose a meaningul environment variable to derive the key from. 141It's up to you to choose a meaningful environment variable to derive the key from.
142Suhosin `is using <https://www.suhosin.org/stories/configuration.html#suhosin-session-cryptraddr>`_ 142Suhosin `is using <https://www.suhosin.org/stories/configuration.html#suhosin-session-cryptraddr>`_
143the ``REMOTE_ADDR`` one, tying the validity of the cookie to the IP address of the user; 143the ``REMOTE_ADDR`` one, tying the validity of the cookie to the IP address of the user;
144unfortunately, nowadays, people are `roaming <https://en.wikipedia.org/wiki/Roaming>`_ a lot on their smartphone, 144unfortunately, nowadays, people are `roaming <https://en.wikipedia.org/wiki/Roaming>`_ a lot on their smartphone,
145hopping from WiFi to 4G, … 145hopping from WiFi to 4G.
146 146
147This is why we recommend, if possible, to use the *extended master secret* 147This is why we recommend, if possible, to use the *extended master secret*
148from TLS connections (`RFC7627 <https://tools.ietf.org/html/rfc7627>`_) 148from TLS connections (`RFC7627 <https://tools.ietf.org/html/rfc7627>`_)
149instead, to make the valitity of the cookie TLS-dependent, by using the ``SSL_SESSION_ID`` variable. 149instead. The will make the validity of the cookie TLS-dependent, by using the ``SSL_SESSION_ID`` variable.
150 150
151- In `Apache <https://httpd.apache.org/docs/current/mod/mod_ssl.html>`_, 151- In `Apache <https://httpd.apache.org/docs/current/mod/mod_ssl.html>`_,
152 it possible to enable by adding ``SSLOptions StdEnvVars`` in your Apache2 configuration. 152 it is possible to enable by adding ``SSLOptions StdEnvVars`` in your Apache2 configuration.
153- In `nginx <https://nginx.org/en/docs/http/ngx_http_ssl_module.html#variables>`_, 153- In `nginx <https://nginx.org/en/docs/http/ngx_http_ssl_module.html#variables>`_,
154 you have to use ``fastcgi_param SSL_SESSION_ID $ssl_session_id if_not_empty;``. 154 you have to use ``fastcgi_param SSL_SESSION_ID $ssl_session_id if_not_empty;``.
155 155
156If you're not using TLS (you should.), you can always use the ``REMOTE_ADDR`` one, 156If you aren't using TLS (you should be), you can always use the ``REMOTE_ADDR`` one,
157or ``X-Real-IP`` if you're behind a reverse proxy. 157or ``X-Real-IP`` if you're behind a reverse proxy.
158 158
159readonly_exec 159readonly_exec
@@ -162,7 +162,7 @@ readonly_exec
162 162
163``readonly_exec`` will prevent the execution of writable PHP files. 163``readonly_exec`` will prevent the execution of writable PHP files.
164 164
165It can either be ``enabled`` or ``disabled``, and used in ``simulation`` mode. 165It can either be ``enabled`` or ``disabled`` and can be used in ``simulation`` mode.
166 166
167:: 167::
168 168
@@ -174,7 +174,7 @@ upload_validation
174 * `more <features.html#remote-code-execution-via-file-upload>`__ 174 * `more <features.html#remote-code-execution-via-file-upload>`__
175 175
176``upload_validation`` will call a given script upon a file upload, with the path 176``upload_validation`` will call a given script upon a file upload, with the path
177to the file being uploaded as argument, and various information about it in the environment: 177to the file being uploaded as argument and various information about it in the environment:
178 178
179* ``SP_FILENAME``: the name of the uploaded file 179* ``SP_FILENAME``: the name of the uploaded file
180* ``SP_FILESIZE``: the size of the file being uploaded 180* ``SP_FILESIZE``: the size of the file being uploaded
@@ -185,10 +185,10 @@ This feature can be used, for example, to check if an uploaded file contains php
185code, with something like `vld <https://derickrethans.nl/projects.html#vld>`_ 185code, with something like `vld <https://derickrethans.nl/projects.html#vld>`_
186(``php -d vld.execute=0 -d vld.active=1 -d extension=vld.so yourfile.php``). 186(``php -d vld.execute=0 -d vld.active=1 -d extension=vld.so yourfile.php``).
187 187
188The upload will be **allowed** if the script return the value ``0``. Every other 188The upload will be **allowed** if the script returns the value ``0``. Every other
189value will prevent the file from being uploaded. 189value will prevent the file from being uploaded.
190 190
191It can either be ``enabled`` or ``disabled``, and used in ``simulation`` mode. 191It can either be ``enabled`` or ``disabled`` and can be used in ``simulation`` mode.
192 192
193:: 193::
194 194
@@ -210,8 +210,8 @@ disable_xxe
210Virtual-patching 210Virtual-patching
211---------------- 211----------------
212 212
213Snuffleupagus provides virtual-patching, via the ``disable_functions`` directive, allowing you to stop or control dangerous behaviours. 213Snuffleupagus provides virtual-patching via the ``disable_functions`` directive, allowing you to stop or control dangerous behaviours.
214Admitting you have a call to ``system()`` that lacks proper user-input validation, thus leading to an **RCE**, this might be the right tool. 214In the situation where you have a call to ``system()`` that lacks proper user-input validation, this could cause issues as it would lead to an **RCE**. The virtual-patching would allow this to be prevented.
215 215
216:: 216::
217 217
@@ -219,7 +219,7 @@ Admitting you have a call to ``system()`` that lacks proper user-input validatio
219 sp.disable_functions.function("system").filename("id.php").param("cmd").value("id").allow(); 219 sp.disable_functions.function("system").filename("id.php").param("cmd").value("id").allow();
220 sp.disable_functions.function("system").filename("id.php").drop() 220 sp.disable_functions.function("system").filename("id.php").drop()
221 221
222Of course, this is a trivial example, and a lot can be achieved with this feature, as you will see below. 222Of course, this is a trivial example, a lot can be achieved with this feature, as you will see below.
223 223
224 224
225Filters 225Filters
@@ -238,7 +238,7 @@ Filters
238- ``ret(value)``: match on the function's return ``value`` 238- ``ret(value)``: match on the function's return ``value``
239- ``ret_r(regexp)``: match with a ``regexp`` on the function's return 239- ``ret_r(regexp)``: match with a ``regexp`` on the function's return
240- ``ret_type(type_name)``: match on the ``type_name`` of the function's return value 240- ``ret_type(type_name)``: match on the ``type_name`` of the function's return value
241- ``value(value)``: match on a litteral ``value`` 241- ``value(value)``: match on a literal ``value``
242- ``value_r(regexp)``: match on a value matching the ``regexp`` 242- ``value_r(regexp)``: match on a value matching the ``regexp``
243- ``var(name)``: match on a **local variable** ``name`` 243- ``var(name)``: match on a **local variable** ``name``
244 244
@@ -267,22 +267,22 @@ Details
267 267
268The ``function`` filter is able to do various dereferencing: 268The ``function`` filter is able to do various dereferencing:
269 269
270- ``function("AwesomeClass::my_method")`` will match in the method ``my_method`` in the class ``AwesomeClass`` 270- ``function("AwesomeClass::my_method")`` will match the method ``my_method`` in the class ``AwesomeClass``
271- ``function("AwesomeNamespace\\my_function")`` will match in the function ``my_function`` in the namespace ``AwesomeNamespace`` 271- ``function("AwesomeNamespace\\my_function")`` will match the function ``my_function`` in the namespace ``AwesomeNamespace``
272 272
273The ``param`` filter is also able to do some dereferencing: 273The ``param`` filter is also able to do some dereferencing:
274 274
275- ``param(foo[bar])`` will get match on the value corresponding to the ``bar`` key in the hashtable ``foo``. 275- ``param(foo[bar])`` will get a match on the value corresponding to the ``bar`` key in the hashtable ``foo``.
276 Remember that in PHP, almost every data structure is a hashtable. You can of course nest this like 276 Remember that in PHP, almost every data structure is a hashtable. You can of course nest this like
277 ``param(foo[bar][baz][batman])``. 277 ``param(foo[bar][baz][batman])``.
278- The ``var`` filter will walk the calltrace until it finds the variable's name, or the end of it, 278- The ``var`` filter will walk the calltrace until it finds the variable name, or the end of the calltrace,
279 allowing to match on global variables: ``.var("_GET[param]")`` will match on the GET parameter ``param``. 279 allowing the filter to match global variables: ``.var("_GET[param]")`` will match on the GET parameter ``param``.
280 280
281For clarity's sake, the presence of the ``allow`` or ``drop`` action is **mandatory**. 281For clarity, the presence of the ``allow`` or ``drop`` action is **mandatory**.
282 282
283.. warning:: 283.. warning::
284 284
285 When you're writing rules, please do keep in mind that the **order matters**. 285 When you're writing rules, please do keep in mind that **the order matters**.
286 For example, if you're denying a call to ``system()`` and then allowing it in a 286 For example, if you're denying a call to ``system()`` and then allowing it in a
287 more narrowed way later, the call will be denied, 287 more narrowed way later, the call will be denied,
288 because it'll match the deny first. 288 because it'll match the deny first.
diff --git a/doc/source/faq.rst b/doc/source/faq.rst
index 53d65ce..71326b6 100644
--- a/doc/source/faq.rst
+++ b/doc/source/faq.rst
@@ -8,19 +8,19 @@ What is Snuffleupagus?
8"""""""""""""""""""""" 8""""""""""""""""""""""
9 9
10Snuffleupagus is a `PHP7+ <http://php.net/manual/en/migration70.php>`_ 10Snuffleupagus is a `PHP7+ <http://php.net/manual/en/migration70.php>`_
11module designed to drastically raising the cost of attacks against website, 11module designed to drastically raise the cost of attacks against websites. This is achieved
12by killing entire bug classes, and also providing a powerful virtual-patching system, 12by killing entire bug classes and providing a powerful virtual-patching system,
13allowing administrator to fix specific vulnerabilities without having to touch the PHP code. 13allowing the administrator to fix specific vulnerabilities without having to touch the PHP code.
14 14
15 15
16Where does the name *Snuffeupagus* comes from? 16Where does the name *Snuffeupagus* come from?
17"""""""""""""""""""""""""""""""""""""""""""""" 17""""""""""""""""""""""""""""""""""""""""""""""
18 18
19 Aloysius Snuffleupagus, more commonly known as Mr. Snuffleupagus, Snuffleupagus 19 Aloysius Snuffleupagus, more commonly known as Mr. Snuffleupagus,
20 or Snuffy for short, is one of the characters on Sesame Street, 20 or Snuffy for short, is one of the characters on Sesame Street,
21 the educational television program for young children. 21 the educational television program for young children.
22 22
23 He was created as a woolly mammoth, without tusks or (visible) ears, 23 He was created as a woolly mammoth without tusks or (visible) ears,
24 and has a long thick pointed tail, similar in shape to that of a dinosaur 24 and has a long thick pointed tail, similar in shape to that of a dinosaur
25 or other reptile. He has long thick brown hair and a trunk, or "snuffle", 25 or other reptile. He has long thick brown hair and a trunk, or "snuffle",
26 that drags along the ground. He is Big Bird's best friend and 26 that drags along the ground. He is Big Bird's best friend and
@@ -43,9 +43,9 @@ We're working for `NBS System <https://nbs-system.com/en/>`__,
43a web hosting company (meaning that we're dealing with PHP code all day long), 43a web hosting company (meaning that we're dealing with PHP code all day long),
44with a strong focus on security. We do have hardening 44with a strong focus on security. We do have hardening
45(`kernel <https://grsecurity.net/>`_, `WAF <https://naxsi.org>`_, 45(`kernel <https://grsecurity.net/>`_, `WAF <https://naxsi.org>`_,
46`IDS <https://en.wikipedia.org/wiki/Intrusion_detection_system>`_, ) 46`IDS <https://en.wikipedia.org/wiki/Intrusion_detection_system>`_, etc)
47below the web stack, but most of the time, when a website is compromised, 47below the web stack, but most of the time, when a website is compromised,
48it's either to send ads, spam, deface it, steal data, 48it's can be to send ads, spam, deface it, steal data etc.
49This is why we need to harden the website itself too, but we can't touch its 49This is why we need to harden the website itself too, but we can't touch its
50source code. 50source code.
51 51
@@ -62,7 +62,7 @@ We're huge fans of `Suhosin <https://suhosin.org>`_, unfortunately:
62We're using the `disable_function <https://secure.php.net/manual/en/ini.core.php#ini.disable-functions>`_ 62We're using the `disable_function <https://secure.php.net/manual/en/ini.core.php#ini.disable-functions>`_
63directive, but unfortunately, it doesn't provide enough usable granularity (guess how many CMS are using 63directive, but unfortunately, it doesn't provide enough usable granularity (guess how many CMS are using
64the `system <https://secure.php.net/manual/en/function.system.php#refsect1-function.system-notes>`_ 64the `system <https://secure.php.net/manual/en/function.system.php#refsect1-function.system-notes>`_
65function to perform various mandatory maintenance tasks). 65function to perform various mandatory maintenance tasks).
66 66
67This is why we decided to write our own hardening module, in the spirit of Suhosin, 67This is why we decided to write our own hardening module, in the spirit of Suhosin,
68via virtual-patching support, and other cool new features. 68via virtual-patching support, and other cool new features.
@@ -70,7 +70,7 @@ via virtual-patching support, and other cool new features.
70What license is Snuffleupagus under and why? 70What license is Snuffleupagus under and why?
71"""""""""""""""""""""""""""""""""""""""""""" 71""""""""""""""""""""""""""""""""""""""""""""
72 72
73Snuffleupagus is licensed under the `LGPL <https://www.gnu.org/copyleft/lesser.html>`_, 73Snuffleupagus is licensed under the `LGPL <https://www.gnu.org/copyleft/lesser.html>`_
74and is developed by the fine people from `NBS System <https://nbs-system.com/>`__. 74and is developed by the fine people from `NBS System <https://nbs-system.com/>`__.
75 75
76We chose the LGPL because we don't care that much how you're using Snuffleupagus, 76We chose the LGPL because we don't care that much how you're using Snuffleupagus,
@@ -92,22 +92,22 @@ it becomes compromised.
92How mature is this project? 92How mature is this project?
93""""""""""""""""""""""""""" 93"""""""""""""""""""""""""""
94 94
95This project was floating around since early 2016, and we did the first commit 95This project was floating around since early 2016 and we did the first commit
96the 28ᵗʰ of December of the same year. We're currently in an alpha phase, 96the 28ᵗʰ of December of the same year. We're currently in an alpha phase,
97finding and fixing as much bugs as possible before the beta. 97finding and fixing as many bugs as possible before the beta.
98 98
99Are you saying that PHP isn't secure? 99Are you saying that PHP isn't secure?
100""""""""""""""""""""""""""""""""""""" 100"""""""""""""""""""""""""""""""""""""
101 101
102We don't like PHP's approach of security; namely (sometimes) adding warnings 102We don't like PHP's approach of security; namely (sometimes) adding warnings
103in the documentation and trusting the developer to not do any mistake, 103in the documentation and trusting the developer to not do any mistake,
104instead of focusing on the root cause, and killing the 104instead of focusing on the root cause and killing the
105bug class one for all. 105bug class once and for all.
106 106
107Moreover, it seems that the current attitude toward security in the PHP world 107Moreover, it seems that the current attitude toward security in the PHP world
108is to `blame the user <https://externals.io/message/100147>`_ instead of acknowledging 108is to `blame the user <https://externals.io/message/100147>`_ instead of acknowledging
109issues, as stated in their `documentation <https://wiki.php.net/security#not_a_security_issue>`_. 109issues, as stated in their `documentation <https://wiki.php.net/security#not_a_security_issue>`_.
110We do think that an security issue that "requires the use of code or settings known to be insecure" 110We do think that a security issue that "requires the use of code or settings known to be insecure"
111is still a security issue, and should be treated as such. 111is still a security issue, and should be treated as such.
112 112
113We don't have the pretention to state that Snuffleupagus will magically solve 113We don't have the pretention to state that Snuffleupagus will magically solve
@@ -133,12 +133,12 @@ Yes.
133 133
134Some options won't break anything, like :ref:`harden-rand <harden-rand-feature>`, 134Some options won't break anything, like :ref:`harden-rand <harden-rand-feature>`,
135but some like :ref:`global_strict <global-strict-feature>` 135but some like :ref:`global_strict <global-strict-feature>`
136or overly-restrictives :ref:`virtual-patching<virtual-patching-feature>` 136or overly-restrictive :ref:`virtual-patching<virtual-patching-feature>`
137rules might pretty well break your website. 137rules might pretty well break your website.
138It's up to you to configure Snuffleupaggus accordingly to your needs. 138It's up to you to configure Snuffleupaggus accordingly to your needs.
139 139
140You can also enable the ``simulation`` mode on features that you're not sure about, 140You can also enable the ``simulation`` mode on features that you're not sure about,
141to see what would snuffleupagus do to your application, before activating them for good. 141to see what snuffleupagus would do to your application, before activating them for good.
142 142
143How can I find out the problem when my application breaks? 143How can I find out the problem when my application breaks?
144"""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 144""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
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
diff --git a/doc/source/index.rst b/doc/source/index.rst
index 6de2fa8..9b91e18 100644
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -1,11 +1,10 @@
1Snuffleupagus 1Snuffleupagus
2============= 2=============
3 3
4Snuffleupagus is a `PHP 7+ <https://secure.php.net/>`_ module designed to 4Snuffleupagus is a `PHP7+ <http://php.net/manual/en/migration70.php>`_
5drastically raise the cost of attacks against website, by killing entire bug 5module designed to drastically raise the cost of attacks against websites. This is achieved
6classes, and also providing a powerful virtual-patching system, allowing 6by killing entire bug classes and providing a powerful virtual-patching system,
7administrator to fix specific vulnerabilities and audit suspicious behaviours 7allowing the administrator to fix specific vulnerabilities without having to touch the PHP code.
8without having to touch the PHP code.
9 8
10Documentation 9Documentation
11------------- 10-------------
diff --git a/doc/source/installation.rst b/doc/source/installation.rst
index fb68ccd..fb3e398 100644
--- a/doc/source/installation.rst
+++ b/doc/source/installation.rst
@@ -28,9 +28,9 @@ Quickstart
28 make 28 make
29 make install 29 make install
30 30
31This should install ``snuffleupagus.so`` file in your extension directory. 31This should install the ``snuffleupagus.so`` file in your extension directory.
32The final step is adding a load directive to ``php.ini``, 32The final step is adding a load directive to ``php.ini``
33and to specify the location of its :doc:`configuration file <config>`: 33and to specify the location of the :doc:`configuration file <config>`:
34 34
35:: 35::
36 36