真正解决upfile_flash.asp漏洞

upfile_flash.asp 这个东西我一直在用,不过本身的漏洞实现太可怕了。刚刚才把这个漏洞彻底解决掉了。以在明小子3.5下试过没有问题了。如果谁发现还有问题请马上E-mail我。

<!--#include file="upload_wj.inc"-->
<%

'先作一个文件名检验函数。过虑掉所有有危险的东西。
Function chkfileExt(savefilename)
  feifaExt="html|htm|php|php2|php3|php4|php5|phtml|pwml|inc|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|com|dll|vbs|js|reg|cgi|htaccess|asis"
  fExt = Split(feifaExt, "|")
   
  For i = 0 To UBound(fExt)
   If instr(savefilename,fExt(i))>0 Then '检测是否存在非法字符。
    response.write("非法的文件格式!")
    Response.End
   End If
  Next
  
End Function


set upload=new upload_file
if upload.form("act")="uploadfile" then

 filepath=trim(upload.form("filepath"))
 filelx=trim(upload.form("filelx"))
 filepath=replace(filepath,chr(0),"")  

'注意这里。替换掉chr(0)。明小子里的程序是把木马名称放在这里的。如果你只检验扩展名是没有用的。程序会传一个变量就是diy.asp&chr(0) 这个chr(0)是什么我不太清楚好像是一个停止符号。ASCII码表中对应的是“NUT”。大家可以试一下 response.write "abc.asp"&chr(0)&"03i320923.jpg" 显示的结果就是“abc.asp” 明小子程序就是通过这种办法绕过去的。


 i=0
 for each formName in upload.File
  set file=upload.File(formName)
 
  fileExt=lcase(file.FileExt) '得到的文件扩展名不含有.
  
  if file.filesize>(1024*1024) then
   response.write "<span style=""font-family: 宋体; font-size: 9pt"">最大只能上传 1M 的文件! [ <a href=# onclick=history.go(-1)>重新上传</a> ]</span>"
   response.end
  end if
 
 
   randomize
   ranNum=int(90000*rnd)+10000
   filename=filepath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&left(ranNum,3)&"."&fileExt
 
   if file.FileSize>0 then
   
    call chkfileExt(FileName)

'这里我们检验的是整个保存地址。如果存在非法字符就报警并停止。
   
   file.SaveToFile Server.mappath(FileName)
   response.write "<script>"
   response.write "window.opener.document."&upload.form("FormName")&"."&upload.form("EditName")&".value='"&FileName&"';"
   response.write "window.alert(""文件上传成功!请不要修改生成的链接地址!"");"
   response.write "window.close();"
   response.write "</script>"
 
  end if
  
  set file=nothing
 next
 set upload=nothing
 
 
end if
%>