您的位置:首页 > 其它

portsentry 防止主机被扫描

2013-10-28 15:37 183 查看
一、PortSentry 的安装
下面详细介绍 PortSentry 工具的安装和配置方法。
1. 从 http://sourceforge.net/projects/sentrytools/ 下 载 软 件 的 最 新 版
portsentry-1.2.tar.gz,用 root 用户执行如下命令进行安装:
#tarzxvfportsentry-1.2.tar.gz
#cdportsentry-1.2_beta
#make
#makeinstall
进行到这步时发现报错,系统生成不了 protsentry 执行文件,我们查看
Makefile 文件时发现,make 后面根据操作系统的不同有许多选项。
所以我们重新执行此步操作,将目录删除重新解压缩
然后我们执行 makelinux,发现系统仍然报错,如下:
SYSTYPE=linux
Making./portsentry.c:1585:error:missingterminating"character
./portsentry.c:1595:error:expected?.?.before?.?.token
make:***[linux]Error1 解决方法:
我们打开portsentry.c文件,在1590行左右,我们将带有Copyright1997-2003
字样的那行调整为一行即可,文字有白线标记的那行代码应调整为一行
调整后我们再执行 makelinux&&makeinstall后,PortSentry顺利安装成功,
其安装路径为/usr/local/psionic/portsentry,如下所示表示成功安装此软件:
Edit/usr/local/psionic/portsentry/portsentry.confandchange
yoursettingsifyouhaven'talready.(route,etc)
WARNING:Thisversionandabovenowuseanew
directorystructureforstoringtheprogram
andconfigfiles(/usr/local/psionic/portsentry)。
Pleasemakesureyoudeletetheoldfileswhen
thetestingofthisinstalliscomplete.
cc-O-Wall-DLINUX-DSUPPORT_STEALTH-o./portsentry./portsentry.c\
./portsentry_io.c./portsentry_util.c
./portsentry.c:Infunction?.ortSentryModeTCP?.
./portsentry.c:1187:warning:pointertargetsinpassingargument3of?.ccept?.di
fferinsignedness
./portsentry.c:Infunction?.ortSentryModeUDP?.
./portsentry.c:1384:warning:pointertargetsinpassingargument6of?.ecvfrom?.
differinsignedness
./portsentry.c:Infunction?.sage?.
./portsentry.c:1584:error:missingterminating"character
./portsentry.c:1585:error:?.ourceforget?.undeclared(firstuseinthisfunction)
./portsentry.c:1585:error:(Eachundeclaredidentifierisreportedonlyonce
./portsentry.c:1585:error:foreachfunctionitappearsin.)
./portsentry.c:1585:error:expected?.?.before?.ot?
./portsentry.c:1585:error:stray?.?.inprogram
二、PortSentry 的配置
1.修改配置文件 portsentry.conf
通过 PortSentry 进行入侵检测,首先需要为它定制一份需要监视的端口清
单,以及相应的阻止对策。然后启动后台进程对这些端口进行检测,一旦发现
有人扫描这些端口,就启动相应的对策进行阻拦。
(1)设置端口清单
下面给出portsentry.conf 中关于端口的默认配置情况:
#Un-commenttheseifyouarereallyanal;
#TCP_PORTS="1,7,9,11,15,70,79,80,109,110,111,119,138,139,143,512,513,514,51
5,540,636,1080,1424,2000,2001,[]
#UDP_PORTS="1,7,9,66,67,68,69,111,137,138,161,162,474,513,517,518,635,640,6
41,666,700,2049,31335,27444,34555,[]
#Usetheseifyoujustwanttobeaware:
TCP_PORTS="1,11,15,79,111,119,143,540,635,1080,1524,2000,5742,6667,12345,1
2346,20034,27665,31337,32771,32772,[]
UDP_PORTS="1,7,9,69,161,162,513,635,640,641,700,37444,34555,31335,32770,3
2771,32772,32773,32774,31337,54321"
#Usetheseforjusebare-bones
#TCP_PORTS="1,11,15,110,111,143,540,635,180,1524,2000,12345,12346,20034,3
2771,32772,32773,32774,49724,54320"
#UDP_PORTS="1,7,9,69,161,162,513,640,700,32770,32771,32772,32773,32774,31
337,54321"
可以有选择地去掉前面的注释来启用默认配置,也可以根据自己的实际情
况定制一份新的清单,格式和原来的一样即可。端口列表要根据具体情况而定,
假如服务器为 Web服务器,那么 Web 端口就不需要监视。反之,如果是 FTP
服务器,那么监视 Web端口也是有必要的。
(2)portsentry.conf里的相关文件
在portsentry.conf 中自动配置了许多文件,我们看下它们有哪些用途:
#此文件记录允许合法扫描服务器的主机地址
IGNORE_FILE="/usr/local/psionic/portsentry/portsentry.ignore"
#此文件中保留了以往所有入侵主机的 IP 历史记录
HISTROY_FILE="/usr/lcal/psionic/portsentry/portsentry.history"
#此文件中是已经被阻止连接的主机 IP 记录
BLOCKED_FILE="/usr/local/psionic/portsentry/portsentry.blocked"
(3)设置路由重定向
通过配置portsentry.conf 文件,可以设置一条虚拟路由记录,把数据包重
定向到一个未知的主机。使之无法获取信息。相应配置代码如下:
#Generic
#KILL_ROUTE="/sbin/routeadd$TARGET 跭。444.555.666"
#GenericLinux
KILL_ROUTE="/sbin/routeadd-host$TARGET$gw333.444.555.666
针对不同的平台有不同的路由命令,在配置文件中选择适台自己平台的命
令即可。我的服务器是 CentOS5.5x86_64,以上语法适合 Linux 平台的机
器;PortSentry 非常人性化,下面都有系统对应的配置文件,我们只需要依样操
作即可。
(4)我们还可以利用 Linux 中的iptables命令,可以切断攻击主机的连接:
KILL_ROUTE="/usr/local/sbin/iptables-IINPUT-s$TARGET$-jDROP"
也可 以 直 接 把 攻 击 者 的 IP 记 录 到 /etc/hosts.deny 文 件 中 , 利 用
TCP_Wrappers保护机制来防止攻击:
KILL_HOSTS_DENY="ALL:$TARGET$#Portsentryblocked"
系统默认是利用 TCP_Wrappers来切断与主机之间的连接
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息