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.
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"
)
...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.