Skip to content

Commit

Permalink
test cases for testing edge cases, eval and cmd execution
Browse files Browse the repository at this point in the history
  • Loading branch information
bef committed Dec 14, 2021
1 parent a5dcbb8 commit c3fddfe
Show file tree
Hide file tree
Showing 18 changed files with 244 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sp.disable_function.function("shell_exec").pos("0").value("ls").drop();
sp.disable_function.function("exec").drop();
sp.disable_function.function("passthru").drop();
#sp.disable_function.function("system").drop();
sp.disable_function.function("proc_open").drop();
sp.disable_function.function("popen").drop();
sp.disable_function.function("phpinfo").drop();
12 changes: 12 additions & 0 deletions src/tests/disable_function/disabled_functions_exec.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Disable functions - exec
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
--FILE--
<?php
echo exec('ls -l');
?>
--EXPECTF--
Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'exec' in %a.php on line 2
12 changes: 12 additions & 0 deletions src/tests/disable_function/disabled_functions_passthru.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Disable functions - passthru
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
--FILE--
<?php
echo passthru('ls -l');
?>
--EXPECTF--
Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'passthru' in %a.php on line 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Disable functions - phpinfo via header_register_callback
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
--FILE--
<?php
header_register_callback('phpinfo');
?>
--EXPECTF--
Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'phpinfo' in Unknown on line 0
12 changes: 12 additions & 0 deletions src/tests/disable_function/disabled_functions_popen.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Disable functions - popen
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
--FILE--
<?php
echo popen('ls -l', 'r');
?>
--EXPECTF--
Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'popen' in %a.php on line 2
17 changes: 17 additions & 0 deletions src/tests/disable_function/disabled_functions_proc_open.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Disable functions - proc_open
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
--FILE--
<?php
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
echo proc_open('ls', $descriptorspec, $pipes);
?>
--EXPECTF--
Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'proc_open' in %a.php on line 7
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Disable functions - shell_exec via backtick operator
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
--FILE--
<?php
echo `ls`;
?>
--EXPECTF--
Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'shell_exec', %a matched a rule in %a.php on line 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Disable functions - shell_exec via backtick operator in context of a var name
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
--FILE--
<?php
echo ${`ls`};
?>
--EXPECTF--
Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'shell_exec', %a matched a rule in %a.php on line 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Disable functions - shell_exec via backtick operator in context of a var name in a string
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
--FILE--
<?php
echo "{${`ls`}}";
?>
--EXPECTF--
Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'shell_exec', %a matched a rule in %a.php on line 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Disable functions - shell_exec via closure
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
--FILE--
<?php
$x = Closure::fromCallable('shell_exec');
echo $x('ls');
?>
--EXPECTF--
Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'shell_exec', %a matched a rule in %a.php on line 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Disable functions - shell_exec via 1st class closure
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
<?php if (PHP_VERSION_ID < 80100) print "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
--FILE--
<?php
$x = shell_exec(...);
echo $x('ls');
?>
--EXPECTF--
Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'shell_exec', %a matched a rule in %a.php on line 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Disable functions - shell_exec via filter_input callback
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
--GET--
cmd=ls
--FILE--
<?php
echo filter_input(INPUT_GET, 'cmd', FILTER_CALLBACK, array('options' => 'shell_exec'));
?>
--EXPECTF--
Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'shell_exec', %a matched a rule in %a.php on line 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Disable functions - shell_exec via include(data://)
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
<?php if (PHP_VERSION_ID < 70400) print "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
allow_url_include=1
--FILE--
<?php
include('data://text/plain,'.urlencode('<?php shell_exec("ls");'));
?>
--EXPECTF--
Deprecated: Directive 'allow_url_include' is deprecated in Unknown on line 0

Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'shell_exec', %a matched a rule in data%a line 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Disable functions - shell_exec via include(php://filter)
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
<?php if (PHP_VERSION_ID < 70400) print "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
allow_url_include=1
--FILE--
<?php
include('php://filter//resource=data://text/plain,'.urlencode('<?php shell_exec("ls");'));
?>
--EXPECTF--
Deprecated: Directive 'allow_url_include' is deprecated in Unknown on line 0

Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'shell_exec', %a matched a rule in php%a line 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Disable functions - shell_exec via opcache.preload
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
<?php if (PHP_VERSION_ID < 70400) print "skip"; ?>
--EXTENSIONS--
opcache
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
allow_url_include=1
opcache.enable=1
opcache.enable_cli=1
opcache.preload=data://text/plain,%3C%3Fphp+shell_exec%28%22ls%22%29%3B
--FILE--
<?php
?>
--EXPECTF--
Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'shell_exec', %a matched a rule in data%a line 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Disable functions - shell_exec via register_shutdown_function
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
--FILE--
<?php
register_shutdown_function('shell_exec', 'ls');
?>
--EXPECTF--
Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'shell_exec', %a matched a rule in Unknown on line 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Disable functions - shell_exec via signal handler
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
<?php if (PHP_VERSION_ID < 70100) print "skip"; ?>
--EXTENSIONS--
pcntl
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
pcntl.async_signals=1
--FILE--
<?php
declare(ticks=1);
ini_set("pcntl.async_signals", "1");
pcntl_signal(SIGALRM, function($signo) { shell_exec("ls"); });
system("kill -14 " . getmypid());
sleep(5);
?>
--EXPECTF--
Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'shell_exec', %a matched a rule in %a.php on line 4
13 changes: 13 additions & 0 deletions src/tests/disable_function/disabled_functions_shell_exec_var.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Disable functions - shell_exec via var call
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/disabled_functions_extra.ini
--FILE--
<?php
$x = 'shell_exec';
echo $x('ls');
?>
--EXPECTF--
Fatal error: [snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'shell_exec', %a matched a rule in %a.php on line 3

0 comments on commit c3fddfe

Please sign in to comment.