summaryrefslogtreecommitdiff
path: root/scripts/generate_rules.php
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/generate_rules.php')
-rw-r--r--scripts/generate_rules.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/scripts/generate_rules.php b/scripts/generate_rules.php
new file mode 100644
index 0000000..e286ef1
--- /dev/null
+++ b/scripts/generate_rules.php
@@ -0,0 +1,43 @@
1<?php
2
3if ($argc != 2) {
4 echo 'Please provide a folder as argument.';
5 die();
6}
7
8$functions_blacklist = ['shell_exec', 'exec', 'passthru', 'php_uname', 'popen',
9 'posix_kill', 'posix_mkfifo', 'posix_setpgid', 'posix_setsid', 'posix_setuid',
10 'posix_setgid', 'posix_uname', 'proc_close', 'proc_nice', 'proc_open',
11 'proc_terminate', 'proc_open', 'proc_get_status', 'dl', 'pnctl_exec',
12 'pnctl_fork', 'assert', 'system'];
13
14$extensions = ['php', 'php7', 'php5'];
15
16$path = realpath($argv[1]);
17
18$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
19foreach($objects as $name => $object){
20 if (FALSE === in_array (pathinfo($name, PATHINFO_EXTENSION), $extensions, true)) {
21 continue;
22 }
23
24 $hash = '';
25 $file_content = file_get_contents($name);
26
27 foreach(token_get_all($file_content) as $token) {
28 if ($token[0] != 319) {
29 continue;
30 }
31
32 if (in_array($token[1], $functions_blacklist, true)) {
33 if ('' === $hash) {
34 $hash = hash('sha256', $file_content);
35 }
36 echo 'sp.disable_function.function("' . $token[1] . '").filename("' . $name . '").hash("' . $hash . '").allow();' . "\n";
37 }
38 }
39}
40foreach($functions_blacklist as $fun) {
41 echo 'sp.disable_function.function("' . $fun . '").drop();' . "\n";
42
43}