Skip to content

Commit d3bca55

Browse files
authored
Merge pull request #56 from BitScout/22-detect-shell-exec-via-backticks
feat(ban): Add rule to ban shell execution via backticks
2 parents 5416d33 + cc5e609 commit d3bca55

16 files changed

+20
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CHANGELOG
44
master
55
------
66

7-
* todo...
7+
* Added rule to ban shell execution via backticks
88

99
v1.0.0
1010
------

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ parameters:
6464
- system
6565
- var_dump
6666
67+
# enable detection of shell execution by backticks
68+
-
69+
type: Expr_ShellExec
70+
functions: null
71+
6772
# enable detection of `use Tests\Foo\Bar` in a non-test file
6873
use_from_tests: true
6974
```

extension.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ parameters:
4141
- system
4242
- var_dump
4343

44+
# enable detection of shell execution by backticks
45+
-
46+
type: Expr_ShellExec
47+
functions: null
48+
4449
# enable detection of `use Tests\Foo\Bar` in a non-test file
4550
use_from_tests: true
4651

snippets/backticks.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
`ls -lsa`;

snippets/echo.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<?php
22

33
echo 'test echo';
4-

snippets/eval.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<?php
22

33
eval(true);
4-

snippets/exec.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<?php
22

3-
exec('');
4-
3+
exec('ls -lsa');

snippets/exit.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<?php
22

33
exit;
4-

snippets/passthru.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<?php
22

33
passthru('');
4-

snippets/phpinfo.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<?php
22

33
phpinfo();
4-

snippets/print_r.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<?php
22

33
print_r('');
4-

snippets/proc_open.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?php
2+
23
$pipes = [];
34
proc_open('', [], $pipes);
4-

snippets/shell_exec.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<?php
22

33
shell_exec('');
4-

snippets/system.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<?php
22

33
system('');
4-

snippets/var_dump.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<?php
22

33
var_dump('');
4-

tests/Rules/BannedNodesRuleTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use PhpParser\Node\Expr\Exit_;
2121
use PhpParser\Node\Expr\FuncCall;
2222
use PhpParser\Node\Expr\Include_;
23+
use PhpParser\Node\Expr\ShellExec;
2324
use PhpParser\Node\Expr\Variable;
2425
use PhpParser\Node\Name;
2526
use PhpParser\Node\Scalar\LNumber;
@@ -52,6 +53,7 @@ protected function setUp(): void
5253
['type' => 'Expr_Eval'],
5354
['type' => 'Expr_Exit'],
5455
['type' => 'Expr_FuncCall', 'functions' => ['debug_backtrace', 'dump']],
56+
['type' => 'Expr_ShellExec'],
5557
]);
5658
$this->scope = $this->createMock(Scope::class);
5759
}
@@ -128,11 +130,12 @@ public function getUnhandledNodes(): \Generator
128130
}
129131

130132
/**
131-
* @return \Generator<array<Eval_|Exit_>>
133+
* @return \Generator<array<mixed>>
132134
*/
133135
public function getHandledNodes(): \Generator
134136
{
135137
yield [new Eval_($this->createMock(Expr::class))];
136138
yield [new Exit_()];
139+
yield [new ShellExec([''])];
137140
}
138141
}

0 commit comments

Comments
 (0)