linux主机安全加固方案 下载本文

目 录

LINUX加固方案 ............................................................................. 错误!未定义书签。 1.安装最新安全补丁.......................................................................................................... 2 2.网络和系统服务.............................................................................................................. 2 3.核心调整.......................................................................................................................... 4 4.日志系统.......................................................................................................................... 5 5.文件/目录访问许可权限 ................................................................................................ 5 6.系统访问, 认证和授权.................................................................................................... 6 7.用户账号和环境.............................................................................................................. 8 8.关键安全工具的安装...................................................................................................... 9

1.安装最新安全补丁

1 项目: 安装操作系统提供商发布的最新的安全补丁 注释: 各常见的Linux发布安全信息的web地址:

RedHat Linux:

http://www.redhat.com/support/ Caldera OpenLinux:

http://www.calderasystems.com/support/security/ Conectiva Linux:

http://www.conectiva.com.br/atualizacoes/

Debian GNU/Linux:

http://www.debian.org/security/ Mandrake Linux: http://www.linux-mandrake.com/en/fupdates.php3 LinuxPPC:

http://www.linuxppc.com/support/updates/security/ S.u.S.E. :

http://www.suse.de/security/index.html

Yellow Dog Linux :

http://www.yellowdoglinux.com/resources/errata.shtml 2.网络和系统服务

inetd/xinetd网络服务: 设置项 1 确保只有确实需要的服务在运行: 先把所有通过ineted/xineted运行的网络服务关闭,再打开确实需要的服务 2

设置xinetd访问控制

注释: 绝大多数通过inetd/xinetd运行的网络服务都可以被禁止,比如echo, exec, login, shell,who,finger等.对于telnet, r系列服务, ftp等, 强烈建议使用SSH来代替.

在/etc/xinetd.conf文件的”default {}”块中加入如下行:

only_from=/ /

每个/(比如

192.168.1.0/24)对表示允许的源地址 启动服务:

1 2

3 4

5

设置项 关闭NFS服务器进程: 运行 chkconfig nfs off 关闭NFS客户端进程: 运行 chkconfig nfslock off chkconfig autofs off 关闭NIS客户端进程: chkconfig ypbind off 关闭NIS服务器进程:

运行 chkconfig ypserv off chkconfig yppasswd off 关闭其它基于RPC的服务: 运行 chkconfig portmap off

注释: NFS通常存在漏洞会导致未授权的文件和系统访问.

NIS系统在设计时就存在安全隐患

6 7 8

关闭SMB服务

运行 chkconfig smb off 禁止Netfs脚本 chkconfig netfs off 关闭打印机守护进程 chkconfig lpd off

关闭启动时运行的 X Server sed 's/id:5:initdefault:/id:3:initdefault:/' \\ < /etc/inittab > /etc/inittab.new mv /etc/inittab.new /etc/inittab chown root:root /etc/inittab chmod 0600 /etc/inittab 关闭Mail Server chkconfig postfix off

基于RPC的服务通常非常脆弱或者缺少安全的认证,但是还可能共享敏感信息.除非确实必需,否则应该完全禁止基于RPC的服务.

除非确实需要和Windows系统共享文件,否则应该禁止该服务.

如果不需要文件共享可禁止该脚本 如果用户从来不通过该机器打印文件则应该禁止该服务.Unix的打印服务有糟糕的安全记录. 对于专门的服务器没有理由要运行X Server, 比如专门的Web服务器

9 10

11 12 13 14

关闭Web Server chkconfig httpd off 关闭SNMP

chkconfig snmpd off 关闭DNS Server chkconfig named off 关闭 Database Server chkconfig postgresql off 关闭路由守护进程 chkconfig routed off chkconfig gated off 关闭Webmin远程管理工具

多数Unix/Linux系统运行Sendmail作为邮件服务器, 而该软件历史上出现过较多安全漏洞,如无必要,禁止该服务

可能的话,禁止该服务.

