— web — 1 min read
服务器使用了系统默认的错误页面, 攻击者可以通过默认错误页面获取应用的版本信息、 从应用的错误信息中提取敏感信息等。
为应用自定义 40x、 50x 错误页面。
修改tomcat
的默认conf/web.xml
或应用的web.xml
文件, 添加如下内容:
1<error-page>2<error-code>403</error-code>3<location>/error.html</location>4</error-page>5<error-page>6<error-code>404</error-code>7<location>/error.html</location>8</error-page>9<error-page>10<error-code>500</error-code>11<location>/error.html</location>12</error-page>
1ErrorDocument 500 /errorhtml2ErrorDocument 404 /error.html3ErrorDocument 403 /error.html
在conf/nginx.conf
配置文件里增加server_tokens off;
作用域是http
,server
,location
语句块
通过页面自定义错误页面,这种只会去除html
页面版本信息,但是软件版本依旧可以通过探针获取到。可以在软件层面配置隐藏版本信息:
1#define NGINX_VERSION "1.12.0"2#define NGINX_VER "nginx/" NGINX_VERSION
去掉版本号并把nginx修改成大写(可以任意)
1#define NGINX_VERSION ""2#define NGINX_VER "NGINX/" NGINX_VERSION
1static char ngx_http_server_string[] = "Server: nginx" CRLF;
1static char ngx_http_server_string[] = "Server: NGINX" CRLF;
static u_char ngx_http_error_tail[] = 下的nginx信息(可以任意)
1static u_char ngx_http_error_tail[] =2"<hr><center>nginx</center>" CRLF3"</body>" CRLF4"</html>" CRLF5;
同样改成大写(可以任意)
1static u_char ngx_http_error_tail[] =2"<hr><center>NGINX</center>" CRLF3"</body>" CRLF4"</html>" CRLF5;
添加 server_tokens off; 参数的时候,调用的是 src/http/ngx_http_header_filter_module.c 里的值 不添加的时候,显示版本号调用的是 src/core/nginx.h 里的值
- 修改错误信息
- fastcgi_intercept_errors 配置方式 这是做正向代理的配置:
1# 定义错误页面码,如果出现相应的错误页面码,转发到那里。2fastcgi_intercept_errors on;3error_page 404 403 500 502 503 504 /404.html;45# 承接上面的location。67location = /404.html {89# 放错误页面的目录路径。1011root /usr/share/nginx/html;1213}
1proxy_intercept_errors on;2error_page 404 /404.html;34location = /404.html {56root /usr/share/nginx/html;78}
(完)