If Instr(request("username"),"=")>0 or
Instr(request("username"),"%")>0 or
Instr(request("username"),chr(32))>0 or
Instr(request("username"),"?")>0 or
Instr(request("username"),"&")>0 or
Instr(request("username"),";")>0 or
Instr(request("username"),",")>0 or
Instr(request("username"),"'")>0 or
Instr(request("username"),"?")>0 or
Instr(request("username"),chr(34))>0 or
Instr(request("username"),chr(9))>0 or
Instr(request("username"),"?K")>0 or
Instr(request("username"),"$")>0 or
Instr(request("username"),">")>0 or
Instr(request("username"),"<")>0 or
Instr(request("username"),"""")>0 then
response.write "朋友,你的提交用户名含有非法字符,请更改,谢谢合作 <a href='****:window.history.go(-1);'>返回</a>"
response.end
end if
for i= 0 to ubound(Bword)
if instr(FQYs,Bword(i))<>0 then
errc=true
end if
next
if errc then
response.write "<script language=""****"">"
response.write "parent.alert('很抱歉!您的操作违法了);"
response.write "history,back();"
response.write "</script>"
response.end
end if
SQL 注入式攻击可能引起的危害取决于该网站的软件环境和配置。当 Web 服务器以操作员(dbo)的身份访问数据库时,利用SQL注入式攻击就可能删除所有表格、创建新表格,等等。当服务器以超级用户 (sa) 的身份访问数据库时,利用SQL注入式攻击就可能控制整个 SQL 服务器;在某些配置下攻击者甚至可以自行创建用户帐号以完全操纵数据库所在的 Windows 服务器。
如:
http://127.0.0.1/forum/showuser.asp?id=999’;declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:\'--&aid=9
http://127.0.0.1/forum/showuser.asp?id=999’; declare @a sysname set @a='xp'+'_cm’+’dshell' exec @a 'dir c:\'--&aid=9
甚至可以执行像:net user fqy fqy /add 这样的指令.当然这就需要你当前的运行身份必须是Sa,或者你攻击的只是一台虚拟主机,我劝你还是就此打住.
fqys=request.servervariables("query_string")
dim nothis(18)
nothis(0)="net user"
nothis(1)="xp_cmdshell"
nothis(2)="/add"
nothis(3)="exec%20master.dbo.xp_cmdshell"
nothis(4)="net localgroup administrators"
nothis(5)="select"
nothis(6)="count"
nothis(7)="asc"
nothis(8)="char"
nothis(9)="mid"
nothis(10)="'"
nothis(11)=":"
nothis(12)=""""
nothis(13)="insert"
nothis(14)="delete"
nothis(15)="drop"
nothis(16)="truncate"
nothis(17)="from"
nothis(18)="%"
errc=false
for i= 0 to ubound(nothis)
if instr(FQYs,nothis(i))<>0 then
errc=true
end if
next
if errc then
response.write ""
response.end
end if
我要做点声明的是:以上的程序只是对GET方式提交的数据进行的过滤,千万不要盲目套用。
像其他一些来自 ASP request 对象 (Reques、Request.QueryString、Request.Form、Request.Cookies和 Request.ServerVariables) 的用户输入的攻击方法的方法,大致都集中在脚本期望的输入变量是数字变量 (ID) 上,当然我们不能只看数字变量,比如:
http://127.0.0.1/systembbs/showtopic.asp?tid=99&name=abc' and left(userpasswor d,1)='a
http://127.0.0.1/systembbs/addtopic.asp?tid=99&name=abc' and userpasswor d=’or’’=’
……addtopic.asp?action=add……
……addtopic.asp?action=delect……
Action1=trim(Request.QueryString())
if left(action1,7)<>"action=" then '限定querystring必须为 action=
error(err01)'错误处理
else
action=Request.querystring("action")'取得querystring的值
end if
select case action'对querystring进行处理
case "add"
.....
case "delete"
......
case else '如果querystring没有这个值则进行错误处理
error(err02)
end select