summaryrefslogtreecommitdiff
path: root/config/default_php8.rules
diff options
context:
space:
mode:
authorjvoisin2021-04-26 21:19:59 +0200
committerjvoisin2021-04-26 21:20:21 +0200
commit0aaa9e51bbf102c37a9f545309c07650b6ee527b (patch)
tree18e9e799062cdb805d6f07c3169587d65dfa7cfa /config/default_php8.rules
parent654552c14ba8c98a244f82f9b8f1225a68526efb (diff)
Add a configuration file for php8
Diffstat (limited to '')
-rw-r--r--config/default_php8.rules146
1 files changed, 146 insertions, 0 deletions
diff --git a/config/default_php8.rules b/config/default_php8.rules
new file mode 100644
index 0000000..5517eb7
--- /dev/null
+++ b/config/default_php8.rules
@@ -0,0 +1,146 @@
1# This is the default configuration file for Snuffleupagus (https://snuffleupagus.rtfd.io),
2# for php8.
3# It contains "reasonable" defaults that won't break your websites,
4# and a lot of commented directives that you can enable if you want to
5# have a better protection.
6
7# Harden the PRNG
8sp.harden_random.enable();
9
10# Disabled XXE
11sp.disable_xxe.enable();
12
13# Global configuration variables
14# sp.global.secret_key("YOU _DO_ NEED TO CHANGE THIS WITH SOME RANDOM CHARACTERS.");
15
16# Globally activate strict mode
17# https://secure.php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.strict
18# sp.global_strict.enable();
19
20# Prevent unserialize-related exploits
21# sp.unserialize_hmac.enable();
22
23# Only allow execution of read-only files. This is a low-hanging fruit that you should enable.
24# sp.readonly_exec.enable();
25
26# Php has a lot of wrappers, most of them aren't usually useful, you should
27# only enable the ones you're using.
28# sp.wrappers_whitelist.list("file,php,phar");
29
30# Prevent sloppy comparisons.
31# sp.sloppy_comparison.enable();
32
33# use SameSite on session cookie
34# https://snuffleupagus.readthedocs.io/features.html#protection-against-cross-site-request-forgery
35sp.cookie.name("PHPSESSID").samesite("lax");
36
37# Harden the `chmod` function
38sp.disable_function.function("chmod").param("mode").value_r("^[0-9]{2}[67]$").drop();
39
40# Prevent various `mail`-related vulnerabilities
41sp.disable_function.function("mail").param("additional_parameters").value_r("\\-").drop();
42
43# Since it's now burned, me might as well mitigate it publicly
44sp.disable_function.function("putenv").param("setting").value_r("LD_").drop()
45
46# This one was burned in Nov 2019 - https://gist.github.com/LoadLow/90b60bd5535d6c3927bb24d5f9955b80
47sp.disable_function.function("putenv").param("setting").value_r("GCONV_").drop()
48
49# Since people are stupid enough to use `extract` on things like $_GET or $_POST, we might as well mitigate this vector
50sp.disable_function.function("extract").param("var_array").value_r("^_").drop()
51sp.disable_function.function("extract").param("extract_type").value("0").drop()
52
53# This is also burned:
54# ini_set('open_basedir','..');chdir('..');…;chdir('..');ini_set('open_basedir','/');echo(file_get_contents('/etc/passwd'));
55# Since we have no way of matching on two parameters at the same time, we're
56# blocking calls to open_basedir altogether: nobody is using it via ini_set anyway.
57# Moreover, there are non-public bypasses that are also using this vector ;)
58sp.disable_function.function("ini_set").param("option").value_r("open_basedir").drop()
59
60##Prevent various `include`-related vulnerabilities
61sp.disable_function.function("require_once").value_r("\.(inc|phtml|php)$").allow();
62sp.disable_function.function("include_once").value_r("\.(inc|phtml|php)$").allow();
63sp.disable_function.function("require").value_r("\.(inc|phtml|php)$").allow();
64sp.disable_function.function("include").value_r("\.(inc|phtml|php)$").allow();
65sp.disable_function.function("require_once").drop()
66sp.disable_function.function("include_once").drop()
67sp.disable_function.function("require").drop()
68sp.disable_function.function("include").drop()
69
70# Prevent `system`-related injections
71sp.disable_function.function("system").param("command").value_r("[$|;&`\\n\\(\\)\\\\]").drop();
72sp.disable_function.function("shell_exec").param("command").value_r("[$|;&`\\n\\(\\)\\\\]").drop();
73sp.disable_function.function("exec").param("command").value_r("[$|;&`\\n\\(\\)\\\\]").drop();
74sp.disable_function.function("proc_open").param("command").value_r("[$|;&`\\n\\(\\)\\\\]").drop();
75
76# Prevent runtime modification of interesting things
77sp.disable_function.function("ini_set").param("option").value("assert.active").drop();
78sp.disable_function.function("ini_set").param("option").value("zend.assertions").drop();
79sp.disable_function.function("ini_set").param("option").value("memory_limit").drop();
80sp.disable_function.function("ini_set").param("option").value("include_path").drop();
81sp.disable_function.function("ini_set").param("option").value("open_basedir").drop();
82
83# Detect some backdoors via environnement recon
84sp.disable_function.function("ini_get").param("varname").value("allow_url_fopen").drop();
85sp.disable_function.function("ini_get").param("varname").value("open_basedir").drop();
86sp.disable_function.function("ini_get").param("varname").value_r("suhosin").drop();
87sp.disable_function.function("function_exists").param("function").value("eval").drop();
88sp.disable_function.function("function_exists").param("function").value("exec").drop();
89sp.disable_function.function("function_exists").param("function").value("system").drop();
90sp.disable_function.function("function_exists").param("function").value("shell_exec").drop();
91sp.disable_function.function("function_exists").param("function").value("proc_open").drop();
92sp.disable_function.function("function_exists").param("function").value("passthru").drop();
93sp.disable_function.function("is_callable").param("var").value("eval").drop();
94sp.disable_function.function("is_callable").param("var").value("exec").drop();
95sp.disable_function.function("is_callable").param("var").value("system").drop();
96sp.disable_function.function("is_callable").param("var").value("shell_exec").drop();
97sp.disable_function.function("is_callable").param("var").value("proc_open").drop();
98sp.disable_function.function("is_callable").param("var").value("passthru").drop();
99
100# Commenting sqli related stuff to improve performance.
101# TODO figure out why these functions can't be hooked at startup
102# Ghetto sqli hardening
103# sp.disable_function.function("mysql_query").param("query").value_r("/\\*").drop();
104# sp.disable_function.function("mysql_query").param("query").value_r("--").drop();
105# sp.disable_function.function("mysql_query").param("query").value_r("#").drop();
106# sp.disable_function.function("mysql_query").param("query").value_r(";.*;").drop();
107# sp.disable_function.function("mysql_query").param("query").value_r("benchmark").drop();
108# sp.disable_function.function("mysql_query").param("query").value_r("sleep").drop();
109# sp.disable_function.function("mysql_query").param("query").value_r("information_schema").drop();
110
111# sp.disable_function.function("mysqli_query").param("query").value_r("/\\*").drop();
112# sp.disable_function.function("mysqli_query").param("query").value_r("--").drop();
113# sp.disable_function.function("mysqli_query").param("query").value_r("#").drop();
114# sp.disable_function.function("mysqli_query").param("query").value_r(";.*;").drop();
115# sp.disable_function.function("mysqli_query").param("query").value_r("benchmark").drop();
116# sp.disable_function.function("mysqli_query").param("query").value_r("sleep").drop();
117# sp.disable_function.function("mysqli_query").param("query").value_r("information_schema").drop();
118
119# sp.disable_function.function("PDO::query").param("query").value_r("/\\*").drop();
120# sp.disable_function.function("PDO::query").param("query").value_r("--").drop();
121# sp.disable_function.function("PDO::query").param("query").value_r("#").drop();
122# sp.disable_function.function("PDO::query").param("query").value_r(";.*;").drop();
123# sp.disable_function.function("PDO::query").param("query").value_r("benchmark\\s*\\(").drop();
124# sp.disable_function.function("PDO::query").param("query").value_r("sleep\\s*\\(").drop();
125# sp.disable_function.function("PDO::query").param("query").value_r("information_schema").drop();
126
127# Ghetto sqli detection
128# sp.disable_function.function("mysql_query").ret("FALSE").drop();
129# sp.disable_function.function("mysqli_query").ret("FALSE").drop();
130# sp.disable_function.function("PDO::query").ret("FALSE").drop();
131
132# Ensure that certificates are properly verified
133sp.disable_function.function("curl_setopt").param("value").value("1").allow();
134sp.disable_function.function("curl_setopt").param("value").value("2").allow();
135# `81` is SSL_VERIFYHOST and `64` SSL_VERIFYPEER
136sp.disable_function.function("curl_setopt").param("option").value("64").drop().alias("Please don't turn CURLOPT_SSL_VERIFYCLIENT off.");
137sp.disable_function.function("curl_setopt").param("option").value("81").drop().alias("Please don't turn CURLOPT_SSL_VERIFYHOST off.");
138
139#File upload
140sp.disable_function.function("move_uploaded_file").param("destination").value_r("\\.ph").drop();
141sp.disable_function.function("move_uploaded_file").param("destination").value_r("\\.ht").drop();
142
143# Logging lockdown
144sp.disable_function.function("ini_set").param("option").value_r("error_log").drop()
145sp.disable_function.function("ini_set").param("option").value_r("error_reporting").drop()
146sp.disable_function.function("ini_set").param("option").value_r("display_errors").drop()