1 / 33

安装一台安全的 Linux

安装一台安全的 Linux. 何伟平 hwtony@xmubbs. Linux 的优点. Linux 花费小,硬件要求低 开放源码 相对安全. Linux 的缺点. 学习成本高 缺少技术支持 特定服务无法满足要求. 选择依据. 根据应用选择操作系统 利用 linux 为老机器延长寿命. 安全概述. 防范谁(天灾、病毒、人) 需要什么样的措施 授予最小的权限. 安装要点. 避免连接网络 慎重规划文件系统 仅安装必要程序. 规划文件系统. 选用日志文件系统 独立 /var 、 /home 、 /boot 独立 /usr 、 /tmp.

luke
Télécharger la présentation

安装一台安全的 Linux

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 安装一台安全的Linux 何伟平 hwtony@xmubbs

  2. Linux的优点 • Linux花费小,硬件要求低 • 开放源码 • 相对安全

  3. Linux的缺点 • 学习成本高 • 缺少技术支持 • 特定服务无法满足要求

  4. 选择依据 • 根据应用选择操作系统 • 利用linux为老机器延长寿命

  5. 安全概述 • 防范谁(天灾、病毒、人) • 需要什么样的措施 • 授予最小的权限

  6. 安装要点 • 避免连接网络 • 慎重规划文件系统 • 仅安装必要程序

  7. 规划文件系统 • 选用日志文件系统 • 独立/var、/home、/boot • 独立/usr、/tmp

  8. 安装最小的操作系统 • 安装时选择Minimal

  9. 物理安全 • 限制启动方式 • 保护控制台

  10. 限制启动方式 • 更改启动顺序 • 加上BIOS密码 • 加上Loader密码

  11. 给GRUB加上密码 • 获得加密串 grub> md5crypt Password: ****** Encrypted: $1$qW/qn0$LOnxgnJ2eyQupw2i7aTtS1 • 编辑/boot/grub/grub.conf,加入 password --md5 $1$b.0qn0$X7vUSPBqlznCPHzQQJJQ51

  12. 保护控制台 –禁用ctrl+alt+del • 编辑/etc/inittab • 注释掉如下配置 ca::ctrlaltdel:/sbin/shutdown -t3 -r now

  13. 保护控制台 –禁用程序 • 执行以下命令 rm –f /etc/security/console.apps/halt rm –f /etc/security/console.apps/reboot rm –f /etc/security/console.apps/poweroff for i in /etc/pam.d/* do > sed ‘/[^#].*pam_console.so/s/^/#/’ < $i > temp && mv –f temp $i > done

  14. 帐户安全 • 删除不必要帐户 • 限制帐户权限 • 保护超级管理员帐户

  15. 删除不必要的帐户 • 用以下命令查看用户 cat /etc/passwd| cut -f 1-1 -d: - • 删除adm、lp、sync、shutdown、halt、news、mail、uucp、operator、games、gopher、ftp

  16. 删除不必要的组 • 用以下命令查看用户 cat /etc/group| cut -f 1-1 -d: - • 删除adm、lp、news、mail、uucp、games、dip

  17. 限制帐户权限 • 允许登陆? usermod -s /sbin/nologin username • 登陆方式,位置? • 避免创建默认组

  18. 保护超级管理员帐户 • 编辑/etc/profile,加入 TMOUT=600 • 编辑/etc/pam.d/su,去掉下面的注释 #auth required /lib/security/$ISA/pam_wheel.so use_uid

  19. 文件安全 • 避免不必要的文件权限 • 保护重要文件 • 注意SUID程序

  20. 避免不必要的文件权限 • 修改fstab • /var、/tmp加上noexec、nosuid、nodev • /home加上nosuid、nodev

  21. 保护重要的文件 • chattr –i • /etc/services • /etc/passwd • /etc/shadow • /etc/group • /etc/gshadow • ……

  22. 去掉不必要的SUID • 查找SUID程序 find / -type f \( -perm -04000 -o -perm -02000 \) • 去掉权限 chmod a-s /bin/mount ……

  23. 网络安全 • 配置防火墙 • 删除不必要的服务 • 设置内核参数

  24. IPTABLES (1) # export INET_IP=xxx.xxx.xxx.xxx # iptables -N bad_tcp_packets # iptables -N allowed # iptables -A bad_tcp_packets -p tcp --tcp-flags \ SYN,ACK SYN,ACK -m state --state NEW -j REJECT --reject-with tcp-reset # iptables -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j DROP # iptables -A allowed -p TCP --syn -j ACCEPT # iptables -A allowed -p TCP -m state --state ESTABLISHED,RELATED -j ACCEPT # iptables -A allowed -p TCP -j DROP

  25. IPTABLES (2) # iptables -A INPUT -p tcp -j bad_tcp_packets # iptables -A INPUT -p ALL -i lo -s 127.0.0.1 -j ACCEPT # iptables -A INPUT -p ALL -i lo -s $INET_IP -j ACCEPT # iptables -A INPUT -p ALL -d $INET_IP -m state --state \ ESTABLISHED,RELATED -j ACCEPT # iptables -A OUTPUT -p tcp -j bad_tcp_packets # iptables -A OUTPUT -p ALL -o lo -d 127.0.0.1 -j ACCEPT # iptables -A OUTPUT -p ALL -o lo -d $INET_IP -j ACCEPT # iptables -A OUTPUT -p ALL -s $INET_IP -m state --state \ ESTABLISHED,RELATED -j ACCEPT

  26. IPTABLES (3) # iptables -A INPUT -p TCP --dport 22 -j allowed …… # iptables -A OUTPUT -p UDP --dport 53 -j ACCEPT # iptables -A OUTPUT -p TCP --dport 53 -j allowed # iptables -A OUTPUT -p TCP --dport 21 -j allowed …… # iptables -P INPUT DROP # iptables -P OUTPUT DROP # iptables -P FORWARD DROP # service iptables save

  27. TCP_WRAPPERS • /etc/hosts.deny ALL:ALL • /etc/hosts.allow,用ip sshd:xxx.xxx.xxx.xxx ……

  28. 删除不必要的服务 • chkconfig –list • chkconfig –level 3 servicename off • 手工编辑/etc/rc.d/rc3.d

  29. 设置内核参数 • /etc/sysctl.conf net.ipv4.icmp_echo_ignore_all = 1 net.ipv4.icmp_echo_ignore_broadcasts = 1 net.ipv4.conf.all.accept_source_route = 0 net.ipv4.tcp_syncookies = 1 net.ipv4.conf.all.accept_redirects = 0 net.ipv4.ip_always_defrag = 1 net.ipv4.icmp_ignore_bogus_error_responses = 1 net.ipv4.conf.all.rp_filter = 1 net.ipv4.conf.all.log_martians = 1

  30. 安全相关 • Security Through Obscurity(不公开、即安全) • 日志&备份 • 升级

  31. Security Through Obscurity • 删除/etc/issue、/etc/issue.net • 修改端口

  32. 日志与备份 • 正确设置/var/log权限 • 设置自动备份并测试(/etc、/var/log) • 备份/var/lib/rpm/fileindex.rpm与/var/lib/rpm/packages.rpm,用rpm –Va检查

  33. 谢谢

More Related