Linux系统安全加固
系统方面:
1.BIOS
2.SSH安全
3.删除/etc/motd
4.禁用代码编译
5.禁用所有特殊账户
6.chmod危险文件
7.关闭不用的服务和端口
8.内核加固(sysctl.conf)
9./tmp,/var/tmp,/dev/shm分区的安全
系统方面: 1.BIOS 2.SSH安全 3.删除/etc/motd 4.禁用代码编译 5.禁用所有特殊账户 6.chmod危险文件 7.关闭不用的服务和端口 8.内核加固(sysctl.conf) 9./tmp,/var/tmp,/dev/shm分区的安全 10.限制 crontab 及 at 的使用 11.指定允许root登陆的TTY设备 12.选择一个安全的密码 13.检查Rootkit 14.安装补丁 15.Nessus漏洞扫描器 16.利用capability特征加强Linux系统安全 17.防范arp嗅探 18.防范cc攻击 19.端口限制 1.BIOS 在系统启动的时候设置一个BIOS密码 2.SSH安全 SSH是一个协议,利用它可以登录到一个远程系统或远程执行系统命令, 默认允许root登录,并且sshv1存在缺陷,我们应该在 sshd_config禁止root访问和使用sshv2来让ssh更加安全。 方法: vi /etc/ssh/sshd_config 把协议改为2 PermitRootLogin = no 重启sshd /etc/rc.d/init.d/sshd restart 一些没必要的转发、dns等等不需要的一律关闭 3.删除/etc/motd 4.禁用代码编译 可以禁用代码编译并且只把编译的权限分配给一个用户组 方法: 添加编译用户组 /usr/sbin/groupadd compiler ,cd /usr/bin 把常见的编译器所属组赋给编译用户组 chgrp compiler *cc* chgrp compiler *++* chgrp compiler ld chgrp compiler as 设置mysqlaccess的访问 chgrp root mysqlaccess 设置权限 chmod 750 *cc* chmod 750 *++* chmod 750 ld chmod 750 as chmod 755 mysqlaccess 把用户添加到组里 修改/etc/group compiler:x:520:user1,user2 5.禁用所有特殊账户 你应该从系统中删除所有默认用户和组 例如news,lp,sync,shutdown,uucp,games,halt 等 方法: 删除账户userdel name 删除组 groupdel name 锁定特定账户:/usr/sbin/usermod -L -s /bin/false user 6.chmod危险文件 这可能是限制不具有root权限的用户执行下面这些命令 方法: chmod 700 /bin/ping chmod 700 /usr/bin/finger chmod 700 /usr/bin/who chmod 700 /usr/bin/w chmod 700 /usr/bin/locate chmod 700 /usr/bin/whereis chmod 700 /sbin/ifconfig chmod 700 /usr/bin/pico chmod 700 /usr/bin/vi chmod 700 /usr/bin/which chmod 700 /usr/bin/gcc chmod 700 /usr/bin/make chmod 700 /bin/rpm chmod 700 /etc/passwd chmod 700 /etc/shadow 7.关闭不用的服务和端口 8.内核加固(sysctl.conf) sysctl.conf用来加固内核,目的是避免DOS和欺骗攻击 方法: sysctl kern.ipc.maxsockets=100000 ##增加并发的socket,对于ddos很有用 sysctl kern.ipc.somaxconn=65535 ##打开文件数 sysctl net.inet.tcp.msl=2500 ##timeout时间 到/proc/sys目录或sysctl -a命令了解下当前配置的大概情况 然后vi /etc/sysctl.conf 添加如下内容: # Kernel sysctl configuration file for Red Hat Linux # # For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and # sysctl.conf(5) for more details. # Controls IP packet forwarding net.ipv4.ip_forward = 0 # Controls source route verification net.ipv4.conf.default.rp_filter = 1 # Controls the System Request debugging functionality of the kernel kernel.sysrq = 0 # Controls whether core dumps will append the PID to the core filename. # Useful for debugging multi-threaded applications. kernel.core_uses_pid = 1 #Prevent SYN attack net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_max_syn_backlog = 2048 net.ipv4.tcp_synack_retries = 2 # Disables packet forwarding net.ipv4.ip_forward=0 # Disables IP source routing net.ipv4.conf.all.accept_source_route = 0 net.ipv4.conf.lo.accept_source_route = 0 net.ipv4.conf.eth0.accept_source_route = 0 net.ipv4.conf.default.accept_source_route = 0 # Enable IP spoofing protection, turn on source route verification net.ipv4.conf.all.rp_filter = 1 net.ipv4.conf.lo.rp_filter = 1 net.ipv4.conf.eth0.rp_filter = 1 net.ipv4.conf.default.rp_filter = 1 # Disable ICMP Redirect Acceptance net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.lo.accept_redirects = 0 net.ipv4.conf.eth0.accept_redirects = 0 net.ipv4.conf.default.accept_redirects = 0 # Enable Log Spoofed Packets, Source Routed Packets, Redirect Packets net.ipv4.conf.all.log_martians = 1 net.ipv4.conf.lo.log_martians = 1 net.ipv4.conf.eth0.log_martians = 1 # Disables IP source routing net.ipv4.conf.all.accept_source_route = 0 net.ipv4.conf.lo.accept_source_route = 0 net.ipv4.conf.eth0.accept_source_route = 0 net.ipv4.conf.default.accept_source_route = 0 # Enable IP spoofing protection, turn on source route verification net.ipv4.conf.all.rp_filter = 1 net.ipv4.conf.lo.rp_filter = 1 net.ipv4.conf.eth0.rp_filter = 1 14 net.ipv4.conf.default.rp_filter = 1 # Disable ICMP Redirect Acceptance net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.lo.accept_redirects = 0 net.ipv4.conf.eth0.accept_redirects = 0 net.ipv4.conf.default.accept_redirects = 0 # Disables the magic-sysrq key kernel.sysrq = 0 # Modify system limits for Ensim WEBppliance fs.file-max = 65000 # Decrease the time default value for tcp_fin_timeout connection net.ipv4.tcp_fin_timeout = 15 # Decrease the time default value for tcp_keepalive_time connection net.ipv4.tcp_keepalive_time = 1800 # Turn off the tcp_window_scaling net.ipv4.tcp_window_scaling = 0 # Turn off the tcp_sack net.ipv4.tcp_sack = 0 # Turn off the tcp_timestamps net.ipv4.tcp_timestamps = 0 # Enable TCP SYN Cookie Protection net.ipv4.tcp_syncookies = 1 # Enable ignoring broadcasts request net.ipv4.icmp_echo_ignore_broadcasts = 1 # Enable bad error message Protection net.ipv4.icmp_ignore_bogus_error_responses = 1 # Log Spoofed Packets, Source Routed Packets, Redirect Packets net.ipv4.conf.all.log_martians = 1 # Set maximum amount of memory allocated to shm to 256MB kernel.shmmax = 268435456 # Improve file system performance vm.bdflush = 100 1200 128 512 15 5000 500 1884 2 # Improve virtual memory performance vm.buffermem = 90 10 60 # Increases the size of the socket queue (effectively, q0). net.ipv4.tcp_max_syn_backlog = 1024 # Increase the maximum total TCP buffer-space allocatable net.ipv4.tcp_mem = 57344 57344 65536 # Increase the maximum TCP write-buffer-space allocatable net.ipv4.tcp_wmem = 32768 65536 524288 15 # Increase the maximum TCP read-buffer space allocatable net.ipv4.tcp_rmem = 98304 196608 1572864 # Increase the maximum and default receive socket buffer size net.core.rmem_max = 524280 net.core.rmem_default = 524280 # Increase the maximum and default send socket buffer size net.core.wmem_max = 524280 net.core.wmem_default = 524280 # Increase the tcp-time-wait buckets pool size net.ipv4.tcp_max_tw_buckets = 1440000 # Allowed local port range net.ipv4.ip_local_port_range = 16384 65536 # Increase the maximum memory used to reassemble IP fragments net.ipv4.ipfrag_high_thresh = 512000 net.ipv4.ipfrag_low_thresh = 446464 # Increase the maximum amount of option memory buffers net.core.optmem_max = 57344 # Increase the maximum number of skb-heads to be cached net.core.hot_list_length = 1024 ## DO NOT REMOVE THE FOLLOWING LINE! ## nsobuild:20051206 重启后生效 /sbin/sysctl -p sysctl -w net.ipv4.route.flush=1 9./tmp,/var/tmp,/dev/shm分区的安全 /tmp,/var/tmp,/dev/shm目录是不安全的,任何用户都可以执行脚本。 最好的解决办法是挂载ncexec和nosuid选项的参数 方法: /tmp目录: cd /dev 创建 100M (“count”) 的存储文件: dd if=/dev/zero of=tmpMnt bs=1024 count=100000 设为一个扩展的文件系统: /sbin/mke2fs /dev/tmpMnt (“…is not a block special device. continue?”回答yes) 备份现有临时文件: cp -R /tmp/ /tmp_backup 用noexec挂载新文件系统: mount -o loop,rw,nosuid,noexec /dev/tmpMnt /tmp chmod 0777 /tmp 把备份的文件拷贝回去: cp -R /tmp_backup/* /tmp/ 删除备份: rm -rf /tmp_backup 修改/etc/fstab 添加下面的条目使其在引导时仍然有效 /dev/tmpMnt /tmp ext2 loop,rw,nosuid,noexec 0 0 /var/tmp目录: mv /var/tmp /var/tmpbak ln -s /tmp /var/tmp cp /var/tmpbak/* /tmp/ /dev/shm目录: 编辑/etc/fstab 把 none /dev/shm tmpfs defaults,rw 0 0 改为none /dev/shm tmpfs defaults,nosuid,noexec,rw 0 0 10.限制 crontab 及 at 的使用 使用者可以用 crontab 和 at 指令来安排自己定时执行的工作。一般的使用者并不需要拥有 crontab 或 at 的执行权,我们可以为这个指令设限,只允许必要的使用者执行。如果要限制使用 crontablinux系统安全,只需要在 /var/cron 目录中,加入 allow 或是 deny 这个档即可。例如,我们只允许少数几个使用者执行 crontab,我们可以新增 /var/cron/allow 这个档,内容为该使用者的名称。相对的,如果我们要限制少数几个使用者执行 crontab,只要编辑 /var/cron/deny 这个档即可。而指令 at 的限制也是一样,不同的只是允许执行 at 指令的名单是 /var/at/at.allow,而 拒绝的名单是 /var/at/at.deny。 11.指定允许root登陆的TTY设备 12.选择一个安全的密码 13.检查Rootkit 14.安装补丁 更新官方打补丁。 依旧存在俩个致命漏洞,普通用户直接获取root权限,和普通用户重启服务器的攻击,需要按照官方打上补丁,攻击方法和漏洞修补稍后写出 15.Nessus漏洞扫描器 检查系统是否存在其他没被注意到的漏洞,可以用其他工具扫描,比如:appscan、wvs 16.虽然我们可以直接修改/proc/sys/kernel/cap-bound来删除系统的某中能力,但是这样毕竟非常的不方便。有一个程序lcap可以帮助我们更方便的从系统中删除指定的能力。它可以从~spoon/lcap/下载。编译之后就可以直接使用。如果不带参数,lcap可以列出系统当前支持的各种能力: [root@nixe0n lcap-0.0.6]# ./lcap Current capabilities: 0xFFFFFEFF 0) *CAP_CHOWN 1) *CAP_DAC_OVERRIDE 2) *CAP_DAC_READ_SEARCH 3) *CAP_FOWNER 4) *CAP_FSETID5) *CAP_KILL 6) *CAP_SETGID7) *CAP_SETUID 8)CAP_SETPCAP 9) *CAP_LINUX_IMMUTABLE 10) *CAP_NET_BIND_SERVICE 11) *CAP_NET_BROADCAST 12) *CAP_NET_ADMIN13) *CAP_NET_RAW 14) *CAP_IPC_LOCK 15) *CAP_IPC_OWNER 16) *CAP_SYS_MODULE 17) *CAP_SYS_RAWIO 18) *CAP_SYS_CHROOT 19) *CAP_SYS_PTRACE 20) *CAP_SYS_PACCT21) *CAP_SYS_ADMIN 22) *CAP_SYS_BOOT 23) *CAP_SYS_NICE 24) *CAP_SYS_RESOURCE 25) *CAP_SYS_TIME 17.arp嗅探 双向绑定,arpon 18.cc攻击 防火墙处理 19.端口限制 对外开放的端口只有80,还是个反向的代理(比如:nginx,nginx保留日志),SSH端口做IP限制,如果有必要用denyhosts,fan2ban,都可以 20.防火墙的严格限制 Related posts:Nginx安全加固 Php安全加固 Tomcat安全加固 Mysql安全加固 (编辑:威海站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |