服务器维护,服务器代维,安全设置,漏洞扫描,入侵检测服务

dirtysea 发表于 2013-4-16 14:47:56

linux系统加固paper

<P>&nbsp;</P>
<P>
<TABLE cellSpacing=0 cellPadding=0>
<TBODY>
<TR>
<TD class=t_f id=postmessage_20996><STRONG>目录:</STRONG><BR>1.BIOS<BR>2.SSH安全<BR>3.禁用telnet<BR>4.禁用代码编译<BR>5.ProFTP<BR>6.TCPwrappers<BR>7.创建一个SU组<BR>8.root通知<BR>9.history安全<BR>10.欢迎信息<BR>11.禁用所有特殊账户<BR>12.chmod危险文件<BR>13.指定允许root登陆的TTY设备<BR>14.选择一个安全的密码<BR>15.检查Rootkit<BR>16.安装补丁<BR>17.隐藏Apache信息<BR>18.隐藏php信息<BR>19.关闭不使用的服务<BR>20.检测监听中的端口<BR>21.关闭打开的端口和服务<BR>22.删除不用的rpm包<BR>23.禁用危险的php函数<BR>24.安装配置防火墙<BR>25.安装和配置BFD<BR>26.内核加固(sysctl.conf)<BR>27.更改SSH端口<BR>28./tmp /var/tmp,/dev/shm分区安全<BR>29.PHP IDS<BR><BR><STRONG>总结</STRONG><BR>========================================================================<BR>介绍<BR><BR>这个教程将一步步的指引你,使你的Linux系统变得安全。<BR>任何默认安装的操作系统都是不够安全的,本文将指引你如何建立一个<BR>相对安全的Linux系统。<BR>========================================================================<BR>1.BIOS<BR>你应该总是在系统启动的时候设置一个BIOS密码和禁用从CD-ROM和软盘引导。<BR>这将防止一些人未经允许访问你的系统和更改BIOS设置<BR><BR>2.SSH安全<BR>SSH是一个协议,利用它可以登录到一个远程系统或远程执行系统命令,<BR>默认允许root登录,并且sshv1存在**,我们应该在<BR>sshd_config禁止root访问和使用sshv2来让ssh更加安全。<BR><BR>方法:<BR>
<DIV class=blockcode>
<DIV id=code_mGv>
<OL>
<LI>vi /etc/ssh/sshd_config</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>把协议改为2<BR>
<DIV class=blockcode>
<DIV id=code_5Dd>
<OL>
<LI>PermitRootLogin = no</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>重启<BR>
<DIV class=blockcode>
<DIV id=code_ReU>
<OL>
<LI>sshd /etc/rc.d/init.d/sshd restart</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>3.禁用telnet<BR>早期的Linux默认开启telnet服务,telnet,ftp,rlogin都是明文传输的协议<BR>是容易被嗅探到的,这就是为什么推荐使用安全的版本(sftp,scp,ssh)的原因<BR>如果你必须要使用telnet,那么至少应该隐藏banner信息<BR><BR>方法:<BR>修改<BR>
<DIV class=blockcode>
<DIV id=code_cKZ>
<OL>
<LI>/etc/xinetd.d/telnet<BR>
<LI>disable=yes</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>4.禁用代码编译<BR>你可以禁用代码编译并且只把编译的权限分配给一个用户组<BR>方法:<BR>添加编译用户组
<DIV class=blockcode>
<DIV id=code_69H>
<OL>
<LI>/usr/sbin/groupadd compiler ,cd /usr/bin</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>把常见的编译器所属组赋给编译用户组<BR>
<DIV class=blockcode>
<DIV id=code_fDn>
<OL>
<LI>chgrp compiler *cc*<BR>
<LI>chgrp compiler *++*<BR>
<LI>chgrp compiler ld<BR>
<LI>chgrp compiler as</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>设置mysqlaccess的访问<BR>
<DIV class=blockcode>
<DIV id=code_gC6>
<OL>
<LI>chgrp root mysqlaccess</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>设置权限<BR>
<DIV class=blockcode>
<DIV id=code_4pn>
<OL>
<LI>chmod 750 *cc*<BR>
<LI>chmod 750 *++*<BR>
<LI>chmod 750 ld<BR>
<LI>chmod 750 as<BR>
<LI>chmod 755 mysqlaccess</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>把用户添加到组里<BR>修改/etc/group<BR>
<DIV class=blockcode>
<DIV id=code_GRh>
<OL>
<LI>compiler:x:520:user1,user2</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>5.ProFTP<BR>你可以通过修改proftpd.conf来禁止root登陆<BR>方法:<BR>修改/etc/proftpd.conf<BR>
<DIV class=blockcode>
<DIV id=code_7X4>
<OL>
<LI>Add RootLogin off</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>重启<BR>
<DIV class=blockcode>
<DIV id=code_219>
<OL>
<LI>proftpd /sbin/service proftpd stop<BR>
<LI>/sbin/service proftpd start</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>6.TCP wrappers<BR>编辑hosts.allow和hosts.deny可以限制或允许访问inet服务<BR><BR>方法:<BR>限制访问inet服务<BR>修改/etc/hosts.allow<BR>建议格式:<BR>
<DIV class=blockcode>
<DIV id=code_JfE>
<OL>
<LI>#Approved IP addresses<BR>
<LI>ALL:192.168.0.1<BR>
<LI>ALL:192.168.5.2<BR>
<LI>#CSV uploader machine<BR>
<LI>proftpd:10.0.0.5<BR>
<LI>#pop3 from antwhere<BR>
<LI>ipop3:ALL</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>修改/etc/hosts.deny<BR>
<DIV class=blockcode>
<DIV id=code_efP>
<OL>
<LI>ALL:ALL EXCEPT localhostENY</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>7.创建SU用户组<BR>因为我们在SSH禁止了root用户访问并且禁用了telnet,所有我们应该<BR>分配给一些用户su权限来获取root特权<BR><BR>方法:<BR>vi /etc/group<BR>添加一行 wheel:x:10:root,user1,user2<BR>
<DIV class=blockcode>
<DIV id=code_AvI>
<OL>
<LI>chgrp wheel /bin/su<BR>
<LI>chmod o-rwx /bin/su</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>8.root通知<BR>当一个具有root权限的用户登录的时候发mail<BR>方法:<BR>编辑/root下的.bashrc ,当有root权限的用户登录时发生email通知<BR>
<DIV class=blockcode>
<DIV id=code_Rjm>
<OL>
<LI>echo ‘ALERT ? Root Shell Access (Server Name) on:’ `date` `who` | mail -s “Alert: Root Access from `who | cut -d”(” -f2 | cut -d”)” -f1`” your@email.com</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>9.history安全<BR>这是一个避免删除.bash_history或重定向到/dev/null的好主意<BR>因此他不能清除或删除他最后执行的命令<BR>方法:<BR>
<DIV class=blockcode>
<DIV id=code_MYa>
<OL>
<LI>chattr +a .bash_history<BR>
<LI>chattr +i .bash_history</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>获取用户的人会知道他的历史命令锁定并且要同意才可以使用服务<BR><BR>10.使用欢迎信息<BR>你必须提供一些信息让攻击者知道该系统不对公众开放。<BR>在国外有类似案件,攻击者入侵一个系统并且系统没有这些信息,<BR>这种情况下法院不能做任何裁决,因为系统说welcome<BR><BR>方法:<BR>删除/etc/redhat-release<BR>编辑/etc/issue /etc/motd并显示警告信息<BR><BR>11.禁用所有特殊账户<BR>你应该从系统中删除所有默认用户和组<BR>例如news,lp,sync,shutdown,uucp,games,halt 等<BR>方法:<BR>删除账户userdel name<BR>删除组 groupdel name<BR>锁定特定账户:
<DIV class=blockcode>
<DIV id=code_W6H>
<OL>
<LI>/usr/sbin/usermod -L -s /bin/false user</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>12.chmod危险文件<BR>这可能是限制不具有root权限的用户执行下面这些命令的好主意<BR>方法:<BR>
<DIV class=blockcode>
<DIV id=code_rkI>
<OL>
<LI>chmod 700 /bin/ping<BR>
<LI>chmod 700 /usr/bin/finger<BR>
<LI>chmod 700 /usr/bin/who<BR>
<LI>chmod 700 /usr/bin/w<BR>
<LI>chmod 700 /usr/bin/locate<BR>
<LI>chmod 700 /usr/bin/whereis<BR>
<LI>chmod 700 /sbin/ifconfig<BR>
<LI>chmod 700 /usr/bin/pico<BR>
<LI>chmod 700 /usr/bin/vi<BR>
<LI>chmod 700 /usr/bin/which<BR>
<LI>chmod 700 /usr/bin/gcc<BR>
<LI>chmod 700 /usr/bin/make<BR>
<LI>chmod 700 /bin/rpm</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>13.指定允许root登陆的TTY设备<BR>/etc/securetty文件允许你指定root可以从哪个TTY设备登录<BR>方法:<BR>
<DIV class=blockcode>
<DIV id=code_JjH>
<OL>
<LI>vi /etc/securetty</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>只留2个连接<BR>
<DIV class=blockcode>
<DIV id=code_Mez>
<OL>
<LI>tty1<BR>
<LI>tty2</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>14.选择一个安全的密码<BR>在/etc/login.defs文件中定义了shadow密码的具体配置<BR>默认密码长度最短为5字符,你应该至少设置为8<BR>方法:<BR>
<DIV class=blockcode>
<DIV id=code_Nur>
<OL>
<LI>vi /etc/login.defs<BR>
<LI>PASS_MIN_LEN 8</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>15.检测Rootkit<BR>用chkrootkit或rkhunter,以chkrootkit为例<BR>方法:<BR>
<DIV class=blockcode>
<DIV id=code_jtU>
<OL>
<LI>wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz<BR>
<LI>wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.md5</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>首先检查md5校验值: md5sum chkrootkit.tar.gz<BR>然后解压安装<BR>
<DIV class=blockcode>
<DIV id=code_rM5>
<OL>
<LI>tar -zxvf chkrootkit.tar.gz<BR>
<LI>cd chkrootkit<BR>
<LI>./configure<BR>
<LI>make sense</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>然后运行./chkrootkit<BR>我们可以将其添加到contrab使其每天自动扫描:<BR>
<DIV class=blockcode>
<DIV id=code_taL>
<OL>
<LI>vi /etc/cron.daily/chkrootkit.sh</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>#!/bin/bash<BR># 输入chkrootkit的安装目录<BR>
<DIV class=blockcode>
<DIV id=code_zZE>
<OL>
<LI>cd /root/chkrootkit/</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR># 输入你想收到检测报告的email<BR>
<DIV class=blockcode>
<DIV id=code_G4t>
<OL>
<LI>./chkrootkit | mail -s “Daily chkrootkit from Server Name” your@email.com</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>16.安装补丁<BR>你要经常检查更新以修复某些**或系统稳定性的改进<BR>否则你存在漏洞的系统将会不时的遭受新的攻击<BR>方法:<BR>
<DIV class=blockcode>
<DIV id=code_c11>
<OL>
<LI>列出可用更新:up2date -l<BR>
<LI>安装未排除的更新:up2date -u<BR>
<LI>安装包括排除的更新up2date -uf</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>17.隐藏Apache信息<BR>你应该隐藏Apache的banner信息使攻击者不知道Apache的版本,从而使他们难以利用漏洞<BR>方法:<BR>修改/etc/httpd/conf/httpd.conf<BR>改变服务器签名:<BR>
<DIV class=blockcode>
<DIV id=code_97Z>
<OL>
<LI>ServerSignature Off</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>重启Apache /sbin/service httpd restart<BR><BR>18.隐藏php信息<BR>你应该隐藏php的banner信息,原因同上<BR>方法:<BR>修改php.ini<BR>改变<BR>
<DIV class=blockcode>
<DIV id=code_1M3>
<OL>
<LI>expose_php=Off</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>重启Apache<BR><BR>19.关闭不用的服务<BR>你应该把任何未使用的服务关闭,可以在/etc/xinetd.d文件夹里找到<BR>方法:<BR>
<DIV class=blockcode>
<DIV id=code_ksB>
<OL>
<LI>cd /etc/xinetd.d<BR>
<LI>grep disable *</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>这将显示所有服务开启或关闭的状态,然后根据需要来开启或关闭服务<BR><BR>20.检测监听的端口<BR>检测是否有必要开放端口是非常重要的<BR>方法:<BR>
<DIV class=blockcode>
<DIV id=code_BKh>
<OL>
<LI>netstat -tulp或<BR>
<LI>lsof -i -n | egrep ‘COMMAND|LISTEN|UDP’或<BR>
<LI>nmap!</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>21.关闭端口和服务<BR>重点是关闭在系统启动时打开的不需要的端口<BR>方法:<BR>对于正在运行的服务,可以执行chkconfig -list | grep on<BR>禁用服务可以执行chkconfig servicename off<BR>然后停止正在运行的服务:/etc/init.d/service stop<BR><BR>22.删除不用的rpm包<BR>首先应该清楚你的系统的作用,它是web,mail,file服务器或其他<BR>然后觉得哪些包是必要的,之后删除不需要的软件包<BR>方法:<BR>首先列出安装列表rpm -qa<BR>更详细的信息rpm -qi rpmname<BR>还可以检测删除包可能出现的冲突rpm -e ?test rpmname<BR><BR>23.禁用危险的php函数<BR>你应该禁用php的危险函数防止在网站上执行系统命令<BR>方法:<BR>
<DIV class=blockcode>
<DIV id=code_IIS>
<OL>
<LI>whereis php.ini<BR>
<LI>vi /usr/local/lib/php.ini</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>编辑<BR>
<DIV class=blockcode>
<DIV id=code_H9h>
<OL>
<LI>disable_functions = “symlink,shell_exec,exec,proc_close,proc_open,popen,<BR>
<LI>system,dl,passthru,escapeshellarg, escapeshellcmd”</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>24.安装配置防火墙<BR>高级策略防火墙(APF)是一种IP表(网络过滤),它是基于当今互联网部署服务器防火墙系统的基本需要和客户部署LINUX安装的唯一需要而设计的。 它是最好的开源防<BR><BR>火墙之一。<BR><BR>配置APF防火墙方法:<BR>下载APF:wget <A href="http://www.r-fx.ca/downloads/apf-current.tar.gz" target=_blank>http://www.r-fx.ca/downloads/apf-current.tar.gz</A><BR>解压安装:<BR>
<DIV class=blockcode>
<DIV id=code_KMX>
<OL>
<LI>tar -zxvf apf-current.tar.gz<BR>
<LI>cd apf-0.9.7-1<BR>
<LI>./install.sh</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>然后我们配置它vi /etc/apf/conf.apf<BR>一般配置:<BR>启用防火墙使用DShield.org块列表<BR>USE_DS=”1″<BR>然后我将列出常规的配置和CPanel配置方式,因为CPanel是应该最广泛的虚拟主机管理软件<BR><BR>1.常规配置(DNS,Mail,Web,FTP)<BR>
<DIV class=blockcode>
<DIV id=code_i3t>
<OL>
<LI>Common ingress (inbound)<BR>
<LI># Common ingress (inbound) TCP ports -3000_3500 = passive port range for Pure FTPD IG_TCP_CPORTS=”21,22,25,53,80,110,143,443,995″<BR>
<LI>#<BR>
<LI># Common ingress (inbound) UDP ports IG_UDP_CPORTS=”53″<BR>
<LI># Egress filtering <BR>
<LI>EGF=”1″<BR>
<LI># Common egress (outbound) TCP ports<BR>
<LI>EG_TCP_CPORTS=”21,25,80,443,43″<BR>
<LI>#<BR>
<LI># Common egress (outbound) UDP ports<BR>
<LI>EG_UDP_CPORTS=”20,21,53″<BR>
<LI><BR>
<LI>2.CPanel配置<BR>
<LI>Common ingress (inbound) ports<BR>
<LI># Common ingress (inbound) TCP ports -3000_3500 = passive port range for Pure FTPD IG_TCP_CPORTS=”21,22,25,53,80,110,143,443,2082,2083, 2086,2087,<BR>
<LI><BR>
<LI>2095, 2096,3000_3500″<BR>
<LI>#<BR>
<LI># Common ingress (inbound) UDP ports<BR>
<LI>IG_UDP_CPORTS=”53″<BR>
<LI>Common egress (outbound) ports<BR>
<LI># Egress filtering <BR>
<LI>EGF=”1″<BR>
<LI># Common egress (outbound) TCP ports<BR>
<LI>EG_TCP_CPORTS=”21,25,80,443,43,2089″<BR>
<LI>#<BR>
<LI># Common egress (outbound) UDP ports<BR>
<LI>EG_UDP_CPORTS=”20,21,53″</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>之后启动防火墙 /etc/apf/apf -s<BR>如果运行良好我在回去修改配置文件,使DEVM=”0″<BR>然后我们配置APF的AntiDos: vi /etc/apf/ad/conf.antidos<BR><BR>找到下面的内容并替换成你的资料<BR>
<DIV class=blockcode>
<DIV id=code_Hwl>
<OL>
<LI># Organization name to display on outgoing alert emails<BR>
<LI>CONAME=”Your Company”<BR>
<LI># Send out user defined attack alerts <BR>
<LI>USR_ALERT=”0″<BR>
<LI>#<BR>
<LI># User for alerts to be mailed to<BR>
<LI>USR=you@yourco.com</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>你应把USR_ALERT改为1<BR>保存后重启APF:/etc/apf/apf ?r<BR>
<DIV class=blockcode>
<DIV id=code_ugt>
<OL>
<LI>To make the firewall start with the Operating System: chkconfig ?level 2345 apf on</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>APF开机自启动:chkconfig ?level 2345 apf on<BR>禁止一个IP用/etc/apf/apf -d ip或vi /etc/apf/deny_hosts.rules<BR>允许一个IP用/etc/apf/apf -a ip或vi /etc/apf/deny_hosts.rules<BR><BR>25.安装配置BFD(暴力破解检测)<BR>BFD是一个用于分析应用日志和检测验证失败的模块化shell脚本<BR>而且安装配置和用法都是非常容易的。使用BFD的原因很简单。<BR>其实在LINUX领域几乎没有结合防火墙或实时设备来监控不验证和<BR>暴力攻击审计的程序。在用BFD之前你必须安装APF防火墙。<BR><BR>方法:<BR>
<DIV class=blockcode>
<DIV id=code_0vp>
<OL>
<LI>wget http://www.r-fx.ca/downloads/bfd-current.tar.gz<BR>
<LI>tar -zxvf bfd-current.tar.gz<BR>
<LI>cd bfd-0.9</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>然后我们来配置它 vi /usr/local/bfd/conf.bfd<BR>把以下内容改为你的资料<BR>
<DIV class=blockcode>
<DIV id=code_uJo>
<OL>
<LI># Enable/disable user alerts <BR>
<LI>ALERT_USR=”1″<BR>
<LI>#<BR>
<LI># User alert email address<BR>
<LI>EMAIL_USR=”your@mail.com”<BR>
<LI>#<BR>
<LI># User alert email; subject<BR>
<LI>SUBJ_USR=”Brute Force Warning for $HOSTNAME”<BR>
<LI>#</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>然后vi /usr/local/bfd/ignore.hosts<BR>把你的IP设置成允许主机,避免意外的锁定自己。<BR>之后重启BFD /usr/local/sbin/bfd -s<BR><BR>26.内核加固(sysctl.conf)<BR>sysctl.conf用来加固内核,目的是避免DOS和欺骗攻击<BR>方法:<BR>到/proc/sys目录或sysctl -a命令了解下当前配置的大概情况<BR>然后vi /etc/sysctl.conf<BR>添加如下内容:<BR>
<DIV class=blockcode>
<DIV id=code_prN>
<OL>
<LI># Kernel sysctl configuration file for Red Hat Linux<BR>
<LI>#<BR>
<LI># For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and<BR>
<LI># sysctl.conf(5) for more details.<BR>
<LI># Controls IP packet forwarding<BR>
<LI>net.ipv4.ip_forward = 0<BR>
<LI># Controls source route verification<BR>
<LI>net.ipv4.conf.default.rp_filter = 1<BR>
<LI># Controls the System Request debugging functionality of the kernel<BR>
<LI>kernel.sysrq = 0<BR>
<LI># Controls whether core dumps will append the PID to the core filename.<BR>
<LI># Useful for debugging multi-threaded applications.<BR>
<LI>kernel.core_uses_pid = 1<BR>
<LI>#Prevent SYN attack<BR>
<LI>net.ipv4.tcp_syncookies = 1<BR>
<LI>net.ipv4.tcp_max_syn_backlog = 2048<BR>
<LI>net.ipv4.tcp_synack_retries = 2<BR>
<LI># Disables packet forwarding<BR>
<LI>net.ipv4.ip_forward=0<BR>
<LI># Disables IP source routing<BR>
<LI>net.ipv4.conf.all.accept_source_route = 0<BR>
<LI>net.ipv4.conf.lo.accept_source_route = 0<BR>
<LI>net.ipv4.conf.eth0.accept_source_route = 0<BR>
<LI>net.ipv4.conf.default.accept_source_route = 0<BR>
<LI># Enable IP spoofing protection, turn on source route verification<BR>
<LI>net.ipv4.conf.all.rp_filter = 1<BR>
<LI>net.ipv4.conf.lo.rp_filter = 1<BR>
<LI>net.ipv4.conf.eth0.rp_filter = 1<BR>
<LI>net.ipv4.conf.default.rp_filter = 1<BR>
<LI># Disable ICMP Redirect Acceptance<BR>
<LI>net.ipv4.conf.all.accept_redirects = 0<BR>
<LI>net.ipv4.conf.lo.accept_redirects = 0<BR>
<LI>net.ipv4.conf.eth0.accept_redirects = 0<BR>
<LI>net.ipv4.conf.default.accept_redirects = 0<BR>
<LI># Enable Log Spoofed Packets, Source Routed Packets, Redirect Packets<BR>
<LI>net.ipv4.conf.all.log_martians = 1<BR>
<LI>net.ipv4.conf.lo.log_martians = 1<BR>
<LI>net.ipv4.conf.eth0.log_martians = 1<BR>
<LI># Disables IP source routing<BR>
<LI>net.ipv4.conf.all.accept_source_route = 0<BR>
<LI>net.ipv4.conf.lo.accept_source_route = 0<BR>
<LI>net.ipv4.conf.eth0.accept_source_route = 0<BR>
<LI>net.ipv4.conf.default.accept_source_route = 0<BR>
<LI># Enable IP spoofing protection, turn on source route verification<BR>
<LI>net.ipv4.conf.all.rp_filter = 1<BR>
<LI>net.ipv4.conf.lo.rp_filter = 1<BR>
<LI>net.ipv4.conf.eth0.rp_filter = 1<BR>
<LI>14<BR>
<LI>net.ipv4.conf.default.rp_filter = 1<BR>
<LI># Disable ICMP Redirect Acceptance<BR>
<LI>net.ipv4.conf.all.accept_redirects = 0<BR>
<LI>net.ipv4.conf.lo.accept_redirects = 0<BR>
<LI>net.ipv4.conf.eth0.accept_redirects = 0<BR>
<LI>net.ipv4.conf.default.accept_redirects = 0<BR>
<LI># Disables the magic-sysrq key<BR>
<LI>kernel.sysrq = 0<BR>
<LI># Modify system limits for Ensim WEBppliance<BR>
<LI>fs.file-max = 65000<BR>
<LI># Decrease the time default value for tcp_fin_timeout connection<BR>
<LI>net.ipv4.tcp_fin_timeout = 15<BR>
<LI># Decrease the time default value for tcp_keepalive_time connection<BR>
<LI>net.ipv4.tcp_keepalive_time = 1800<BR>
<LI># Turn off the tcp_window_scaling<BR>
<LI>net.ipv4.tcp_window_scaling = 0<BR>
<LI># Turn off the tcp_sack<BR>
<LI>net.ipv4.tcp_sack = 0<BR>
<LI># Turn off the tcp_timestamps<BR>
<LI>net.ipv4.tcp_timestamps = 0<BR>
<LI># Enable TCP SYN Cookie Protection<BR>
<LI>net.ipv4.tcp_syncookies = 1<BR>
<LI># Enable ignoring broadcasts request<BR>
<LI>net.ipv4.icmp_echo_ignore_broadcasts = 1<BR>
<LI># Enable bad error message Protection<BR>
<LI>net.ipv4.icmp_ignore_bogus_error_responses = 1<BR>
<LI># Log Spoofed Packets, Source Routed Packets, Redirect Packets<BR>
<LI>net.ipv4.conf.all.log_martians = 1<BR>
<LI># Set maximum amount of memory allocated to shm to 256MB<BR>
<LI>kernel.shmmax = 268435456<BR>
<LI># Improve file system performance<BR>
<LI>vm.bdflush = 100 1200 128 512 15 5000 500 1884 2<BR>
<LI># Improve virtual memory performance<BR>
<LI>vm.buffermem = 90 10 60<BR>
<LI># Increases the size of the socket queue (effectively, q0).<BR>
<LI>net.ipv4.tcp_max_syn_backlog = 1024<BR>
<LI># Increase the maximum total TCP buffer-space allocatable<BR>
<LI>net.ipv4.tcp_mem = 57344 57344 65536<BR>
<LI># Increase the maximum TCP write-buffer-space allocatable<BR>
<LI>net.ipv4.tcp_wmem = 32768 65536 524288<BR>
<LI>15<BR>
<LI># Increase the maximum TCP read-buffer space allocatable<BR>
<LI>net.ipv4.tcp_rmem = 98304 196608 1572864<BR>
<LI># Increase the maximum and default receive socket buffer size<BR>
<LI>net.core.rmem_max = 524280<BR>
<LI>net.core.rmem_default = 524280<BR>
<LI># Increase the maximum and default send socket buffer size<BR>
<LI>net.core.wmem_max = 524280<BR>
<LI>net.core.wmem_default = 524280<BR>
<LI># Increase the tcp-time-wait buckets pool size<BR>
<LI>net.ipv4.tcp_max_tw_buckets = 1440000<BR>
<LI># Allowed local port range<BR>
<LI>net.ipv4.ip_local_port_range = 16384 65536<BR>
<LI># Increase the maximum memory used to reassemble IP fragments<BR>
<LI>net.ipv4.ipfrag_high_thresh = 512000<BR>
<LI>net.ipv4.ipfrag_low_thresh = 446464<BR>
<LI># Increase the maximum amount of option memory buffers<BR>
<LI>net.core.optmem_max = 57344<BR>
<LI># Increase the maximum number of skb-heads to be cached<BR>
<LI>net.core.hot_list_length = 1024<BR>
<LI>## DO NOT REMOVE THE FOLLOWING LINE!<BR>
<LI>## nsobuild:20051206</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>重启后生效<BR>/sbin/sysctl -p<BR>
<DIV class=blockcode>
<DIV id=code_Ipl>
<OL>
<LI>sysctl -w net.ipv4.route.flush=1</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>27.更改SSH端口<BR>更改SSH默认端口号在一定程度上可以提高安全性<BR>方法:<BR>vi /etc/ssh/sshd_config<BR>Port 22改为其他端口<BR>当然不要忘记把更改的端口加进防火墙<BR>然后重启生效/etc/init.d/ssh restart<BR>如果安装了APF并把端口添加之后,还要重启APF:/etc/init.d/apf restart<BR><BR>28./tmp,/var/tmp,/dev/shm分区的安全<BR>/tmp,/var/tmp,/dev/shm目录是不安全的,任何用户都可以执行脚本。<BR>最好的解决办法是挂载ncexec和nosuid选项的参数<BR>注意:不建议在CPanel使用<BR>方法:<BR>/tmp目录:<BR>cd /dev<BR>创建 100M (“count”) 的存储文件:<BR>dd if=/dev/zero of=tmpMnt bs=1024 count=100000<BR>设为一个扩展的文件系统:<BR>
<DIV class=blockcode>
<DIV id=code_ITK>
<OL>
<LI>/sbin/mke2fs /dev/tmpMnt (“…is not a block special device. continue?”回答yes)</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>备份现有临时文件:<BR>
<DIV class=blockcode>
<DIV id=code_0Dy>
<OL>
<LI>cp -R /tmp/ /tmp_backup</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>用noexec挂载新文件系统:<BR>
<DIV class=blockcode>
<DIV id=code_hY9>
<OL>
<LI>mount -o loop,rw,nosuid,noexec /dev/tmpMnt /tmp</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV>
<DIV class=blockcode>
<DIV id=code_Q3c>
<OL>
<LI>chmod 0777 /tmp</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>把备份的文件拷贝回去:<BR>
<DIV class=blockcode>
<DIV id=code_5qo>
<OL>
<LI>cp -R /tmp_backup/* /tmp/</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>删除备份:<BR>
<DIV class=blockcode>
<DIV id=code_luU>
<OL>
<LI>rm -rf /tmp_backup</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR>修改/etc/fstab 添加下面的条目使其在引导时仍然有效<BR>
<DIV class=blockcode>
<DIV id=code_3ag>
<OL>
<LI>/dev/tmpMnt /tmp ext2 loop,rw,nosuid,noexec 0 0</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>/var/tmp目录:<BR>
<DIV class=blockcode>
<DIV id=code_t1l>
<OL>
<LI>mv /var/tmp /var/tmpbak<BR>
<LI>ln -s /tmp /var/tmp<BR>
<LI>cp /var/tmpbak/* /tmp/</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV><BR><BR>/dev/shm目录:<BR>编辑/etc/fstab<BR>把 none /dev/shm tmpfs defaults,rw 0 0<BR>改为
<DIV class=blockcode>
<DIV id=code_125>
<OL>
<LI>none /dev/shm tmpfs defaults,nosuid,noexec,rw 0 0</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV></TD></TR></TBODY></TABLE></P>
<P>&nbsp;</P>
<P><STRONG>账号安全管理:<BR></STRONG>1.限制使用su的用户并合理利用sudo:<BR>vi /etc/pam.d/su,添加auth required /lib/security/$ISA/pam_wheel.so group=wheel行,<BR>用命令“usermod -G 10 &lt;用户名&gt;”来添加允许使用su的用户<BR>合理利用sudo大家可以查看资料,也可以有人整理专题讨论。<BR><BR><BR>2.禁止root使用ssh远程登入:<BR>vi /etc/ssh/sshd_config,找到#PermitRootLogin yes 改成?&gt; PermitRootLogin no,重启ssh服务<BR><BR>3.给重要文件加锁,拒绝修改:<BR># chattr +i /etc/passwd<BR># chattr +i /etc/shadow<BR><BR>4.删除大部分不必要帐号,取消帐号中不必要的shell。<BR>如下帐号可被删除:<BR>adm,lp,sync,shutdown,halt,mail,news,uucp,operator,games,gopher,ftp,rpm,nscd,rpc,<BR>rpcuser,nfsnobody,mailnull,smmsp,pcap,xfs,ntp<BR>如果要使用KDE之类的图形窗口,则有些帐号如rpc,xfs是需要的。<BR><BR><BR><STRONG>文件系统权限</STRONG><BR>1) 找出系统中所有含s"位的程序,把不必要的"s"位去掉,或者把根本不用的直接删除,这样可以防止用户滥用及提升权限的可能性,其命令如下:<BR>&nbsp;&nbsp;find / -type f -perm -4000 -o -perm -2000 -print | xargs ls -lg<BR><BR>2) 把重要文件加上不可改变属性(一般情况不用这么做):<BR>&nbsp;&nbsp;chattr +i /etc/passwd<BR>&nbsp; &nbsp;Immutable,系统不允许对这个文件进行任何的修改。如果目录具有这个属性,那么任何的进程只能修改目录之下的文件,不允许建立和删除文件。<BR><BR>3) 找出系统中没有属主的文件:<BR>&nbsp;&nbsp;find / -nouser -o -nogroup<BR><BR>4) 找出任何都有写权限的文件和目录:<BR>&nbsp;&nbsp;find / -type f -perm -2 -o -perm -20 |xargs ls -lg<BR>&nbsp;&nbsp;find / -type d -perm -2 -o -perm -20 |xargs ls -ldg<BR><BR>5) Suid及sgid文件检查:<BR>执行如下命令:<BR>find / -user root -perm -4000 -print -exec md5sum {} \;<BR>find / -user root -perm -2000 -print -exec md5sum {} \;<BR>将结果重定向到一个文件,保存起来以后备查。<BR><BR><BR>Banner伪装<BR>1)系统banner<BR>2)各服WEB服务软件banner伪装及隐藏。<BR><BR><BR><STRONG>补充的比较乱,可能不对!我再总结一下:</STRONG><BR></P>
<DIV class=blockcode>
<DIV id=code_j2K>
<OL>
<LI>1.linux系统服务去掉和关闭不必要的服务。<BR>
<LI>2.删除一些没有用的账号<BR>
<LI>3.严格限制gcc及限制非root用户执行命令的权限及nc这些工具的权限。<BR>
<LI>3.将系统可执行命令的md5值保存下来方便以后查找问题。<BR>
<LI>4.机房安装系统后arp -an &gt; arp.mac&nbsp;&nbsp;将arp列表mac地址保存下来,方便遇到问题的时候查询。<BR>
<LI>5.关于PHP,WEB方面的安全,我想kindle版主将带我们一起**这方面的攻防讨论,他在这方面经验比较多。<BR>
<LI>&nbsp;&nbsp;</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV>
<P><BR><BR><BR><BR>群里补充:<BR>{杭州}NetKey(67212915)&nbsp;&nbsp;11:09:39<BR></P>
<DIV class=blockcode>
<DIV id=code_qXf>
<OL>
<LI>#!/bin/sh<BR>
<LI>for a in $(chkconfig --list |grep 0:|awk '{print $1}') ; do<BR>
<LI>&nbsp; &nbsp; case "$a" in<BR>
<LI>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;"sshd"&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;)&nbsp; &nbsp;&nbsp;&nbsp;STATUS=on;;<BR>
<LI>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;"crond"&nbsp; &nbsp;&nbsp; &nbsp; )&nbsp; &nbsp;&nbsp;&nbsp;STATUS=on;;<BR>
<LI>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;"network"&nbsp; &nbsp;&nbsp;&nbsp;)&nbsp; &nbsp;&nbsp;&nbsp;STATUS=on;;<BR>
<LI>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;"syslog"&nbsp; &nbsp;&nbsp; &nbsp;)&nbsp; &nbsp;&nbsp;&nbsp;STATUS=on;;<BR>
<LI>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;"iptables"&nbsp; &nbsp; )&nbsp; &nbsp;&nbsp;&nbsp;STATUS=on;;<BR>
<LI>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;"irqbalance"&nbsp;&nbsp;)&nbsp; &nbsp;&nbsp;&nbsp;STATUS=on;;<BR>
<LI>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;*&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; )&nbsp; &nbsp;&nbsp;&nbsp;STATUS=off;;<BR>
<LI>&nbsp; &nbsp; esac<BR>
<LI>&nbsp; &nbsp; /sbin/chkconfig --level 345 $a $STATUS<BR>
<LI>done</LI></OL></DIV><FONT color=#336699 size=2>复制代码</FONT></DIV>
<P><BR>&nbsp;</P>
<P>&nbsp;</P>
<P>来源 <A href="http://bbs.linuxtone.org/thread-6631-1-1.html">http://bbs.linuxtone.org/thread-6631-1-1.html</A>&nbsp;</P>
<P>&nbsp;</P>
页: [1]
查看完整版本: linux系统加固paper