logo

Database

Go Os Exec Command Injection

Description

Detects command injection vulnerabilities in Go applications where user-controlled input is passed unsafely to system commands through the os/exec package. This could allow attackers to execute arbitrary system commands by injecting malicious shell metacharacters into the command arguments.

Weakness:

404 - OS Command Injection

Category: Functionality Abuse

Detection Strategy

    Checks if the os/exec package is imported in the Go source code

    Identifies calls to exec.Command function in the code

    Analyzes if any user-controlled/untrusted input flows into the exec.Command parameters

    Reports a vulnerability if untrusted input can reach the command execution without proper sanitization

Vulnerable code example

package main

import (
    "net/http"
    "os/exec"
)

func vulnerableHandler(w http.ResponseWriter, r *http.Request) {...

✅ Secure code example

package main

import (
    "net/http"
    "os/exec"
    "regexp"
)
...