如果必需运行SNMP的话,应该更改缺省的community string 可能的话,禁止该服务

Linux下常见的数据库服务器有

Mysql, Postgre, Oracle等, 没有必要的话,应该禁止这些服务

组织里仅有极少数的机器才需要作为路由器来运行.大多数机器都使用简单的”静态路由”, 并且它不需要运行特殊的守护进程

Webmin是一个远程管理工具,它有糟

15

16

chkconfig webmin off 17 18

关闭Squid Web Cache chkconfig squid off

可能的话禁止inetd/xinetd chkconfig inetd off 或 chkconfig xinetd off 设置守护进程掩码 cd /etc/rc.d/init.d

if [ \echo \fi

糕的认证和会话管理历史, 所以应该谨慎使用

如果必需使用, 应该谨慎配置 如果没有网络服务通过inetd/xinetd运行则可以禁止它们

系统缺省的umask 值应该设定为022以避免守护进程创建所有用户可写的文件

19

3.核心调整

1 设置项 禁止core dump: cat <>/etc/security/limits.conf * soft core 0 * hard core 0 END_ENTRIES

限制NFS客户端使用特权端口: perl -i.orig -pe \\

'next if (/^\\s*#/ || /^\\s*$/); ($res, @hst) = split(\foreach $ent (@hst) { undef(%set);

($optlist) = $ent =~ /\\((.*?)\\)/; foreach $opt (split(/,/, $optlist)) { $set{$opt} = 1; }

delete($set{\$set{\$ent =~ s/\\(.*?\\)//;

$ent .= \}

$hst[0] = \$_ = \/etc/exports 网络参数调整:

cat <> /etc/sysctl.conf net.ipv4.ip_forward = 0

net.ipv4.conf.all.accept_source_route = 0 注释: 允许core dump会耗费大量的磁盘空间.

2

可以防止非特权用户发起的automouted NFS攻击.

3

详见:

http://www.linuxhq.com/kernel/v2.4/doc/networking/ip-sysctl.txt.html 或

net.ipv4.tcp_max_syn_backlog = 4096 net.ipv4.conf.all.rp_filter = 1 END_SCRIPT

cat <> /etc/sysctl.conf net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.default.accept_redirects = 0 END_SCRIPT

chown root:root /etc/sysctl.conf chmod 0600 /etc/sysctl.conf

http://www.linuxhq.com/kernel/v2.2/doc/networking/ip-sysctl.txt.html

4.日志系统

1 设置项 捕捉发送给AUTH 和AUTHPRIV facility的消息到日志文件/var/log/secure:

if [ `grep -c 'auth\\.' /etc/syslog.conf` -eq 0 ] then

echo -e \>>/etc/syslog.conf fi

if [ `grep -c 'authpriv\\.' /etc/syslog.conf` eq 0 ] then

echo -e \>>/etc/syslog.conf fi

touch /var/log/secure

chown root:root /var/log/secure chmod 600 /var/log/secure

注释: .syslog中的AUTH 和AUTHPRIV facility包含了大量安全相关的信息, 不是所有Linux发布都记录这些日志信息.应该把这些信息记录到

/var/log/secure文件中(该文件仅超级用户可读)

5.文件/目录访问许可权限

1 设置项 对/etc/fstab中的可移动介质增加”nosuid”选项: awk '($2 ~ /^\\/m.*\\/(floppy|cdrom)$/ && \\ $3 != \

{ $4 = sprintf(\{ print }' /etc/fstab >/etc/fstab.new mv /etc/fstab.new /etc/fstab chown root:root /etc/fstab chmod 0644 /etc/fstab

禁止普通用户来mount可移动文件系统: cd /etc/security 注释: 可以移动介质是引入恶意代码的一个重要途径.该设置可以防止普通用户通过CDROM或软盘引入SUID程序

2

在基于Linux的发布中普通用户在控制台上有更大的权限, 可以使用CD-