CodeQL 文档

通过不安全连接下载敏感文件

ID: rb/insecure-download
Kind: path-problem
Security severity: 8.1
Severity: error
Precision: high
Tags:
   - security
   - external/cwe/cwe-829
Query suites:
   - ruby-code-scanning.qls
   - ruby-security-extended.qls
   - ruby-security-and-quality.qls

单击以在 CodeQL 仓库中查看查询

通过未加密连接下载可执行文件或其他敏感文件会导致服务器容易受到中间人攻击 (MITM)。这种攻击可以允许攻击者将任意内容插入到下载的文件中,在最坏情况下,允许攻击者在易受攻击的系统上执行任意代码。

建议

在下载可执行文件或其他敏感文件时使用安全的传输协议。

示例

在这个示例中,服务器从远程 URL 下载一个 shell 脚本,然后执行该脚本。

require "net/http"

script = Net::HTTP.new("http://mydownload.example.org").get("/myscript.sh").body
system(script)

HTTP 协议容易受到 MITM 攻击,因此攻击者可能会用任意代码替换下载的 shell 脚本,从而使攻击者完全控制系统。

下面的示例通过将 HTTP 协议替换为 HTTPS 协议来修复该问题。

require "net/http"

script = Net::HTTP.new("https://mydownload.example.org").get("/myscript.sh").body
system(script)

参考资料

  • ©GitHub, Inc.
  • 条款
  • 隐私