diff options
| author | jvoisin | 2018-01-12 12:09:52 +0100 |
|---|---|---|
| committer | jvoisin | 2018-01-12 12:09:52 +0100 |
| commit | 44255b8dbf5c98c8d110c2e3918298ee6978b93c (patch) | |
| tree | b588c6b3b87eb18b8fd1c0fa5e41856c6e6fe2fd /doc | |
| parent | 5da0c0fa9351a758e28941a7d0b1755dd57fea9b (diff) | |
Massive overhaul of the documentation
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/source/config.rst | 105 | ||||
| -rw-r--r-- | doc/source/features.rst | 19 |
2 files changed, 67 insertions, 57 deletions
diff --git a/doc/source/config.rst b/doc/source/config.rst index 85e9da5..9244668 100644 --- a/doc/source/config.rst +++ b/doc/source/config.rst | |||
| @@ -34,14 +34,34 @@ but will write a warning in the log. | |||
| 34 | The rules are evaluated in the order that they are written, the **first** one | 34 | The rules are evaluated in the order that they are written, the **first** one |
| 35 | to match will terminate the evaluation (except for rules in simulation mode). | 35 | to match will terminate the evaluation (except for rules in simulation mode). |
| 36 | 36 | ||
| 37 | |||
| 38 | Miscellaneous | ||
| 39 | ------------- | ||
| 40 | |||
| 41 | global | ||
| 42 | ^^^^^^ | ||
| 43 | |||
| 44 | This configuration variable contains parameters that are used by multiple features: | ||
| 45 | |||
| 46 | - ``secret_key``: A secret key used by various cryptographic features, | ||
| 47 | like `cookies protection <features.html#session-cookie-stealing-via-xss>`__ or `unserialize protection <features.html#unserialize-related-magic>`__, | ||
| 48 | please ensure the length and complexity is sufficient. | ||
| 49 | You can generate it with functions such as: ``head -c 256 /dev/urandom | tr -dc 'a-zA-Z0-9'``. | ||
| 50 | |||
| 51 | :: | ||
| 52 | |||
| 53 | sp.global.secret_key("44239bd400aa82e125337c9d4eb8315767411ccd"); | ||
| 54 | |||
| 55 | - ``cookie_env_var``: A environment variable used as part of cookies encryption. | ||
| 56 | See the :ref:`relevant documentation <env-var-config>`. | ||
| 57 | |||
| 37 | Bugclass-killer features | 58 | Bugclass-killer features |
| 38 | ------------------------ | 59 | ------------------------ |
| 39 | 60 | ||
| 40 | global_strict | 61 | global_strict |
| 41 | ^^^^^^^^^^^^^ | 62 | ^^^^^^^^^^^^^ |
| 42 | `default: disabled` | ||
| 43 | 63 | ||
| 44 | ``global_strict`` will enable the `strict <https://secure.php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.strict>`_ mode globally, | 64 | :ref:`global_strict <global-strict-feature>`, disabled by default, will enable the `strict <https://secure.php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.strict>`_ mode globally, |
| 45 | forcing PHP to throw a `TypeError <https://secure.php.net/manual/en/class.typeerror.php>`_ | 65 | forcing PHP to throw a `TypeError <https://secure.php.net/manual/en/class.typeerror.php>`_ |
| 46 | exception if an argument type being passed to a function does not match its corresponding declared parameter type. | 66 | exception if an argument type being passed to a function does not match its corresponding declared parameter type. |
| 47 | 67 | ||
| @@ -54,12 +74,13 @@ It can either be ``enabled`` or ``disabled``. | |||
| 54 | 74 | ||
| 55 | harden_random | 75 | harden_random |
| 56 | ^^^^^^^^^^^^^ | 76 | ^^^^^^^^^^^^^ |
| 57 | * `default: enabled` | ||
| 58 | * `more <features.html#weak-prng-via-rand-mt-rand>`__ | ||
| 59 | 77 | ||
| 60 | ``harden_random`` will silently replace the insecure `rand <https://secure.php.net/manual/en/function.rand.php>`_ | 78 | :ref:`harden_random <harden-rand-feature>`, enabled by default, will silently |
| 61 | and `mt_rand <https://secure.php.net/manual/en/function.mt-rand.php>`_ functions with | 79 | replace the insecure `rand |
| 62 | the secure PRNG `random_int <https://secure.php.net/manual/en/function.random-int.php>`_. | 80 | <https://secure.php.net/manual/en/function.rand.php>`_ and `mt_rand |
| 81 | <https://secure.php.net/manual/en/function.mt-rand.php>`_ functions with the | ||
| 82 | secure PRNG `random_int | ||
| 83 | <https://secure.php.net/manual/en/function.random-int.php>`_. | ||
| 63 | 84 | ||
| 64 | It can either be ``enabled`` or ``disabled``. | 85 | It can either be ``enabled`` or ``disabled``. |
| 65 | 86 | ||
| @@ -70,27 +91,12 @@ It can either be ``enabled`` or ``disabled``. | |||
| 70 | 91 | ||
| 71 | .. _config_global: | 92 | .. _config_global: |
| 72 | 93 | ||
| 73 | global | ||
| 74 | ^^^^^^ | ||
| 75 | |||
| 76 | This configuration variable contains parameters that are used by multiple functions: | ||
| 77 | |||
| 78 | - ``secret_key``: A secret key used by various cryptographic features, | ||
| 79 | like `cookies protection <features.html#session-cookie-stealing-via-xss>`__ or `unserialize protection <features.html#unserialize-related-magic>`__, | ||
| 80 | please ensure the length and complexity is sufficient. | ||
| 81 | You can generate it with functions such as: ``head -c 256 /dev/urandom | tr -dc 'a-zA-Z0-9'``. | ||
| 82 | |||
| 83 | :: | ||
| 84 | |||
| 85 | sp.global.secret_key("44239bd400aa82e125337c9d4eb8315767411ccd"); | ||
| 86 | |||
| 87 | unserialize_hmac | 94 | unserialize_hmac |
| 88 | ^^^^^^^^^^^^^^^^ | 95 | ^^^^^^^^^^^^^^^^ |
| 89 | * `default: disabled` | ||
| 90 | * `more <features.html#unserialize-related-magic>`__ | ||
| 91 | 96 | ||
| 92 | ``unserialize_hmac`` will add an integrity check to ``unserialize`` calls, preventing | 97 | :ref:`unserialize_hmac <unserialize-feature>`, disabled by default, will add an |
| 93 | abritrary code execution in their context. | 98 | integrity check to ``unserialize`` calls, preventing arbitrary code execution |
| 99 | in their context. | ||
| 94 | 100 | ||
| 95 | It can either be ``enabled`` or ``disabled`` and can be used in ``simulation`` mode. | 101 | It can either be ``enabled`` or ``disabled`` and can be used in ``simulation`` mode. |
| 96 | 102 | ||
| @@ -102,11 +108,11 @@ It can either be ``enabled`` or ``disabled`` and can be used in ``simulation`` m | |||
| 102 | 108 | ||
| 103 | auto_cookie_secure | 109 | auto_cookie_secure |
| 104 | ^^^^^^^^^^^^^^^^^^ | 110 | ^^^^^^^^^^^^^^^^^^ |
| 105 | * `default: disabled` | ||
| 106 | * `more <features.html#session-cookie-stealing-via-xss>`__ | ||
| 107 | 111 | ||
| 108 | ``auto_cookie_secure`` will automatically mark cookies as `secure <https://en.wikipedia.org/wiki/HTTP_cookie#Secure_cookie>`_ | 112 | :ref:`auto_cookie_secure <auto-cookie-secure-feature>`, disabled by default, |
| 109 | when the web page is requested over HTTPS. | 113 | will automatically mark cookies as `secure |
| 114 | <https://en.wikipedia.org/wiki/HTTP_cookie#Secure_cookie>`_ when the web page | ||
| 115 | is requested over HTTPS. | ||
| 110 | 116 | ||
| 111 | It can either be ``enabled`` or ``disabled``. | 117 | It can either be ``enabled`` or ``disabled``. |
| 112 | 118 | ||
| @@ -117,11 +123,12 @@ It can either be ``enabled`` or ``disabled``. | |||
| 117 | 123 | ||
| 118 | cookie_samesite | 124 | cookie_samesite |
| 119 | ^^^^^^^^^^^^^^^^ | 125 | ^^^^^^^^^^^^^^^^ |
| 120 | * `default: disabled` | ||
| 121 | 126 | ||
| 122 | ``samesite`` will add the `samesite <https://tools.ietf.org/html/draft-west-first-party-cookies-07>`_ | 127 | :ref:`samesite <samesite-feature>`, disabled by default, will add the `samesite |
| 123 | attribute to cookies. It `prevents CSRF <https://www.owasp.org/index.php/SameSite>`_ | 128 | <https://tools.ietf.org/html/draft-west-first-party-cookies-07>`_ attribute to |
| 124 | but is not implemented by `all web browsers <https://caniuse.com/#search=samesite>`_ yet. | 129 | cookies. It `prevents CSRF <https://www.owasp.org/index.php/SameSite>`_ but is |
| 130 | not implemented by `all web browsers <https://caniuse.com/#search=samesite>`_ | ||
| 131 | yet. | ||
| 125 | 132 | ||
| 126 | It can either be set to ``strict`` or ``lax``: | 133 | It can either be set to ``strict`` or ``lax``: |
| 127 | 134 | ||
| @@ -139,9 +146,6 @@ It can either be set to ``strict`` or ``lax``: | |||
| 139 | 146 | ||
| 140 | cookie_encryption | 147 | cookie_encryption |
| 141 | ^^^^^^^^^^^^^^^^^ | 148 | ^^^^^^^^^^^^^^^^^ |
| 142 | |||
| 143 | * `default: disabled` | ||
| 144 | * `more <features.html#session-cookie-stealing-via-xss>`__ | ||
| 145 | 149 | ||
| 146 | .. warning:: | 150 | .. warning:: |
| 147 | 151 | ||
| @@ -151,7 +155,7 @@ cookie_encryption | |||
| 151 | `trivially bruteforcing <https://www.idontplaydarts.com/2011/11/decrypting-suhosin-sessions-and-cookies/>`_ | 155 | `trivially bruteforcing <https://www.idontplaydarts.com/2011/11/decrypting-suhosin-sessions-and-cookies/>`_ |
| 152 | or re-using session cookies. | 156 | or re-using session cookies. |
| 153 | 157 | ||
| 154 | ``cookie_secure`` will activate transparent encryption of specific cookies. | 158 | :ref:`cookie_secure <cookie-encryption-feature>`, disabled by default, will activate transparent encryption of specific cookies. |
| 155 | 159 | ||
| 156 | It can either be ``enabled`` or ``disabled`` and can be used in ``simulation`` mode. | 160 | It can either be ``enabled`` or ``disabled`` and can be used in ``simulation`` mode. |
| 157 | 161 | ||
| @@ -174,6 +178,8 @@ it to your php process. | |||
| 174 | We think that this use case is too exotic to be worth implementing as a | 178 | We think that this use case is too exotic to be worth implementing as a |
| 175 | proper configuration directive. | 179 | proper configuration directive. |
| 176 | 180 | ||
| 181 | .. _env-var-config: | ||
| 182 | |||
| 177 | Choosing the proper environment variable | 183 | Choosing the proper environment variable |
| 178 | """""""""""""""""""""""""""""""""""""""" | 184 | """""""""""""""""""""""""""""""""""""""" |
| 179 | 185 | ||
| @@ -197,9 +203,9 @@ or ``X-Real-IP`` if you're behind a reverse proxy. | |||
| 197 | 203 | ||
| 198 | readonly_exec | 204 | readonly_exec |
| 199 | ^^^^^^^^^^^^^ | 205 | ^^^^^^^^^^^^^ |
| 200 | * `default: disabled` | ||
| 201 | 206 | ||
| 202 | ``readonly_exec`` will prevent the execution of writable PHP files. | 207 | :ref:`readonly_exec <readonly-exec-feature>`, disabled by default, will prevent |
| 208 | the execution of writeable PHP files. | ||
| 203 | 209 | ||
| 204 | It can either be ``enabled`` or ``disabled`` and can be used in ``simulation`` mode. | 210 | It can either be ``enabled`` or ``disabled`` and can be used in ``simulation`` mode. |
| 205 | 211 | ||
| @@ -209,11 +215,10 @@ It can either be ``enabled`` or ``disabled`` and can be used in ``simulation`` m | |||
| 209 | 215 | ||
| 210 | upload_validation | 216 | upload_validation |
| 211 | ^^^^^^^^^^^^^^^^^ | 217 | ^^^^^^^^^^^^^^^^^ |
| 212 | * `default: disabled` | ||
| 213 | * `more <features.html#remote-code-execution-via-file-upload>`__ | ||
| 214 | 218 | ||
| 215 | ``upload_validation`` will call a given script upon a file upload, with the path | 219 | :ref:`upload_validation <fileupload-feature>`, disabled by default, will call a |
| 216 | to the file being uploaded as argument and various information about it in the environment: | 220 | given script upon a file upload, with the path to the file being uploaded as |
| 221 | argument and various information about it in the environment: | ||
| 217 | 222 | ||
| 218 | * ``SP_FILENAME``: the name of the uploaded file | 223 | * ``SP_FILENAME``: the name of the uploaded file |
| 219 | * ``SP_FILESIZE``: the size of the file being uploaded | 224 | * ``SP_FILESIZE``: the size of the file being uploaded |
| @@ -236,10 +241,8 @@ It can either be ``enabled`` or ``disabled`` and can be used in ``simulation`` m | |||
| 236 | 241 | ||
| 237 | disable_xxe | 242 | disable_xxe |
| 238 | ^^^^^^^^^^^ | 243 | ^^^^^^^^^^^ |
| 239 | * `default: enabled` | ||
| 240 | * `more <features.html#xxe>`__ | ||
| 241 | 244 | ||
| 242 | ``disable_xxe`` will prevent XXE attacks by disabling the loading of external entities (``libxml_disable_entity_loader``) in the XML parser. | 245 | :ref:`disable_xxe <xxe-feature>`, enabled by default, will prevent XXE attacks by disabling the loading of external entities (``libxml_disable_entity_loader``) in the XML parser. |
| 243 | 246 | ||
| 244 | :: | 247 | :: |
| 245 | 248 | ||
| @@ -248,12 +251,10 @@ disable_xxe | |||
| 248 | 251 | ||
| 249 | Eval white and blacklist | 252 | Eval white and blacklist |
| 250 | ^^^^^^^^^^^^^^^^^^^^^^^^ | 253 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 251 | * `default: disabled` | ||
| 252 | * :ref:`more <eval-feature>` | ||
| 253 | 254 | ||
| 254 | ``eval_whitelist`` and ``eval_blacklist`` allow to respectively specify | 255 | :ref:`eval_whitelist and eval_blacklist <eval-feature>`, disabled by default, |
| 255 | functions allowed and forbidden from being called inside ``eval``. The | 256 | allow to respectively specify functions allowed and forbidden from being called |
| 256 | functions names are comma-separated. | 257 | inside ``eval``. The functions names are comma-separated. |
| 257 | 258 | ||
| 258 | :: | 259 | :: |
| 259 | 260 | ||
| @@ -366,7 +367,7 @@ It's currently not possible to: | |||
| 366 | - Hook every `language construct <https://secure.php.net/manual/en/reserved.keywords.php>`__, | 367 | - Hook every `language construct <https://secure.php.net/manual/en/reserved.keywords.php>`__, |
| 367 | because each of them requires a specific implementation. | 368 | because each of them requires a specific implementation. |
| 368 | - Hook on the return value of user-defined functions | 369 | - Hook on the return value of user-defined functions |
| 369 | - Use extra-convoluted rulesfor matching, like ``${$A}$$B->${'}[1]``, because if you're writing | 370 | - Use extra-convoluted rules for matching, like ``${$A}$$B->${'}[1]``, because if you're writing |
| 370 | things like this, odds are that you're doing something wrong anyway. | 371 | things like this, odds are that you're doing something wrong anyway. |
| 371 | 372 | ||
| 372 | 373 | ||
diff --git a/doc/source/features.rst b/doc/source/features.rst index 86b81fd..24c5074 100644 --- a/doc/source/features.rst +++ b/doc/source/features.rst | |||
| @@ -61,6 +61,8 @@ Examples of related vulnerabilities | |||
| 61 | - `CVE-2016-10033 <https://legalhackers.com/advisories/PHPMailer-Exploit-Remote-Code-Exec-CVE-2016-10033-Vuln.html>`_: remote code execution in PHPMailer | 61 | - `CVE-2016-10033 <https://legalhackers.com/advisories/PHPMailer-Exploit-Remote-Code-Exec-CVE-2016-10033-Vuln.html>`_: remote code execution in PHPMailer |
| 62 | - `CVE-2016-9920 <https://www.ripstech.com/blog/2016/roundcube-command-execution-via-email/>`_: Unauthenticated remote code execution in Roundcube | 62 | - `CVE-2016-9920 <https://www.ripstech.com/blog/2016/roundcube-command-execution-via-email/>`_: Unauthenticated remote code execution in Roundcube |
| 63 | 63 | ||
| 64 | .. _cookie-encryption-feature: | ||
| 65 | |||
| 64 | Session-cookie stealing via XSS | 66 | Session-cookie stealing via XSS |
| 65 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 67 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 66 | 68 | ||
| @@ -82,6 +84,9 @@ thus using curve25519, xsalsa20 and poly1305 for the encryption. We chose this | |||
| 82 | library because of its portability, simplicity and reduced size (a single `.h` and | 84 | library because of its portability, simplicity and reduced size (a single `.h` and |
| 83 | `.c` file.). | 85 | `.c` file.). |
| 84 | 86 | ||
| 87 | |||
| 88 | .. _fileupload-feature: | ||
| 89 | |||
| 85 | Remote code execution via file-upload | 90 | Remote code execution via file-upload |
| 86 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 91 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 87 | 92 | ||
| @@ -114,6 +119,8 @@ Examples of related vulnerabilities | |||
| 114 | - `EDB-19154 <https://www.rapid7.com/db/modules/exploit/multi/http/qdpm_upload_exec>`_: Authenticated remote code execution in qdPM | 119 | - `EDB-19154 <https://www.rapid7.com/db/modules/exploit/multi/http/qdpm_upload_exec>`_: Authenticated remote code execution in qdPM |
| 115 | 120 | ||
| 116 | 121 | ||
| 122 | .. _unserialize-feature: | ||
| 123 | |||
| 117 | Unserialize-related magic | 124 | Unserialize-related magic |
| 118 | ^^^^^^^^^^^^^^^^^^^^^^^^^ | 125 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 119 | 126 | ||
| @@ -191,11 +198,6 @@ It's worth noting that the PHP documentation contains the following warning: | |||
| 191 | 198 | ||
| 192 | This is of course addressed as well by the ``harden_rand`` feature. | 199 | This is of course addressed as well by the ``harden_rand`` feature. |
| 193 | 200 | ||
| 194 | .. warning:: | ||
| 195 | |||
| 196 | Activating this feature will raise an `Error <https://secure.php.net/manual/en/class.error.php>`_ | ||
| 197 | exception if ``min`` is superior to ``max``, while the default dehaviour is simply to swap them. | ||
| 198 | |||
| 199 | 201 | ||
| 200 | Examples of related vulnerabilities | 202 | Examples of related vulnerabilities |
| 201 | """"""""""""""""""""""""""""""""""" | 203 | """"""""""""""""""""""""""""""""""" |
| @@ -209,6 +211,8 @@ Examples of related vulnerabilities | |||
| 209 | - `CVE-2008-4102 <https://sektioneins.de/en/advisories/advisory-042008-joomla-weak-random-password-reset-token-vulnerability.html>`_: Unauthenticated accounts takeover in Joomla | 211 | - `CVE-2008-4102 <https://sektioneins.de/en/advisories/advisory-042008-joomla-weak-random-password-reset-token-vulnerability.html>`_: Unauthenticated accounts takeover in Joomla |
| 210 | - `CVE-2006-0632 <https://www.cvedetails.com/cve/CVE-2006-0632/>`_: Unauthenticated account takeover in phpBB | 212 | - `CVE-2006-0632 <https://www.cvedetails.com/cve/CVE-2006-0632/>`_: Unauthenticated account takeover in phpBB |
| 211 | 213 | ||
| 214 | .. _xxe-feature: | ||
| 215 | |||
| 212 | XXE | 216 | XXE |
| 213 | ^^^ | 217 | ^^^ |
| 214 | 218 | ||
| @@ -239,6 +243,8 @@ Examples of related vulnerabilities | |||
| 239 | - `CVE-2011-4107 <https://www.phpmyadmin.net/security/PMASA-2011-17/>`_: Authenticated local file disclosure in PHPMyAdmin | 243 | - `CVE-2011-4107 <https://www.phpmyadmin.net/security/PMASA-2011-17/>`_: Authenticated local file disclosure in PHPMyAdmin |
| 240 | 244 | ||
| 241 | 245 | ||
| 246 | .. _auto-cookie-secure-feature: | ||
| 247 | |||
| 242 | Cookie stealing via HTTP MITM | 248 | Cookie stealing via HTTP MITM |
| 243 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 249 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 244 | 250 | ||
| @@ -313,6 +319,8 @@ This feature is largely inspired from the | |||
| 313 | `autostrict <https://github.com/krakjoe/autostrict>`_ module from `krakjoe <http://krakjoe.ninja>`__. | 319 | `autostrict <https://github.com/krakjoe/autostrict>`_ module from `krakjoe <http://krakjoe.ninja>`__. |
| 314 | 320 | ||
| 315 | 321 | ||
| 322 | .. _readonly-exec-feature: | ||
| 323 | |||
| 316 | Preventing execution of writable PHP files | 324 | Preventing execution of writable PHP files |
| 317 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 325 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 318 | 326 | ||
| @@ -337,6 +345,7 @@ it's broadly (mis)used all around the web. | |||
| 337 | Snuffleupagus provides a white and blacklist mechanism, to explicitly allow | 345 | Snuffleupagus provides a white and blacklist mechanism, to explicitly allow |
| 338 | and forbid specific functions call from being issued inside ``eval``. | 346 | and forbid specific functions call from being issued inside ``eval``. |
| 339 | 347 | ||
| 348 | .. _samesite-feature: | ||
| 340 | 349 | ||
| 341 | Protection against cross site request forgery | 350 | Protection against cross site request forgery |
| 342 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 351 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
