77家的会客2010

动网ASP上传文件漏洞原理
Weather:有点闷,在屋子热,忘开空调了...

网上有一篇专门针对动网论坛的文章,太长了,并且在不懂计算机原理的朋友看来,实在是太费劲了.其实这个漏洞并不复杂,利用起来也没什么高深的知识,但用起来比较麻烦,所以流传不广。我们看一下动网上传文件中的一部分 

 '===========无组件上传(upload_0)====================
sub upload_0()
set upload=new UpFile_Class ''建立上传对象
upload.GetDate (int(Forum_Setting(56))*1024)   '取得上传数据,不限大小
iCount=0

if upload.err > 0 then
    select case upload.err
    case 1
    Response.Write "请先选择你要上传的文件 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
    case 2
    Response.Write "图片大小超过了限制 "&Forum_Setting(56)&"K [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
    end select
    exit sub
    else
formPath=upload.form("filepath")
''在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"

for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName)  ''生成一个文件对象
if file.filesize<100 then
    response.write "请先选择你要上传的图片 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
    response.end
end if

fileExt=lcase(file.FileExt)
if CheckFileExt(fileEXT)=false then
    response.write "文件格式不正确 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
    response.end
end if

randomize
ranNum=int(90000*rnd)+10000
filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
if file.FileSize>0 then         ''如果 FileSize > 0 说明有文件数据
  file.SaveToFile Server.mappath(filename)   ''保存文件
'  response.write file.FilePath&file.FileName&" ("&file.FileSize&") => "&formPath&File.FileName&" 成功!<br>"
response.write "<script>parent.document.forms[0].myface.value='"&FileName&"'</script>"
  iCount=iCount+1
end if
set file=nothing
next
set upload=nothing
session("upface")="done"
Htmend iCount&" 个文件上传结束!"

end if
end sub
很正常的一段ASP代码,但要命的在这一句

   filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt

在计算机中检测字符串的关键就是看是否碰到'\0'字符,所以我们可以为filename构造这样一个值uploadface\zwell.asp'\0'

这样我们的文件将会保存为uploadface\zweell.asp,既然这里可以上传一般的asp,那上传个ASP木马也是正常的了,如果服务器再配置不当,那这台服务器就算陷落了。

    幸好这个漏洞并不能直接提交,需要自己构造HTTP流,主要工具是Win Socket Express和UltraEdit,很简单,只是先把提交流截下来,然后改动一下,在里面加入'\0',再改动一下Content-Lengt就OK了

那么我们在程序设计的时候如何来避免呢?如何解决?我的想法是,对HTTP流进行判断,没有授权就不能上传,甚至不能使用上传脚本;至少对于个人网站应该是够了,因为个人网站不需要客户来提交上传文件,而像论坛类的就要另当别论了.

历史上的今天: [2008/09/26]厦门第六天
[2006/09/26]马屁的距离
[2005/09/26]忙?氓?盲?忙!~~

[动网ASP上传文件漏洞原理]的回复

Post a Comment~