OS Command Injection (ARCH5102)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key go.security.os-command-injection · Severity error · Category security · CWE CWE-78
Concatenating untrusted input into a command string and running it through a shell (sh -c) lets an attacker execute arbitrary commands. Input must be passed as an argument, not to a shell.
Incorrect
Section titled “Incorrect”cmd := exec.Command("sh", "-c", "ping -c 1 "+r.FormValue("host"))out, _ := cmd.Output()Correct
Section titled “Correct”host := r.FormValue("host")cmd := exec.Command("ping", "-c", "1", host) // no shell, separate argout, _ := cmd.Output()Run the command without a shell and pass user input as a separate argument instead of a concatenated string.