哪位有ASP写的SQL注入测试用例?解决思路
哪位有ASP写的SQL注入测试用例?
想搭个SQL注入的测试环境,最好是ASP+MSSQL2000的页面文件,不需要太复杂,一个页面的也行。哪位有共享一下。
谢谢!
------解决方案--------------------
<% set rs=conn.execute("select * from t where name='" + request("name") + "' and pwd='" + request("pwd") + "'") %>
<input type="text" name="name" value="" />
输入'; delete from t;select '1 这样就攻击了 要不输入个'就能找到漏洞了.....
------解决方案--------------------
asp写的sql注入检测程序
闲着没事,写了段sql注入检测程序,虽然还有一些地方待完善,但基本能检测并清除被注入的危险代码,
sql2000,access2003经过了测试。
<" CODEPAGE="936"%>
<!--#include file="inc/conn.asp"-->
<%
''表检测程序
''==========================================================================================
Sub MonTB()
Set rs=conn.OpenSchema(20)
rs.MoveFirst
xz=""
For i=1 to rs.RecordCount
If rs("TABLE_TYPE")="TABLE" Then
If rs("TABLE_NAME")=Request.Form("tbname") Then
Session("jz")=i
End If
jz=Session("jz")
If jz="" Or IsNull(jz) Then
Else
If i=jz+1 Then
xz="selected"
End If
End If
Response.Write("<option value='"&rs("TABLE_NAME")&"' "&xz&">"&rs("TABLE_NAME")&"</option>")
xz=""
End If
rs.Movenext
Next
rs.Close
Set rs=Nothing
Session("tbnum")=i
End Sub
''============================================================================================
''sql注入检测程序
Sub MonitorSql(tb)
Dim m,lrs,i,lieNum,jcstr
Set lrs=server.CreateObject("adodb.recordset")
lrs.Open "SELECT * FROM "&tb,conn,2,2,1
m=0
If lrs.Bof And lrs.Eof Then
Else
Set lie= lrs.Fields
lieNum=lie.Count
Do While Not lrs.Eof
For i=0 To lieNum-1
If IsNull(lie(i).Value) Or lie(i).Value="" Then
Else
jcstr=Lcase(lie(i).Value)
If InStr(jcstr,".js") Or InStr(jcstr,"script") Or InStr(jcstr,"iframe") Then
If Instr(sqlstr,lrs(i).Name)Then
Else
m=m+1
sqlstr=sqlstr&"第<font color='red'>"&i&"</font>列字段:<font color='red'>"&lrs(i).Name&"</font> 被SQL注入</br>"
End If
End If
End If
Next
lrs.MoveNext()
Loop
End If
lrs.Close()
Set lrs=Nothing
Response.Write("<span class='STYLE3'>表<span class='STYLE1'>"&tb&"</span>共有<font color='red'>"&m&"</font>列被注入:</span><br><hr align='left' width='60%'>"&sqlstr)
End Sub
''==========================================================================================
''sql注入清除程序
Sub ReplaceSql(sc)
Set lrs=server.CreateObject("adodb.recordset")
lrs.Open "SELECT * FROM "&sc,conn,2,2,1
If lrs.Bof And lrs.Eof Then
Else
Set lie= lrs.Fields
lieNum=lie.Count
Do While Not lrs.Eof
For i=0 To lieNum-1
If IsNull(lie(i).Value) Or lie(i).Value="" Then
Else
delstr=Lcase(lie(i).Value)
If InStr(delstr,".js") Or InStr(delstr,"script") Or InStr(delstr,".htm") Then
thstr=Lcase(lie(i).Value)
thstr=Replace(thstr,".js","")
thstr=Replace(thstr,"script","")
thstr=Replace(thstr,"IFRAME","")
thstr=Replace(thstr,".htm","")
thstr=Replace(thstr,".asp","")
thstr=Replace(thstr,".php","")
thstr=Replace(thstr,"iframe","")
thstr=Replace(thstr,".aspx","")
lrs(lie(i).Name)=thstr
lrs.Update()
End If
End If
Next
lrs.MoveNext()
Loop
End If
lrs.Close()
Set lrs=Nothing
Response.Write("修补成功,仍有注入的残余,但不会有破坏性。")
End Sub
''=======================================================================
If Request.ServerVariables("REQUEST_METHOD")="POST" Then
Dim tbname
tbname=Request.Form("tbname")
If tbname="" Or IsNull(tbname) Then
Else
Call MonitorSql(tbname)
想搭个SQL注入的测试环境,最好是ASP+MSSQL2000的页面文件,不需要太复杂,一个页面的也行。哪位有共享一下。
谢谢!
------解决方案--------------------
<% set rs=conn.execute("select * from t where name='" + request("name") + "' and pwd='" + request("pwd") + "'") %>
<input type="text" name="name" value="" />
输入'; delete from t;select '1 这样就攻击了 要不输入个'就能找到漏洞了.....
------解决方案--------------------
asp写的sql注入检测程序
闲着没事,写了段sql注入检测程序,虽然还有一些地方待完善,但基本能检测并清除被注入的危险代码,
sql2000,access2003经过了测试。
<" CODEPAGE="936"%>
<!--#include file="inc/conn.asp"-->
<%
''表检测程序
''==========================================================================================
Sub MonTB()
Set rs=conn.OpenSchema(20)
rs.MoveFirst
xz=""
For i=1 to rs.RecordCount
If rs("TABLE_TYPE")="TABLE" Then
If rs("TABLE_NAME")=Request.Form("tbname") Then
Session("jz")=i
End If
jz=Session("jz")
If jz="" Or IsNull(jz) Then
Else
If i=jz+1 Then
xz="selected"
End If
End If
Response.Write("<option value='"&rs("TABLE_NAME")&"' "&xz&">"&rs("TABLE_NAME")&"</option>")
xz=""
End If
rs.Movenext
Next
rs.Close
Set rs=Nothing
Session("tbnum")=i
End Sub
''============================================================================================
''sql注入检测程序
Sub MonitorSql(tb)
Dim m,lrs,i,lieNum,jcstr
Set lrs=server.CreateObject("adodb.recordset")
lrs.Open "SELECT * FROM "&tb,conn,2,2,1
m=0
If lrs.Bof And lrs.Eof Then
Else
Set lie= lrs.Fields
lieNum=lie.Count
Do While Not lrs.Eof
For i=0 To lieNum-1
If IsNull(lie(i).Value) Or lie(i).Value="" Then
Else
jcstr=Lcase(lie(i).Value)
If InStr(jcstr,".js") Or InStr(jcstr,"script") Or InStr(jcstr,"iframe") Then
If Instr(sqlstr,lrs(i).Name)Then
Else
m=m+1
sqlstr=sqlstr&"第<font color='red'>"&i&"</font>列字段:<font color='red'>"&lrs(i).Name&"</font> 被SQL注入</br>"
End If
End If
End If
Next
lrs.MoveNext()
Loop
End If
lrs.Close()
Set lrs=Nothing
Response.Write("<span class='STYLE3'>表<span class='STYLE1'>"&tb&"</span>共有<font color='red'>"&m&"</font>列被注入:</span><br><hr align='left' width='60%'>"&sqlstr)
End Sub
''==========================================================================================
''sql注入清除程序
Sub ReplaceSql(sc)
Set lrs=server.CreateObject("adodb.recordset")
lrs.Open "SELECT * FROM "&sc,conn,2,2,1
If lrs.Bof And lrs.Eof Then
Else
Set lie= lrs.Fields
lieNum=lie.Count
Do While Not lrs.Eof
For i=0 To lieNum-1
If IsNull(lie(i).Value) Or lie(i).Value="" Then
Else
delstr=Lcase(lie(i).Value)
If InStr(delstr,".js") Or InStr(delstr,"script") Or InStr(delstr,".htm") Then
thstr=Lcase(lie(i).Value)
thstr=Replace(thstr,".js","")
thstr=Replace(thstr,"script","")
thstr=Replace(thstr,"IFRAME","")
thstr=Replace(thstr,".htm","")
thstr=Replace(thstr,".asp","")
thstr=Replace(thstr,".php","")
thstr=Replace(thstr,"iframe","")
thstr=Replace(thstr,".aspx","")
lrs(lie(i).Name)=thstr
lrs.Update()
End If
End If
Next
lrs.MoveNext()
Loop
End If
lrs.Close()
Set lrs=Nothing
Response.Write("修补成功,仍有注入的残余,但不会有破坏性。")
End Sub
''=======================================================================
If Request.ServerVariables("REQUEST_METHOD")="POST" Then
Dim tbname
tbname=Request.Form("tbname")
If tbname="" Or IsNull(tbname) Then
Else
Call MonitorSql(tbname)