这里以ASPUPLOAD组件上传为例
以下3个关键函数:
function killext(byval s1) '干掉非法文件后缀
dim allowext
allowext=".JPG,.JPEG,.GIF,.BMP,.PNG,.SWF,.RM,.MP3,.W***,.MID,.MIDI,.RA,.***I,.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
之类的“狗屎”文件!
| Windows Server2003 防木马权限设 | 04-06 | |
| PHP开发安全浅谈 | 01-23 | |
| 防范Serv-U漏洞 | 01-16 | |
| WEB专用服务器的安全设置的实战技 | 12-30 | |
| 重燃你的PHP安全之火 | 12-04 | |
| Web服务攻击痕迹检测 | 11-28 | |
| 脚本攻击防范策略完全篇 | 11-02 | |
| 脚本攻击防范策略完全篇 | 10-28 | |
| 拒绝肉鸡之上兴远程控制的发现与 | 10-26 | |
| 拒绝肉鸡之灰鸽子的发现与清除 | 10-24 | |
| 力克旁注 巧绑域名防范whois查询 | 10-21 | |
| 系统敏感端口真正的关闭大法 | 10-01 | |