summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/default.rules4
-rw-r--r--doc/source/config.rst2
-rw-r--r--doc/source/features.rst6
-rw-r--r--src/sp_crypt.c4
4 files changed, 14 insertions, 2 deletions
diff --git a/config/default.rules b/config/default.rules
index 3e82ae3..0fa4878 100644
--- a/config/default.rules
+++ b/config/default.rules
@@ -35,6 +35,10 @@ sp.xxe_protection.enable();
35# https://snuffleupagus.readthedocs.io/features.html#protection-against-cross-site-request-forgery 35# https://snuffleupagus.readthedocs.io/features.html#protection-against-cross-site-request-forgery
36sp.cookie.name("PHPSESSID").samesite("lax"); 36sp.cookie.name("PHPSESSID").samesite("lax");
37 37
38# Note that an attacker with arbitrary PHP code execution
39# can bypass some virtual-patching, by (as)using PHP feature.
40# A clever example would be to declare a class with a __toString method.
41
38# Harden the `chmod` function (0777 (oct = 511, 0666 = 438) 42# Harden the `chmod` function (0777 (oct = 511, 0666 = 438)
39@condition PHP_VERSION_ID < 80000; 43@condition PHP_VERSION_ID < 80000;
40 sp.disable_function.function("chmod").param("mode").value("438").drop(); 44 sp.disable_function.function("chmod").param("mode").value("438").drop();
diff --git a/doc/source/config.rst b/doc/source/config.rst
index 2053c2f..a84bb60 100644
--- a/doc/source/config.rst
+++ b/doc/source/config.rst
@@ -152,7 +152,7 @@ least astonishment
152<https://en.wikipedia.org/wiki/Principle_of_least_astonishment>`__. But since 152<https://en.wikipedia.org/wiki/Principle_of_least_astonishment>`__. But since
153it's `possible to modify php's logging system via php 153it's `possible to modify php's logging system via php
154<https://www.php.net/manual/en/errorfunc.configuration.php>`__, it's 154<https://www.php.net/manual/en/errorfunc.configuration.php>`__, it's
155heavily recommended to use the ``syslog`` option instead. The ``file:` option 155heavily recommended to use the ``syslog`` option instead. The ``file:`` option
156might be useful if you're using Snuffleupagus to fuzz or audit a codebase. 156might be useful if you're using Snuffleupagus to fuzz or audit a codebase.
157 157
158log_max_len 158log_max_len
diff --git a/doc/source/features.rst b/doc/source/features.rst
index adb8779..517bbec 100644
--- a/doc/source/features.rst
+++ b/doc/source/features.rst
@@ -309,7 +309,11 @@ of dangerous functions, dropping them everywhere else:
309 :language: php 309 :language: php
310 310
311 311
312The intent is to make post-exploitation process (such as backdooring of legitimate code, or RAT usage) a lot harder for the attacker. 312The intent is to make post-exploitation process (such as backdooring of
313legitimate code, or RAT usage) a lot harder for the attacker.
314
315Note that an attacker able to run arbitrary PHP code can likely bypass some virtual-patching
316by (ab)using some PHP features.
313 317
314 318
315.. _global-strict-feature: 319.. _global-strict-feature:
diff --git a/src/sp_crypt.c b/src/sp_crypt.c
index 9d4e6bb..3b65616 100644
--- a/src/sp_crypt.c
+++ b/src/sp_crypt.c
@@ -32,6 +32,7 @@ void generate_key(unsigned char *key) {
32 } 32 }
33 33
34 PHP_SHA256Final((unsigned char *)key, &ctx); 34 PHP_SHA256Final((unsigned char *)key, &ctx);
35 ZEND_SECURE_ZERO(&ctx, sizeof(ctx));
35} 36}
36 37
37// This function return 0 upon success , non-zero otherwise 38// This function return 0 upon success , non-zero otherwise
@@ -120,6 +121,7 @@ int decrypt_zval(zval *pDest, bool simulation, zend_hash_key *hash_key) {
120 ret = ZEND_HASH_APPLY_KEEP; 121 ret = ZEND_HASH_APPLY_KEEP;
121 122
122out: 123out:
124 ZEND_SECURE_ZERO(key, sizeof(key));
123 zend_string_efree(debase64); 125 zend_string_efree(debase64);
124 efree(decrypted); 126 efree(decrypted);
125 efree(backup); 127 efree(backup);
@@ -169,6 +171,8 @@ zend_string *encrypt_zval(zend_string *data) {
169 z = php_base64_encode(encrypted_data, emsg_and_nonce_len); 171 z = php_base64_encode(encrypted_data, emsg_and_nonce_len);
170 } 172 }
171 173
174 ZEND_SECURE_ZERO(key, sizeof(key));
175 ZEND_SECURE_ZERO(nonce, sizeof(nonce));
172 efree(data_to_encrypt); 176 efree(data_to_encrypt);
173 efree(encrypted_data); 177 efree(encrypted_data);
174 178