其實無論是元件或非元件上傳,都有這個漏洞,以下程式碼請需要朋友仔細閱讀,只要讀懂程式碼就能融會貫通。
這裡以ASPUPLOAD元件上傳為例
以下3個關鍵函數:
function killext(byval s1) '幹掉非法文件後綴
dim allowext
allowext=.JPG,.JPEG,.GIF,.BMP,.PNG,.SWF,.RM,.MP3,.WAV,.MID,.MIDI,.RA,.
AVI,.MPG,.MPEG,.ASF,.ASX,.WMA,.MOV,.RAR,.ZIP,.EXE,.DOC,.XLS,.CHM,.HLP,.PDF
s1=ucase(s1)
if len(s1)=0 then
killext=
else
if not chk(allowext,s1,,) then
killext=.shit
else
killext=s1
end if
end if
end function
function chk(byval s1,byval s2,byval fuhao) '檢查字串包含
dim i,a
chk=false
a=split(s1,fuhao)
for i = 0 to ubound(a)
if trim(a(i))=trim(s2) then
chk=true
exit for
end if
next
end function
function gname(byval n1) '以日期自動產生目錄和檔名,參數1產生目錄,參數2產生檔名(無後綴)
dim t,r
t=now()
randomize(timer)
r=int((rnd+1-1)*9999)
select case n1
case 1
gname=year(t)&right(00&month(t),2)&right(00&day(t),2)
case 2
gname=right(00&hour(t),2)&right(00&minute(t),2)&right(00&second(t),2)&right(0000&r,4)
end select
end function
調用方法:
dim oup,ofile,ext,myfile
Set oup = Server.CreateObject(Persits.Upload)
oup.SetMaxSize 10000000, True
call oup.Save() '這裡是上傳到伺服器內存,並沒有實際檔案產生
set ofile = oup.files(1)
ext=killext(ofile.ext)
myfile=/ & ganme(1) & / & gname(2) & ext
call ofile.saveas(server.mappath(myfile))
附加說明:
駭客如果用nc 上傳非法文件,最終得到的文件只是如200511051234559103.shit之類的狗屎文件!