0x01 linux 基线安全

1 Linux系统端口加固

    以root权限登录到Linux操作系统,首先运行“setup”命令,选择“Firewallconfiguration”,在“Security Level”里,选择“(*) Enabled”启用操作系统防火墙。

案例1:如果需要开放特定的服务,如需要开放mysql服务给任意主机使用,则编辑iptables配置文件,设置开放哪些对外服务。

#vi/etc/sysconfig/iptables

加入一行:

-ARH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

其中3306为需要对外开放的服务端口。

继而重启IPTABLES服务即可。

#service iptablesrestart

案例2:如果需要开放特定的服务,如需要开放mysql服务给特定的一台主机,如192.168.100.5使用,则可以:

#vi/etc/sysconfig/iptables

加入一行:

-ARH-Firewall-1-INPUT -m state --state NEW -m tcp -s 192.168.100.5 -p tcp --dport3306 -j ACCEPT

其中3306为需要对外开放的服务端口。

继而重启IPTABLES服务即可。

#service iptablesrestart

2  Linux网页文件权限调整。

可根据实际情况,调整需要修改的文件权限。如,需要把 /var/www目录下所有文件的权限全部改为 644,则可以输入

find /var/www-type f |xargs chmod 644

需要把所有 777 权限的目录调整为700,则可以输入:

find /var/www-type d -perm 777 |xargs chmod 700

需要把所有 php 文件的权限调整为600,则可以输入:

find . -name"*.php" -type f |xargs chmod 600

3  安全加固和检查

A  去除目录的浏览、包含等指令

方法:用文本编辑器打开Apache配置文件httpd.conf,搜索是否存在Indexes或者+Indexes字样,如有应去除,改为-Indexes,如下:

<Directory/usr/local/apache/htdocs/>

Order allow,deny

Allow from all

Options  -Includes -Indexs Multiviews

</Directory>

0X02 POST方法

1 POST 方法

用文本编辑器打开Apache配置文件httpd.conf,增加以下配置

<Directory /usr/local/apache/htdocs/>

<LimitExcept GET POST>

deny from all

</LimitExcept>

Order allow,deny

Allow from all

Options –Includes –Indexs –Multiviews

</Directory>

 

限制不能使用TRACE、TRACK、OPTIONS等方法,方法:用文本编辑器打开Apache配置文件httpd.conf,增加以下配置

 

RewriteEngine On

RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK|OPTIONS)

RewriteRule .* - [F]

 

如果有多个虚拟主机,需要在每个主机都要加入以上配置。

2 运行用户和组

方法:用文本编辑器检查httpd.conf,查看User和Group指令对应的用户名和组别名称。这个用户在/etc/passwd列表里,应该为/sbin/nologin 的运行环境,而不应该有类似这样的运行环境:/bin/bash

#如在httpd.conf里用户和组别为

User nobody

Group nobody

#在/etc/passwd里为

nobody:x:99:99:Nobody:/:/sbin/nologin

3 服务器帐号

如Linux,设置web服务器

passwd -lwebserv
usemod -s /bin/nolo httpuser

#编辑httpd.conf配置文件,把以下几个指令如下设置:

ServerSignatureOff

ServerTokensProd

4 错误提示页面

应该定义自己的错误页面,避免由于运行出错时泄露敏感信息

ErrorDocument         401           /custom401.html

ErrorDocument         404           /custom404.html

ErrorDocument         500           /custom500.html

5 扩展名,如.php.gif

<Files ~"^\w+\.(gif|jpe?g|png|avi)$">
order deny,allow
allow from all
</Files>

6 不允许访问/WEB-INF/目录

      如果Apache后台有使用Tomcat、WebSphere、WebLogic、Resin等应用服务器,应该加上禁止通过Apache访问/WEB-INF目录的限制,以免由于Apache应用服务连接器的设置漏洞,导致的配置文件信息泄露。

方法:编辑httpd.conf文件,加入:

LoadModulerewrite_module modules/mod_rewrite.so
RewriteEngine on
RewriteRule /WEB-INF

欢迎大家分享更好的思路,热切期待^^_^^ !

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:1 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