summaryrefslogtreecommitdiff
path: root/src/tests/deny_writable/dump_deny_writable_execution.phpt
diff options
context:
space:
mode:
authorjvoisin2019-01-14 19:29:25 +0000
committerGitHub2019-01-14 19:29:25 +0000
commite79f7e3bd992c7f0915ef9afe7afb6d79740527a (patch)
treef881c25694eb00da2331a9ab280ec1c24a5662ab /src/tests/deny_writable/dump_deny_writable_execution.phpt
parentc943db586ac46b686b49bdf61d8473e39dd93000 (diff)
Reorganize the testsuite
Splitting the testsuite in several components makes it easier to manage and comprehend. This was also needed some some tests aren't passing on Alpine Linux, but we still want to run as many of them as we can on this platform.
Diffstat (limited to 'src/tests/deny_writable/dump_deny_writable_execution.phpt')
-rw-r--r--src/tests/deny_writable/dump_deny_writable_execution.phpt67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/tests/deny_writable/dump_deny_writable_execution.phpt b/src/tests/deny_writable/dump_deny_writable_execution.phpt
new file mode 100644
index 0000000..c6dd6cd
--- /dev/null
+++ b/src/tests/deny_writable/dump_deny_writable_execution.phpt
@@ -0,0 +1,67 @@
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--POST--
19post_a=data_post_a_readonly&post_b=data_post_b_readonly
20--GET--
21get_a=data_get_a_readonly&get_b=data_get_b_readonly
22--COOKIE--
23cookie_a=data_cookie_a_readonly&cookie_b=data_cookie_b_readonly
24--INI--
25sp.configuration_file={PWD}/config/dump_deny_writable_execution.ini
26--FILE--
27<?php
28@mkdir("/tmp/dump_result/");
29foreach (glob("/tmp/dump_result/sp_dump.*") as $dump) {
30 @unlink($dump);
31}
32$dir = __DIR__;
33
34// just in case
35@unlink("$dir/non_writable_file.txt");
36@unlink("$dir/writable_file.txt");
37
38file_put_contents("$dir/writable_file.txt", '<?php echo "Code execution within a writable file.\n";');
39file_put_contents("$dir/non_writable_file.txt", '<?php echo "Code execution within a non-writable file.\n";');
40chmod("$dir/writable_file.txt", 0777);
41chmod("$dir/non_writable_file.txt", 0400);
42include "$dir/writable_file.txt";
43include "$dir/non_writable_file.txt";
44
45$filename = glob('/tmp/dump_result/sp_dump.*')[0];
46$res = file($filename);
47if ($res[2] != "GET:get_a='data_get_a_readonly' get_b='data_get_b_readonly' \n") {
48 echo "1\n";
49} elseif ($res[3] != "POST:post_a='data_post_a_readonly' post_b='data_post_b_readonly' \n") {
50 echo "2\n";
51} elseif ($res[4] != "COOKIE:cookie_a='data_cookie_a_readonly&cookie_b=data_cookie_b_readonly' \n") {
52 echo "3\n";
53} else {
54 echo "WIN\n";
55}
56?>
57--EXPECTF--
58%a
59WIN
60--CLEAN--
61<?php
62$dir = __DIR__;
63chmod("$dir/non_writable_file.txt", 0777);
64chmod("$dir/writable_file.txt", 0777);
65unlink("$dir/non_writable_file.txt");
66unlink("$dir/writable_file.txt");
67?>