Apache安全配置参考

date: 2017-01-03 13:30:12

0X01 账号
以专门的非root用户账号和组运行Apache。
操作: 根据需要为Apache创建用户、组。
参考配置操作:
修改httpd.conf配置文件,添加如下语句:
User apache
Group apachegroup
其中apache、apachegroup分别是为Apache创建的用户和组。
检测:检查httpd.conf配置文件,检查用户配置文件。
补充说明:

  1. 根据不同用户,取不同的名称。
  2. 为用户设置适当的家目录和shell。
    0x02 授权
    禁止Apache访问Web目录之外的任何文件。
    操作:
    编辑httpd.conf配置文件,

    Order Deny,Allow
    Deny from all

    检测:访问服务器上不属于Web目录的一个文件,结果应无法显示。
    判定:无法访问Web目录之外的文件。
    补充说明:
    设置可访问目录,
    <Directory /web>
    Order Allow,Deny
    Allow from all

    其中/web为网站根目录。
    0x03 日志
    设备应配置日志功能,对用户登录进行记录,记录内容包括用户登录使用的账号,登录是否成功,登录时间,以及远程登录时,用户使用的IP地址。
    操作:
    编辑httpd.conf配置文件,设置日志记录文件、记录内容、记录格式。
    LogLevel notice
    ErrorLog logs/error_log
    LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Accept}i\” \”%{Referer}i\” \”%{User-Agent}i\”” combined
    CustomLog logs/access_log combined
    ErrorLog指令设置错误日志文件名和位置。错误日志是最重要的日志文件,Apache httpd将在这个文件中存放诊断信息和处理请求中出现的错误。若要将错误日志送到Syslog,则设置:ErrorLog syslog。
    CustomLog指令设置访问日志的文件名和位置。访问日志中会记录服务器所处理的所有请求。
    LogFormat设置日志格式。LogLevel用于调整记录在错误日志中的信息的详细程度,建议设置为notice。
    检测:查看相关日志记录。
    判定:查看logs目录中相关日志文件内容,记录完整。
    0x04 其它
    1 Apache错误页面重定向
    操作:
  3. 修改httpd.conf配置文件:
    ErrorDocument 400 /custom400.html
    ErrorDocument 401 /custom401.html
    ErrorDocument 403 /custom403.html
    ErrorDocument 404 /custom404.html
    ErrorDocument 405 /custom405.html
    ErrorDocument 500 /custom500.html
    Customxxx.html为要设置的错误页面。
  4. 重启Apache服务
    检测方法:URL地址栏中输入http://ip/xxxxxxx~~~(一个不存在的页面)
    判定:指向指定错误页面。
    2 禁止列目录
    操作:
  5. 编辑httpd.conf配置文件,

    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all

    将Options Indexes FollowSymLinks中的Indexes 去掉,就可以禁止 Apache 显示该目录结构。Indexes 的作用就是当该目录下没有 index.html文件时,就显示目录结构。
    2.设置Apache的默认页面,编辑%apache%\conf\httpd.conf配置文件,

    DirectoryIndex index.html

    其中index.html即为默认页面,可根据情况改为其它文件。
  6. 重启Apache服务
    检测:直接访问http://ip:8800/xxx(xxx为某一目录)
    判定:当WEB目录中没有默认首页如index.html文件时,不会列出目录内容。
    3 拒绝服务
    操作:
  7. 编辑httpd.conf配置文件,
    Timeout 10 KeepAlive On
    KeepAliveTimeout 15
    AcceptFilter http data
    AcceptFilter https data
  8. 重启Apache服务
    检测方法:
  9. 检查配置文件是否设置。
    4 删除无用文件
    操作:
  10. 删除缺省HTML文件:

    rm -rf /usr/local/apache2/htdocs/*

    删除缺省的CGI脚本:

    rm –rf /usr/local/apache2/cgi-bin/*

    删除Apache说明文件:

    rm –rf /usr/local/apache2/manual

    删除源代码文件:

    rm -rf /path/to/httpd-2.2.4*

    根据安装步骤不同和版本不同,某些目录或文件可能不存在或位置不同。
    检测:检查对应目录。
    5 隐藏版本信息
    操作:
  11. 编修改httpd.conf配置文件:
      ServerSignature Off
      ServerTokens Prod
    检测:检查配置文件。
    判定:存在ServerSignature Off

参考链接:http://blog.csdn.net/qq_29277155/article/details/52915206