FreeBSD基本安全加固:
1.修改 /etc/rc.conf:JHZLinux联盟
sendmail_enable="NONE" //关闭sendmailJHZLinux联盟
syslogd_enable="YES" //开户syslogdJHZLinux联盟
syslogd_flags="-ss" //禁止syskogd接受来自远程主机的记录并关闭端口,但仍然允许 localhost 进行日志记录JHZLinux联盟
tcp_drop_synfin="YES" //阻止OS指纹识别的企图,需在内核中加入" options TCP_DROP_SYNFIN "JHZLinux联盟
log_in_vain="YES" //记录每一个到关闭端口的连接企图,这个最好是在启用了防火墙功能之后再打开.JHZLinux联盟
accounting_enable="YES" //打开系统审计功能JHZLinux联盟
clear_tmp_enable="YES" //在系统启动时将清空 /tmpJHZLinux联盟
icmp_drop_redirect="YES" //丢弃ICMP重定向。可以防止DOS攻击或劫持进程JHZLinux联盟
icmp_log_redirect="YES" //记录ICMP重定向JHZLinux联盟
fsck_y_enable="YES" //计算机启动时候发现文件系统失效,将以-y参数运行fsckJHZLinux联盟
update_motd="NO" //防止系统自动加入信息到motd
sendmail_enable="NONE"JHZLinux联盟
syslogd_enable="YES"JHZLinux联盟
syslogd_flags="-ss"JHZLinux联盟
tcp_drop_synfin="YES"JHZLinux联盟
log_in_vain="YES"JHZLinux联盟
accounting_enable="YES"JHZLinux联盟
clear_tmp_enable="YES"JHZLinux联盟
icmp_drop_redirect="YES"JHZLinux联盟
icmp_log_redirect="YES"JHZLinux联盟
fsck_y_enable="YES"JHZLinux联盟
update_motd="NO"
修改/etc/sysctl.conf文件,调整IP堆栈JHZLinux联盟
net.inet.icmp.bmcastecho=0 #关闭对广播类型的响应,过滤ICMP响应后,服务器无法ping 通,可以提高部分安全性能JHZLinux联盟
net.inet.udp.checksum=1 #对UDP包的校验和进行计算,防止不正确的UDP包的攻击
net.inet.tcp.blackhole=2JHZLinux联盟
net.inet.udp.blackhole=1JHZLinux联盟
#在默认情况下,操作系统在关闭的端口上接受到TCP SYN段的时候,会发送RST信息包,告诉攻击者这个端口关闭了,导致攻击者继续扫描下一个端口,使端口扫描简单化,浪费了本机CPU时间在DOS上。我们可以使用blackhole来控制对没有socket监听的TCP或者UDP端口接受到连接请求时的行为。JHZLinux联盟
#当设置这个选项后,系统将马上丢弃这个包而不发RST包,连接端将看到"Connection reset by peer."
JHZLinux联盟
2.限制远程登录的终端数量:JHZLinux联盟
修改 /etc/ttys,如果不想打开太多的终端,请把对应的 "on" 改为 "off" ,当然,只是一部分 ttys .保持至少1个 "on," 否则会无法登录,这将导致系统无法使用.ttyv8 默认情况下是 "off" .
JHZLinux联盟
3.限制远程登录地址和用户:JHZLinux联盟
限制远程登录,可以通过编辑 /etc/login.access 实现的:JHZLinux联盟
如果禁止一切远程登录(这意味着必须物理地坐在机器前面),删除下面这一行前面的#号:JHZLinux联盟
#-:wheel:ALL EXCEPT LOCAL .win.tue.nlJHZLinux联盟
并把 .win.tue.nl 去掉,于是它看起来将像这样:JHZLinux联盟
-:wheel:ALL EXCEPT LOCAL JHZLinux联盟
如果你需要从远程登录,那么把.win.tue.nl 替换为相应的IP或域名。如果有多个地址,用空格分开。JHZLinux联盟
如果只有一两个用户的话,那么可以拒绝其他人登录:JHZLinux联盟
-:ALL EXCEPT user1 user2:ttyv0 ttyv1 ttyv2 ttyv3 ttyv4JHZLinux联盟
用具体的用户名替换掉 user1 user2 。如果需要的话,增加相应的tty。
4.升级源码:JHZLinux联盟
创建stable-supfile:JHZLinux联盟
*default host=cvsup4.freebsdchina.org JHZLinux联盟
*default base=/usr JHZLinux联盟
*default prefix=/usr JHZLinux联盟
*default release=cvs tag=RELENG_4 JHZLinux联盟
*default delete use-rel-suffix JHZLinux联盟
src-all JHZLinux联盟
ports-all tag=. JHZLinux联盟
执行:JHZLinux联盟
cvsup -g -L 2 stable-supfileJHZLinux联盟
完成后在/usr/src中执行:JHZLinux联盟
make worldJHZLinux联盟
完成后,再编译内核,如果发生错误:JHZLinux联盟
执行:JHZLinux联盟
mergemaster -pJHZLinux联盟
make worldJHZLinux联盟
mergemaster -i
JHZLinux联盟
5.内核编译:JHZLinux联盟
加入:JHZLinux联盟
options IPFILTER #ipfilter supportJHZLinux联盟
options IPFILTER_LOG #ipfilter loggingJHZLinux联盟
options TCP_DROP_SYNFIN #drop TCP packets with SYN+FIN 丢弃SYNFIN包,需要在rc.conf中打开
options SC_NO_HISTORY #取消历史记录,在登出系统后刷新虚拟终端缓冲中的内容JHZLinux联盟
options SC_DISABLE_DDBKEY # disable `debug' key 取消debug键JHZLinux联盟
options SC_DISABLE_REBOOT # disable reboot key sequence 取消ctl+alt+del键
6.修改/etc/sysctl.conf文件,调整IP堆栈JHZLinux联盟
net.inet.tcp.blackhole=2 JHZLinux联盟
net.inet.udp.blackhole=1JHZLinux联盟
在默认情况下,操作系统在关闭的端口上接受到TCP SYN段的时候,会发送RST信息包,告诉攻击者这个端口关闭了,导致攻击者继续扫描下一个端口,使端口扫描简单化,浪费了本机CPU时间在DOS上。我们可以使用blackhole来控制对没有socket监听的TCP或者UDP端口接受到连接请求时的行为。 JHZLinux联盟
当设置这个选项后,系统将马上丢弃这个包而不发RST包,连接端将看到"Connection reset by peer."
7.使用 tcp wrapper (/etc/hosts.allow)允许/拒绝访问特定的TCP服务。 JHZLinux联盟
tcp_wrappers 可以在访问者要求服务前先检查/etc/hosts.allow 文件中设定的规则,符合放行规则的才会去启动服务程序,可以达到有条件开放系统服务的目的。 JHZLinux联盟
在/etc/host.allow文件中,注释掉"ALL:ALL:allow",去掉其他无关服务访问,增加如下内容: JHZLinux联盟
sshd: localhost : allow JHZLinux联盟
sshd: friendlycomputer : allow JHZLinux联盟
sshd: all : deny JHZLinux联盟
另外需要注意的是: JHZLinux联盟
注意规则的先后顺序,因为tcp_wrappers的规则有first match 的特性,最好把放行的规则写在前面,然后在后面加一条全部禁止的规则; JHZLinux联盟
为避免 DNS 欺骗,规则尽量使用IP表示; JHZLinux联盟
FreeBSD缺省的/etc/hosts.allow中第一条规则是 ALL : ALL : allow,自己的规则一定要放在他前面才有效。
8.登录环境:
JHZLinux联盟freebsd# rm -rf /etc/motd
JHZLinux联盟freebsd# ee /etc/motd
JHZLinux联盟I am administrator , Who are you ?
JHZLinux联盟freebsd# touch /etc/COPYRIGHT
JHZLinux联盟freebsd# ee /etc/gettytab
JHZLinux联盟default:下面一行改为:
JHZLinux联盟:cb:ce:ck:lc#1000:im=\r\This is
www.lingfengcn ! \n\r\n:sp#1200:\
9、配置SSHJHZLinux联盟
修改/etc/ssh/ssh_config文件JHZLinux联盟
1)使用protocol 2代替protocol 1,SSH2更加安全,可以防止攻击者通过修改携带的版本banner来劫持(hijacking)启动会话进程并降低到protocol 1。注释掉protocol 2,1 改用下面语句代替:JHZLinux联盟
protocol 2JHZLinux联盟
2)合理设置最大连接数量, 防止DOS攻击JHZLinux联盟
MaxStartups 5:50:10JHZLinux联盟
3)禁止远程root和空密码登录,建议关闭X11forwordingJHZLinux联盟
X11Forwarding no
10、检视系统记录:JHZLinux联盟
在 /var/log 中,记录了许多系统的信息,我们应该要时常检视它们:JHZLinux联盟
adduser 使用 adduser 的记录。 JHZLinux联盟
cron 定时排程的记录。 JHZLinux联盟
maillog 邮件记录。 JHZLinux联盟
messages 系统讯息记录。 JHZLinux联盟
security 安全性记录,如防火墙。
FreeBSD 预设每天定时执行一些分析的工作,并将结果寄给 root,建议你最好每天阅读它们。我们可以在 /etc/mail/aliases 的开头中加入下面这一行:
JHZLinux联盟freebsd# ee /etc/mail/aliases
JHZLinux联盟加入:
JHZLinux联盟root:
wanglin.sun@163.comJHZLinux联盟freebsd# newaliases //让设定生效
JHZLinux联盟这样,所有寄给 root 的信件,都会自动转给所设定的信箱。root 每天会收到 "daily run output" 及 "security check output" 这二封信,这是依照我们在 /etc/defaults/periodic.conf 中所设定的定时执行工作输出的结果。
例如:JHZLinux联盟
FreeBSD-SA-05:17.devfs.asc JHZLinux联盟
FreeBSD-SA-05:16.zlib.asc JHZLinux联盟
FreeBSD-SA-05:15.tcp.asc JHZLinux联盟
FreeBSD-SA-05:14.bzip2.asc JHZLinux联盟
FreeBSD-SA-05:13.ipfw.asc JHZLinux联盟
FreeBSD-SA-05:12.bind9.asc JHZLinux联盟
FreeBSD-SA-05:11.gzip.asc JHZLinux联盟
FreeBSD-SA-05:10.tcpdump.asc JHZLinux联盟
FreeBSD-SA-05:09.htt.asc
Solution:
Perform one of the following:
1) Upgrade your vulnerable system to 5-STABLE, or to the RELENG_5_4,JHZLinux联盟
or RELENG_5_3 security branch dated after the correction date.
2) To patch your present system:
The following patches have been verified to apply to FreeBSD 5.3, andJHZLinux联盟
5.4 systems.
a) Download the relevant patch from the location below, and verify theJHZLinux联盟
detached PGP signature using your PGP utility.
b) Apply the patch.
freebsd# cd /usr/srcJHZLinux联盟
freebsd# patch < /path/to/patch
我们可以选择下列二种方式其中之一来进行修补,第一种方式是将您的 FreeBSD 升级至 5-STABLE、RELENG_5_4、或 RELENG_5_3。第二种方式是我们最常用的方法,也就是下载修补的原始码。通常我们必须依照所使用的 FreeBSD 系统来下载不同版本所使用的补丁。上述范例中,其修补文件分别供 FreeBSD 5.3 及 5.4 使用。
我们以 FreeBSD 5.4 为例,首先,我们必须下载更新档,请使用下列指令下载:
我们所下载的 patch 档是将漏洞修补前及修补后的原始码差异存成一个档案,接下来我们必须将这个差异和我们系统中的原始码合并。因此,我们系统中一定要安装 FreeBSD 的原始码,也就是 /usr/src 这个目录下有原始码的数据,如果您在安装 FreeBSD 时并未安装原始码,您可以使用 sysinstall 来安装原始码套件。接下来我们就可以将所下载的档案合并到系统中:
freebsd# cd /usr/srcJHZLinux联盟
freebsd# patch < /usr/src/devfs.patchJHZLinux联盟
最后,依照这个修补档的说明,我们必须重新编译系统核心,请参考「编译核心」一章,并于安装新核心之后重新开机即可。并非所有修补都必须重新编译系统核心,有的修补可能要重新编译其它非核心程序,甚至整个系统,我们必须按照 Solution 的说明执行适当的步骤。JHZLinux联盟
JHZLinux联盟
12.FreeBSD下,IP与MAC绑定命令:JHZLinux联盟
arp -s <mac> <lan_pc_ip>JHZLinux联盟
如JHZLinux联盟
arp -s 99:de:dd:88:od:cc 192.168.1.5JHZLinux联盟
arp -s 99:de:d4:68:od:cc 192.168.1.8