summaryrefslogtreecommitdiff
path: root/src/tests/deny_writable/deny_writable_execution_simulation.phpt
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/deny_writable/deny_writable_execution_simulation.phpt')
-rw-r--r--src/tests/deny_writable/deny_writable_execution_simulation.phpt50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/tests/deny_writable/deny_writable_execution_simulation.phpt b/src/tests/deny_writable/deny_writable_execution_simulation.phpt
new file mode 100644
index 0000000..7fc0c63
--- /dev/null
+++ b/src/tests/deny_writable/deny_writable_execution_simulation.phpt
@@ -0,0 +1,50 @@
1--TEST--
2Readonly execution attempt (simulation mode)
3--SKIPIF--
4<?php
5if (!extension_loaded("snuffleupagus")) print "skip";
6
7// root has write privileges on any file
8if (TRUE == function_exists("posix_getuid")) {
9 if (0 == posix_getuid()) {
10 print "skip";
11 }
12} elseif (TRUE == function_exists("shell_exec")) {
13 if ("root" == trim(shell_exec("whoami"))) {
14 print "skip";
15 }
16}
17 ?>
18--INI--
19sp.configuration_file={PWD}/config/config_disable_writable_simulation.ini
20--FILE--
21<?php
22$dir = __DIR__;
23
24// just in case
25@unlink("$dir/non_writable_file.txt");
26@unlink("$dir/writable_file.txt");
27
28file_put_contents("$dir/writable_file.txt", '<?php echo "Code execution within a writable file.\n";');
29file_put_contents("$dir/non_writable_file.txt", '<?php echo "Code execution within a non-writable file.\n";');
30chmod("$dir/writable_file.txt", 0777);
31chmod("$dir/non_writable_file.txt", 0400);
32include "$dir/writable_file.txt";
33include "$dir/non_writable_file.txt";
34?>
35--CLEAN--
36<?php
37$dir = __DIR__;
38chmod("$dir/non_writable_file.txt", 0777);
39chmod("$dir/writable_file.txt", 0777);
40unlink("$dir/non_writable_file.txt");
41unlink("$dir/writable_file.txt");
42?>
43--EXPECTF--
44Warning: [snuffleupagus][readonly_exec] Attempted execution of a writable file (%a/deny_writable_execution_simulation.php). in %a/deny_writable_execution_simulation.php on line 2
45
46Warning: [snuffleupagus][readonly_exec] Attempted execution of a writable file (%a/writable_file.txt). in %a/deny_writable_execution_simulation.php on line 12
47
48Warning: [snuffleupagus][readonly_exec] Attempted execution of a writable file (%a/writable_file.txt). in %a/writable_file.txt on line 1
49Code execution within a writable file.
50Code execution within a non-writable file.