浏览模式: 标准 | 列表分类:网站|ASP备忘

[转贴]终极防范上传漏洞!

终极防范上传漏洞!

其实无论是组件还是非组件上传,都有这个漏洞,以下代码请需要得朋友仔细阅读,只要读懂代码就能融会贯通。

这里以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

之类的“狗屎”文件!

相关关键字: 漏洞

------------------------------------------
作者:apollosun
落伍者

[转贴]终极防范SQL注入漏洞!

其实SQL注入漏洞并不可怕,知道原理 + 耐心仔细,就可以彻底防范!

下面给出4个函数,足够你抵挡一切SQL注入漏洞!读懂代码,你就能融会贯通。

注意要对所有的request对象进行过滤:包括 request.cookie, request.ServerVariables 等等容易被忽视的对象:

function killn(byval s1) '过滤数值型参数
if not isnumeric(s1) then
  killn=0
else
  if s1<0 or s1>2147483647 then
   killn=0
  else
   killn=clng(s1)
  end if
end if
end function

function killc(byval s1) 过滤货币型参数
if not isnumeric(s1) then
  killc=0
else
        killc=formatnumber(s1,2,-1,0,0)
end if
end function

function killw(byval s1) '过滤字符型参数
if len(s1)=0 then
  killw=""
else
  killw=trim(replace(s1,"'",""))
end if
end function

function killbad(byval s1) 过滤所有危险字符,包括跨站脚本
If len(s1) = 0 then
  killbad=""
else
  killbad = trim(replace(replace(replace(replace(replace(replace(replace(replace(s1,Chr(10), "<br>"), Chr(34), """), ">", "&gt;"), "<", "&lt;"), "&", "&"),chr(39),"&#39"),chr(32)," "),chr(13),""))
end if
end function

--------------------------------------------
apollosun
落伍者

动易2005 SP2最新漏洞补丁程序(临时方案)

漏洞描述:攻击者通过作者文集的批量操作功能,利用系统对字符串没有完全过滤的弱点,进行SQL注入。

漏洞级别:严重

解决方案:(临时)

一、用提供的补丁包中的两个文件替换系统中的文件。

二、开启后台管理验证码:Admin_ChkCode.asp文件中将EnableSiteManageCode设置为True,并修改SiteManageCode的默认值。

三、最好可以开启前台用户操作部分的审核功能,比如文集的审核等。

四、注意检查系统管理员中是否有非法的管理员帐号。

[file=uploads/200605/09_172543_2005sp2.rar]点击下载[/file]
Records:123«45678910111213