荔园在线
荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀
[回到开始]
[上一篇][下一篇]
发信人: jjksam (欢迎光临荔园晨风Linux版, InstallBBS版!), 信区: Linux
标 题: portsentry的安装配置(zz)
发信站: 荔园晨风BBS站 (Sun Dec 9 14:17:01 2001), 转信
copy from http://www.fanqiang.com/a5/b6/20010927/1200011361.html
portsentry的安装配置
本文出自: 作者: Yiming Gong(yiming@security.zz.ha.cn) (2001-09-27 12:00:01)
--------------
Copyright 2000-2003 by 水银流动 Yiming Gong(yiming@security.zz.ha.cn)
All rights reserved. This document may only be reproduced (whole or in
part) for non-commercial purposes. All reproductions must contain this
copyright notice and must not be altered, except by permission of the
author.
--------------
在网络入侵中,几乎所有攻击行为的前奏都是针对目标主机的漏洞扫描,入侵者通
过扫描发现目标系统的漏洞,然后针对性的采取攻击手段。一旦目标主机有没有及时修复
的漏洞,那么这个系统所要面临的局面就可怕了。另一方面,即使主机系统是安全的,某
些开放的端口也会为有意入侵者提供不必要的敏感消息。
自成熟的扫描器鼻祖工具SATAN在1995年4月诞生以来,越来越多的可供免费下载的
扫描器在互连网上被公布出来,每天也都有越来越多的扫描事件发生。利用扫描器发现潜
在的可攻击的目标和发现系统漏洞已经成为网络入侵者必备的技能,它也大大方便了入侵
者的攻击工作。我们可以看看下面的扫描记录,这是我们利用目前在入侵者中使用极为广
泛的扫描工具vetescan对目标主机扫描产生的部分扫描报告:
21/tcp open ftp
23/tcp open telnet
80/tcp open http
111/tcp open sunrpc
513/tcp open login
514/tcp open shell
800/tcp open unknown
TCP Sequence Prediction: Class=random positive increments
Difficulty=14856 (Worthy challenge)
Remote operating system guess: Solaris 2.5, 2.5.1
Nmap run completed -- 1 IP address (1 host up) scanned in 5 seconds
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Lets see what OS the Bitch has: Solaris 2.5, 2.5.1
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Checking for rpcinfo services: bitch said no
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Checking for rpc.cmsd vulnerability: bitch said no
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Checking for OpenLink 3.2 vulnerability: bitch said no
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Checking for amd vulnerability: bitch said no
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Checking for sadmin vulnerability: right on
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Checking for ftp services: bitch said no
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vulnerable version of wu-ftpd: no
可以看到在摘录的段内这个扫描工具报告了目标主机的活动端口,提供的服务,操
作系统的类别,版本,以及系统的漏洞等等。从上述这个很短的报告中,我们就可以很清
楚的了解到目标主机运行的是solaris2.5或solaris2.5.1系统,而且这个系统上有两个"著
名"的漏洞sadmin,adm!我们知道,利用这两个漏洞,入侵者可以很容易的取得超级用户
的权限!现在是我们自身对网络的扫描,如果这次扫描是入侵者发起的呢,当入侵者利用
相似的漏洞扫描软件扫描到这台主机及其上两个恶名远扬的漏洞时,剩下的侵入工作就显
得太简单了。
如果管理员打算阻拦这样的网络扫描行为,那么Portsentry是一个很好的选择,这
个软件是Rowland所写的用于侦测,阻挡网络扫描的免费工具。目前它的版本可用于大多数
主流的unix操作系统,如:Solaris,HPUNIX,Freebsd,AIX,SCO,Linux等。主机在安装
了这个系统以后,可以对指定的一个或多个tcp/udp端口进行监听,当这些端口被试图连接
或扫描时,portsentry能在瞬间捕捉这种连接或扫描企图,并立刻加以屏蔽。除此以外,
portsentry还有如下特别功能
1: 可对外界的扫描动作生成详细的日志记录,包括发起扫描的主机名,扫描时间
,连接的tcp/udp端口等。
2:在linux操作系统下可捕捉SYN/half-open, FIN, NULL, X-MAS等诸多
stealth扫描模式。
3:可有效捕捉非连续随机扫描,我们知道,很多防扫描软件不能辨别随机端口的扫
描,portsentry不然,通过可记忆的内置引擎,即使扫描是随机的,portsentry也可以立
刻辨别出来并迅速加以屏蔽。
4:可以与经典防火墙软件tcp_wrapper结合,将发起扫描的主机写入tcp_wrapper的
hosts.deny文件中。
5:可根据设置自动将发起扫描的主机在路由上重指,屏蔽后续连接功能。使发起扫
描的主机与系统丧失正常连接。
下面我们就来介绍一下这个软件的安装使用
1:下载
管理员可以在http://www.psionic.com/abacus/portsentry这个网站下载相应文件
,当前portsentry的最新版本为1.0版,下载后,需要进行解压,如下:
Yiming.unix.org#gzip -d portsentry-1.0.tar.gz
Yiming.unix.org#tar xvf portsentry-1.0.tar
这样会生成一个名为portsentry-1.0的目录,我们进入这个目录,可以看到内有
README.install等相关文件,为了顺利安装它,我们主要需要关注两个配置文件,
portsentry_config.h和portsentry.conf。
portsentry_config.h文件:
这个文件主要是对系统的设置,我们看一看它的主要部分:
- -------------
/* These are probably ok. Be sure you change the Makefile if you */
/* change the path */
#define CONFIG_FILE "/usr/local/psionic/portsentry/portsentry.conf"
/* The location of Wietse Venema's TCP Wrapper hosts.deny file */
#define WRAPPER_HOSTS_DENY "/etc/hosts.deny"
/* The default syslog is as daemon.notice. You can also use */
/* any of the facilities from syslog.h to send messages to (LOCAL0, etc)
*/
#define SYSLOG_FACILITY LOG_LOCAL3
#define SYSLOG_LEVEL LOG_NOTICE
- -------------
CONFIG_FILE -
这里代表着portsentry配置文件的路径,可不做改动,当然,也可按照需要情况修
改,但注意一点,如果此处改动了,需要同时修改Makefile中的INSTALLDIR和CHILDDIR。
WRAPPER_HOSTS_DENY -
如果系统安装了tcp_wrapper文件,则在这里填入hosts.deny文件的路径即可。这样
portsentry在察觉到有扫描活动时,可以将发起扫描的主机加入tcp_wrapper的hosts.
deny文件。
SYSLOG_FACILITY -
使用syslog的精灵级别,建议使用local级别的,如local3,这样可以单独生成
portsentry自己的日志文件,简洁方便。
SYSLOG_LEVEL - 这里可以保持原有配置不变。
在本例中我们的SYSLOG_FACILITY使用的是local3,而为了使日志功能工作正常,我
们知道需要在solaris的syslogd,所以在/etc/syslog.conf文件中我们需要加入相应的配
置,在本例中如下:
- -------------
#logfile for portsentry
local3.info /var/log/portsentry.log
- -------------
加入后再在/var/log下生成portsentry.log文件,kill -1 'cat
/etc/syslog.pid'重起syslogd进程,使syslogd读新的配置,那么关于日志这一部
分的准备工作即完成了。
portsentry.conf
这个文件是控制portsentry本身的各项设置的,文件的第一部分首先是对端口的基
本配置,包括tcp和udp端口,在TCP_PORTS和UDP_PORTS后是portsentry需要监控的端口,
每个端口之间用","号分隔开,中间没有空格,我们可以看以下片断:
#######################
# Port Configurations #
#######################
# Un-comment these if you are really anal:
#TCP_PORTS="1,7,9,11,15,70,79,80,109,110,111,119,138,139,
143,512,513,514,515,540,635,1080,1524,2000,2001,4000,4001,5742,
6000,6001,6667,12345,12346,20034,30303,32771,32772,32773,32774,
31337,40421,40425,49724,54320"
#UDP_PORTS="1,7,9,66,67,68,69,111,137,138,161,162,474,513,
517,518,635,640,641,666,700,2049,32770,32771,32772,32773,32774,
31337,54321"
#
# Use these if you just want to be aware:
TCP_PORTS="1,11,15,79,82,88,111,119,143,540,635,1080,1524,
2000,5742,6667,12345,12346,20034,31337,32771,32772,32773,32774,
40421,49724,54320"
UDP_PORTS="1,7,9,69,161,162,513,635,640,641,700,32770,32771,
32772,32773,32774,31337,54321"
#
# Use these for just bare-bones
#TCP_PORTS="1,11,15,110,111,143,540,635,1080,524,2000,12345,
12346,20034,32771,32772,32773,32774,49724,54320"
#UDP_PORTS="1,7,9,69,161,162,513,640,700,32770,32771,32772,
32773,32774,31337,54321"
我们可以看到这一片断中提供了3个小的选择部分,由上而下,tcp和udp监控的端口
数目逐渐减少,
portsentry软件默认是选择了第二部分,因为这一部分TCP_PORTS和UDP_PORTS前面
的"#"注释符号被取消了。管理员可以根据需要对监控的级别加以变化。同时,管理员也可
以再添加需要监控的tcp和udp端口,只要是每一项总的端口不超过64个即可。
我们再往下看portsentry.conf这个配置文件:
######################
# Configuration Files#
######################
#
# Hosts to ignore
IGNORE_FILE="/usr/local/psionic/portsentry/portsentry.ignore"
# Hosts that have been denied (running history)
HISTORY_FILE="/usr/local/psionic/portsentry/portsentry.history"
# Hosts that have been denied this session only (temporary until next
restart)
BLOCKED_FILE="/usr/local/psionic/portsentry/portsentry.blocked"
在这一部分的设置中IGNORE_FILE项目表示凡是在portsentry.ignore文件中的主机
发起的扫描及对特定端口的连接portsentry不会加以屏蔽。如果管理员打算加入可信主机
时,在这个文件中加入可信主机的ip即可。
在HISTORY_FILE后所跟的portsentry.history为发起扫描主机的历史纪录文件,
BLOCKED_FILE后所跟的portsentry.blocked为存放本次portsentry启动后发起扫描的主机
记录文件。它们均为系统自动生成的,格式类似下面的记录:
965974779 - 08/11/2000 14:19:39 Host: hack.unix.org/11.22.33.44 Port:
1
TCP Blocked,从中管理员可以检查端口扫描的情况。
再来看portsentry.conf中下一个比较重要的部分:
在本文开始的时候,曾经讲到portsentry具有路由重指屏蔽功能,当portsentry拦
截到扫描企图时,可以将系统与发起扫描的主机之间的路由重指,使发起扫描的主机丧失
与安装portsentry所在系统的正常连接,这样一方面使扫描工作无法进行下去,另一方面
,使发起扫描的主机在路由上不可能与安装portsentry的系统再次连解。也就是说,当路
由重指后,发起扫描的主机与安装portsentry的连接被"永远"中断了。这一部分的配置如
下:
###################
# Dropping Routes:#
###################
# Generic
#KILL_ROUTE="/sbin/route add $TARGET$ 333.444.555.666"
# Generic Linux
#KILL_ROUTE="/sbin/route add -host $TARGET$ gw 333.444.555.666"
# Newer versions of Linux support the reject flag now。 This
# is cleaner than the above option。
#KILL_ROUTE="/sbin/route add -host $TARGET$ reject"
# Generic BSD (BSDI, OpenBSD, NetBSD, FreeBSD)
#KILL_ROUTE="/sbin/route add $TARGET$ 333.444.555.666"
# Generic Sun
KILL_ROUTE="/usr/sbin/route add $TARGET$ 11.22.33.55 1"
# NEXTSTEP
#KILL_ROUTE="/usr/etc/route add $TARGET$ 127.0.0.1 1"
# FreeBSD (Not well tested。)
#KILL_ROUTE="route add -net $TARGET$ -netmask 255.255.255.255 127.0.0.1
-blackhole"
# Digital UNIX 4.0D (OSF/1 / Compaq Tru64 UNIX)
#KILL_ROUTE="/sbin/route add -host -blackhole $TARGET$ 127.0.0.1"
# Generic HP-UX
#KILL_ROUTE="/usr/sbin/route add net $TARGET$ netmask 255.255.255.0
127.0.0.1"
如上我们根据具体安装的系统类型选择即可,本例中我们安装portsentry的操作系
统用的是solaris,所以我们将Generic
Sun部分下面的#注释号取消,同时,将KILL_ROUTE="/usr/sbin/route add
$TARGET$后跟一个"死"的网关,比如与安装portsentry系统在同一网段的主机ip,
这样,就从路由上改变了数据包的方向。
配置文件的最后一部分是告警标示,在PORT_BANNER后任意输入你打算给扫描者的告
警信息即可。
######################
# Port Banner Section#
######################
PORT_BANNER="** please go away! -----Yiming----zzpenetrate**"
至此,基本功能的配置就结束了。
其实除此以外,portsentry还提供了一些其它的安装选项,如果管理员有更多的兴
趣,可以在portsentry.conf中的ADVANCED_PORTS_TCP,
External Command等地方对配置加以细化。
2:编译:
在上述关键文件设置无误后,在portsentry的主目录下执行make <systype>,
<systype>可为linux, bsd,
solaris, hpux, hpux-gcc,freebsd, openbsd, netbsd, bsdi, aix, osf
,
generic,管理员根据所在操作系统选择即可,我们实验的操纵系统为solaris,所
以执行make
solaris编译即可,编译结束,再执行make
install,这样,portsentry的关键文件即会生成到前面配置文件中所设的
/usr/local/psionic/portsentry下。我们可以在这个目录下看到portsentry,
portsentry.conf,portsentry.ignore三个文件。
3:运行
portsentry有基本的工作状态有两中:portsentry -tcp, portsentry -udp,分别
代表对tcp
和udp端口进行监控,对linux来讲,还有其它四种模式: portsentry -stcp,
portsentry -atcp,
portsentry -sudp, portsentry -audp,这里就不介绍了。
现在我们打算对tcp端口进行监控,所以我们在/usr/local/psionic/portsentry下
执行./portsentry
-tcp,portsentry系统即开始运行,我们可以看上面讲到的日志文件
/var/log/port文件,如下:
Aug 11 22:12:20 secu.unix.org portsentry[8398]: adminalert: Psionic
PortSentry 1.0 is starting.
Aug 11 22:12:20 secu.unix.org portsentry[8399]: adminalert: Going
into
listen mode on TCP port: 1
Aug 11 22:12:20 secu.unix.org portsentry[8399]: adminalert: Going
into
listen mode on TCP port: 11
Aug 11 22:12:20 secu.unix.org portsentry[8399]: adminalert: Going
into
listen mode on TCP port: 15
Aug 11 22:12:20 secu.unix.org portsentry[8399]: adminalert: Going
into
listen mode on TCP port: 15
Aug 11 22:12:20 secu.unix.org portsentry[8399]: adminalert: Going
into
listen mode on TCP port: 79
Aug 11 22:12:20 secu.unix.org portsentry[8399]: adminalert: Going
into
listen mode on TCP port: 82
Aug 11 22:12:20 secu.unix.org portsentry[8399]: adminalert: Going
into
listen mode on TCP port: 88
Aug 11 22:12:20 secu.unix.org portsentry[8399]: adminalert: Going
into
listen mode on TCP port: 111
Aug 11 22:12:20 secu.unix.org portsentry[8399]: adminalert: Going
into
listen mode on TCP port: 119
Aug 11 22:12:20 secu.unix.org portsentry[8399]: adminalert: Going
into
listen mode on TCP port: 143
Aug 11 22:12:20 secu.unix.org portsentry[8399]: adminalert: Going
into
listen mode on TCP port: 540
Aug 11 22:12:20 secu.unix.org portsentry[8399]: adminalert: Going
into
listen mode on TCP port: 635
Aug 11 22:12:20 secu.unix.org portsentry[8399]: adminalert: Going
into
listen mode on TCP port: 1080
Aug 11 22:12:20 secu.unix.org portsentry[8399]: adminalert: Going
into
listen mode on TCP port: 1524
(省略一部分) Aug 11 22:12:20 secu.unix.org portsentry[8399]:
adminalert:
PortSentry is now active and listening。
我们看到在系统启动有三个过程,首先是Psionic PortSentry 1.0
程序本身启动。其后是对所设置需要监控的端口逐个加载,最后PortSentry进入激
活侦听状态。这时portsentry即启动完毕。
4:扫描试验
我们可以就以上设置来做实验,首先,我们来从hack.unix.org这台主机来尝试扫描
安装了portsentry的主机secu.unix.org,我们使用的端口扫描工具为目前在unix下很流行
的nmap,操作如下,首先,在未启动portsentry的状况下开始扫描。
Hack.unix.org# nmap secu.unix.org
Starting nmap V. 2.30BETA17 by fyodor@insecure.org (
www.insecure.org/nmap/ )
Interesting ports on secu.unix.org
Port State Service
1/tcp open tcpmux
11/tcp open systat
15/tcp open netstat
21/tcp open ftp
23/tcp open telnet
25/tcp open smtp
37/tcp open time
43/tcp open whois
79/tcp open finger
80/tcp open http
110/tcp open pop-3
111/tcp open sunrpc
119/tcp open nntp
143/tcp open imap2
540/tcp open uucp
635/tcp open unknown
901/tcp open samba-swat
1080/tcp open socks
1524/tcp open ingreslock
1999/tcp open tcp-id-port
2000/tcp open callbook
4045/tcp open lockd
6000/tcp open X11
6667/tcp open irc
31337/tcp open Elite
32771/tcp open sometimes-rpc5
32772/tcp open sometimes-rpc7
32773/tcp open sometimes-rpc9
32775/tcp open sometimes-rpc13
32776/tcp open sometimes-rpc15
Nmap run completed -- 1 IP address (1 host up) scanned in 1 second
我们看到,portsentry没有启动时,secu.unix.org这台主机上所有的端口被清楚的
扫描出来了。现在我们启动portsentry以后,再扫描看有什么反应。
Hack.unix.org# nmap secu.unix.org
Starting nmap V. 2.30BETA17 by fyodor@insecure.org (
www.insecure.org/nmap/)
Interesting ports on secu.unix.org
我们看到没有任何端口信息输出,nmap的端口查询被终止了。此时,看一下
portsentry的日志文件
Jun 21 21:34:38 secu.unix.org portsentry[451]: attackalert: Connect
from
host: hack.unix.org/hack.unix.org to TCP port: 1
Jun 21 21:34:38 secu.unix.org portsentry[451]: attackalert: Host
hack.unix.org has been blocked via wrappers with string: "ALL:
hack.unix.org"
Jun 21 21:34:38 secu.unix.org portsentry[451]: attackalert: Host
hack.unix.org has been blocked via dropped route using command:
"/usr/sbin/route add hack.unix.org 11.22.33.55 1"
可以看到portsentry在扫描开始的瞬间即被激活。随后portsentry将hack.unix.
org这台主机加入了tcp_wrapper的hosts.deny文件中。然后,将路由重指。我们可以看看
secu.unix.org此时的路由表:
secu.unix.org#netstat -rn
相关部分如下:
Routing Table:
Destination Gateway Flags Ref Use Interface
- -------------------- -------------------- ----- ----- ------
---------
hack.unix.org 11.22.33.55 UGH 0 5571
这时,因为网关被改为11.22.33.55,所以hack.unix.org与secu.unix.org不可能正
常连接了,此时,别说扫描了,连hack.unix.org
发起的ping这个动作,secu.unix.org都不会再响应。
上面是对主机的扫描,我们再对portsentry监控的单个端口连接看看,在下面的例
子中,我们连接secu.unix.org的tcp 11端口。
hack2.unix.org#telnet secu.unix.org 11
Trying secu.unix.org...
Connected to secu.unix.org.
Escape character is '^]'.
** please go away! -----Yiming----zzpenetrate**
Connection closed by foreign host
我们看到,对端口11的连接被拒绝了,同时所设定的告警标示也产生作用。与上面
的例子相同,此时secu.unix.org的路由表中hack2.unix.org也被重新定向,hack2.unix.
org这个来源的数据包将丧失与secu.unix.org的连接。
由上我们可以看出,portsentry在防范网络扫描,阻拦端口恶意连接上的功能是极
为强大的。对安全管理员来讲,当自己的网络倍受扫描的威胁时,portsentry不失为一个
很好的应对工具 (http://www.fanqiang.com)
--
____________________________________________
|┏━━━━━━━━━━━━━━━━━━━━┓
|┃ 欢迎光临荔园晨风 Linux 版,InstallBBS 版┃
|┗━━━━━━━━━━━━━━━━━━━━┛
﹋﹋﹋﹋﹋﹋﹋﹋﹋﹋﹋﹋﹋﹋﹋﹋﹋﹋﹋﹋﹋﹋
welcome to http://www.linuxbyte.net
※ 修改:·jjksam 於 Dec 10 15:45:59 修改本文·[FROM: 192.168.0.146]
※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.0.146]
[回到开始]
[上一篇][下一篇]
荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店