修复建议
应用程序应该返回名称为X-Frame-Options、值DENY以完全防止成帧的响应头,或者返回值SAMEORIGIN以允许仅通过与响应本身相同的来源上的页进行成帧,或者通过ALLOW-FROM origin设置白名单来限制允许加载的页面地址。
1)修改中间件配置:
a)IIS:
web.config 配置文件中添加如下响应头:
<add name="X-Frame-Options" value="SAMEORIGIN"/>
b)Apache:
Header always append X-Frame-Options SAMEORIGIN
c)Nginx:
add_header X-Frame-Options SAMEORIGIN;
使用meta标签
<meta http-equiv="X-Frame-Options" content="SAMEORIGIN" />
八、启用了不安全的HTTP方法
漏洞描述
Web服务器或应用服务器以不安全的方式进行配置,导致启用了WebDAV和不安全的HTTP方法,不安全的HTTP方法一般包括:TRACE、PUT、DELETE、COPY等,可能会造成攻击者在Web服务器上上传、修改或删除Web页面、脚本和文件的隐患。
修复建议
禁用WebDAV。禁止不需要的HTTP方法(建议只使用GET和POST方法)。
1)Apache:
使用Apache的重写规则来禁用Options方法和Trace方法。在Apache配置文件httpd-conf中【vhosts-conf】添加以下代码:
#单独禁用Trace方法:
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
单独禁用Options方法:
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(OPTIONS)
RewriteRule .* - [F]
同时禁用Trace方法和Options方法:
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK|OPTIONS)
RewriteRule .* - [F]<VirtualHost *:80>
DocumentRoot "D:\wwwroot"
ServerName www.abc.com
ServerAlias abc.com
<Directory "D:\wwwroot">
Options FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK|OPTIONS)
RewriteRule .* - [F]
</Directory></VirtualHost>
2)Nginx:
在server段里加入下面代码:
if ($request_method !~* GET|POST) {
return 403;
}
重启Nginx,就可以屏蔽GET、POST之外的HTTP方法。
3)Tomcat:
修改web.xml配置文件。
<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
<http-method>HEAD</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
</web-resource-collection>
<auth-constraint>
</auth-constraint>
</security-constraint>
4)IIS:
a)禁用WebDAV功能;
b)在web.config的【configuration】下添加如下代码:
<system.webServer> <security> <requestFiltering>
<verbs allowUnlisted="false">
<add verb="GET" allowed="true"/>
<add verb="POST" allowed="true"/>
</verbs>
</requestFiltering> </security></system.webServer>
九、"X-Powered-By"字段泄露服务器信息
漏洞描述
因Web服务器、应用服务器配置不安全,导致响应报文的响应头中"X-Powered-By"字段泄露服务器信息,攻击者可以通过获取服务器版本信息,收集相关漏洞,进行特定的攻击。
修复建议
隐藏响应头中"X-Powered-By"字段。
1)IIS:
修改web.config配置文件。
<configuration>
<location>
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
</system.webServer>
</location>
</configuration>
2)Nginx:
需要加上proxy_hide_header。
location / {
proxy_hide_header X-Powered-By;
}
3)WAS:
修改websphere相应配置,将com.ibm.ws.webcontainer.disabledxPoweredBy配置更改为true。
十、"Server"字段泄露服务器信息
漏洞描述
因Web服务器、应用服务器配置不安全,导致响应报文的响应头中"Server"字段泄露服务器信息,攻击者可以通过获取服务器版本信息,收集相关漏洞,进行特定的攻击。
修复建议
隐藏HTTP响应头中"Server"字段,在web.config添加以下配置:
<system.webServer>
<modules>
<add name="CustomHeaderModule" type="StrongNamespace.HttpModules.CustomHeaderModule" />
以上就是笔者在实际项目测试过程中经常遇见的十类常见应用配置型漏洞描述及针对常见中间件的修复建议,希望能够帮助开发同事快速理解各类漏洞并找到对应的修复方式!