AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 696551
Accepted
jamboNum5
jamboNum5
Asked: 2015-06-05 01:06:22 +0800 CST2015-06-05 01:06:22 +0800 CST 2015-06-05 01:06:22 +0800 CST

如何检查服务器令牌是否关闭?

  • 772

我们从渗透测试报告中得到反馈,说我们应该关闭服务器令牌。这会阻止人们看到我们正在使用的 PHP 版本,并限制他们针对特定 PHP 版本的能力。

我在 nginx.conf 的 http 块下添加了以下内容:

server_tokens off;

但是我可以使用哪些工具来检查此更改是否已生效?

nginx
  • 4 4 个回答
  • 33386 Views

4 个回答

  • Voted
  1. HBruijn
    2015-06-05T01:21:37+08:002015-06-05T01:21:37+08:00

    从手册中您知道设置的作用:

    语法: server_tokens on | off;
    默认值: server_tokens on;
    上下文:http、服务器、位置

    启用或禁用在错误消息和“服务器”响应头字段中发出 nginx 版本。

    所以你的选择是:

    • 生成错误消息,例如,如果您没有自定义 404 错误消息,只需请求一个不存在的页面,并且在页脚中您将不会再看到版本信息nginx/1.2.3。
    • 检查服务器标头并确认不再显示该版本。

    查看 HTTP 响应标头的简单检查是手动连接,即:telnet www.example.com 80 客户端行是您输入的内容:

    客户端:HEAD / HTTP/1.1
    客户端:主机:www.example.com

    服务器:HTTP/1.1 200 OK
    服务器:日期:1970 年 1 月 1 日星期三 22:13:05 GMT
    服务器:服务器:Nginx/1.2.3
    服务器:连接:关闭
    服务器:内容类型:文本/html

    • 17
  2. Best Answer
    jamboNum5
    2015-06-05T02:55:29+08:002015-06-05T02:55:29+08:00

    经过一番谷歌搜索,我发现 curl 命令可以检查显示服务器令牌和 php 版本的服务器标头:

    curl -I -L www.example.com
    

    感谢 Alexey 指出 PHP 所需的更改。

    HTTP/1.1 301 Moved Permanently
    Server: nginx
    Date: Thu, 04 Jun 2015 10:49:35 GMT
    Content-Type: text/html
    Content-Length: 178
    Connection: keep-alive
    Location: https://www.example.com
    
    HTTP/1.1 200 OK
    Server: nginx
    Date: Thu, 04 Jun 2015 10:49:36 GMT
    Content-Type: text/html; charset=utf-8
    Connection: keep-alive
    Expires: Sun, 19 Nov 1978 05:00:00 GMT
    Last-Modified: Thu, 04 Jun 2015 10:49:35 GMT
    Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0
    ETag: "1433414975"
    Content-Language: en
    
    • 7
  3. Alexander Br.
    2020-02-06T13:06:26+08:002020-02-06T13:06:26+08:00

    此外,如果您服务于 PHP 项目,您可能需要更改/etc/nginx/{fastcgi,fastcgi_params).conf

    fastcgi_param  SERVER_SOFTWARE    nginx;
    
    • 3
  4. james.garriss
    2018-09-06T10:20:33+08:002018-09-06T10:20:33+08:00

    看看 InSpec,它是一个允许您“将合规性、安全性和其他策略要求转化为自动化测试”的工具。

    https://www.inspec.io

    它可以为您的 Nginx 服务器进行所有需要的配置测试。这是测试 conf 文件是否存在以及 的值的一种方法server_tokens:

    conf_path = '/etc/nginx/nginx.conf'
    
    control 'Server tokens should be off' do
      describe file(conf_path) do
        it 'The config file should exist and be a file.' do
          expect(subject).to(exist)
          expect(subject).to(be_file)
        end
      end
      if (File.exist?(conf_path))
        Array(nginx_conf(conf_path).params['http']).each do |http|
          describe "http:" do
            it 'server_tokens should be off if found in the http context.' do
              Array(http["server_tokens"]).each do |tokens|
                expect(tokens).to(cmp 'off')
              end
            end
          end
        end
      end
    end
    

    如果设置正确,InSpec 将返回:

      ✔  Server tokens should be off: File /etc/nginx/nginx.conf
         ✔  File /etc/nginx/nginx.conf The config file should exist and be a file.
         ✔  http: server_tokens should be off if found in the http context.
    

    如果不:

      ×  Server tokens should be off: File /etc/nginx/nginx.conf (1 failed)
         ✔  File /etc/nginx/nginx.conf The config file should exist and be a file.
         ×  http: server_tokens should be off if found in the http context.
    
         expected: "off"
              got: ["on"]
    
         (compared using `cmp` matcher)
    
    • 0

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve