From cc5e609d49a413fd35bb6a1eebad40114715c58c Mon Sep 17 00:00:00 2001 From: Christian Kollross Date: Fri, 25 Feb 2022 11:08:06 +0100 Subject: [PATCH] feat(ban): Add rule to ban shell execution via backticks --- CHANGELOG.md | 2 +- README.md | 5 +++++ extension.neon | 5 +++++ snippets/backticks.php | 3 +++ snippets/echo.php | 1 - snippets/eval.php | 1 - snippets/exec.php | 3 +-- snippets/exit.php | 1 - snippets/passthru.php | 1 - snippets/phpinfo.php | 1 - snippets/print_r.php | 1 - snippets/proc_open.php | 2 +- snippets/shell_exec.php | 1 - snippets/system.php | 1 - snippets/var_dump.php | 1 - tests/Rules/BannedNodesRuleTest.php | 5 ++++- 16 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 snippets/backticks.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e5aecb..2aca616 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ CHANGELOG master ------ -* todo... +* Added rule to ban shell execution via backticks v1.0.0 ------ diff --git a/README.md b/README.md index 0664579..13060c4 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,11 @@ parameters: - system - var_dump + # enable detection of shell execution by backticks + - + type: Expr_ShellExec + functions: null + # enable detection of `use Tests\Foo\Bar` in a non-test file use_from_tests: true ``` diff --git a/extension.neon b/extension.neon index 00c5ecb..9bdad7b 100644 --- a/extension.neon +++ b/extension.neon @@ -41,6 +41,11 @@ parameters: - system - var_dump + # enable detection of shell execution by backticks + - + type: Expr_ShellExec + functions: null + # enable detection of `use Tests\Foo\Bar` in a non-test file use_from_tests: true diff --git a/snippets/backticks.php b/snippets/backticks.php new file mode 100644 index 0000000..50b7664 --- /dev/null +++ b/snippets/backticks.php @@ -0,0 +1,3 @@ + 'Expr_Eval'], ['type' => 'Expr_Exit'], ['type' => 'Expr_FuncCall', 'functions' => ['debug_backtrace', 'dump']], + ['type' => 'Expr_ShellExec'], ]); $this->scope = $this->createMock(Scope::class); } @@ -128,11 +130,12 @@ public function getUnhandledNodes(): \Generator } /** - * @return \Generator> + * @return \Generator> */ public function getHandledNodes(): \Generator { yield [new Eval_($this->createMock(Expr::class))]; yield [new Exit_()]; + yield [new ShellExec([''])]; } }