BETA Shoulder jest w wersji beta — Wyniki mogą czasami być błędne. Twoja opinia kształtuje to, co naprawimy w następnej kolejności. Podziel się opinią
💻

Command Injection

Review child_process usage
🛡️ 3 reguł wykrywa to

Improper Neutralization of Special Elements used in an OS Command

User input is passed unsanitized to system shell commands, allowing attackers to execute arbitrary commands on the server.

Rozpowszechnienie
Common
Found in many applications
Wplyw
Critical
Full server compromise
Zapobieganie
Avoid shell
Use execFile, not exec
2 Zapobieganie
2 Zapobieganie

Jak naprawić tę podatność

Strategie zapobiegania dla OS Command Injection oparte na 3 regułach detekcji Shoulder.

Command Injection via os/exec CRITICAL

Use exec.Command with explicit arguments, never shell invocation

+14 -6 go
  package main
  
  import (
      "net/http"
      "os/exec"
- )
- 
- func handler(w http.ResponseWriter, r *http.Request) {
-     cmd := r.URL.Query().Get("cmd")
-     // Vulnerable: shell invocation with user input
-     output, _ := exec.Command("sh", "-c", cmd).Output()
+     "regexp"
+ )
+ 
+ var safePattern = regexp.MustCompile(`^[a-zA-Z0-9._-]+$`)
+ 
+ func handler(w http.ResponseWriter, r *http.Request) {
+     filename := r.URL.Query().Get("file")
+     // Validate input
+     if !safePattern.MatchString(filename) {
+         http.Error(w, "Invalid filename", http.StatusBadRequest)
+         return
+     }
+     // Safe: explicit command with validated argument
+     output, _ := exec.Command("cat", filename).Output()
      w.Write(output)
  }
  
Command Injection via child_process CRITICAL

Use execFile/spawn with array arguments instead of exec with string commands

+5 -5 javascript
- const { exec } = require('child_process');
- 
- app.get('/convert', (req, res) => {
-   const filename = req.query.file;
-   exec(`convert ${filename} output.png`, (err, stdout) => {
+ const { execFile } = require('child_process');
+ 
+ app.get('/convert', (req, res) => {
+   const filename = req.query.file;
+   execFile('convert', [filename, 'output.png'], (err, stdout) => {
      res.send('Converted');
    });
  });
  
OS Command Injection CRITICAL

Use subprocess.run with list arguments and shell=False

+1 -1 python
  import subprocess
  from flask import request
  
  @app.route('/convert')
  def convert():
      filename = request.args.get('file')
-     subprocess.run(f'convert {filename} output.png', shell=True)
+     subprocess.run(['convert', filename, 'output.png'], check=True)
      return 'Done'
  
3 Wykrywanie
3 Wykrywanie

Znajdz podatnosci w swoim kodzie

Uzyj Shoulder do skanowania kodu w poszukiwaniu wzorcow Command Injection. 3 reguly.

terminal
# Scan with Shoulder CLI
npx @shoulderdev/cli trust --cwe=78

# Or scan entire project
npx @shoulderdev/cli trust .
4 Sygnaly Ostrzegawcze
4 Sygnaly Ostrzegawcze

Na co zwracac uwage podczas przegladu kodu

Te wzorce wskazuja na potencjalne podatnosci Command Injection. Szukaj ich podczas przegladow kodu i audytow bezpieczenstwa.

🔴
user input flowing to os/exec command execution, enabling OS command injection go-command-injection
🔴
user input flowing to shell command execution functions javascript-command-injection
🔴
untrusted user input flowing into operating system command execution functions without proper saniti python-command-injection
5 Audyt kodu
5 Audyt kodu

Wzorce do ręcznego przeglądu

Podczas ręcznego przeglądu kodu szukaj tych niebezpiecznych wzorców.

Sygnały ostrzegawcze, których szukać
query = + konkatenacja łańcuchów
execute(f"... or execute("..." +
raw_query, rawQuery, executeRaw
${ or #{ wewnątrz łańcuchów SQL
6 Analiza eksperta
6 Analiza eksperta

Jak myślą eksperci ds. bezpieczeństwa

Model myślowy, którego specjaliści ds. bezpieczeństwa używają podczas przeglądu tej podatności.

1

Zmapuj punkty wejścia

Parametry URL, ciała POST, nagłówki, cookies, przesyłanie plików.

2

Śledź przepływ danych

Śledź wejście przez kod. Czy jest sanitizowane?

3

Zidentyfikuj punkty końcowe (sinks)

Where queries are executed: execute(), query()

4

Sprawdź granice zaufania

Uważaj na przechowywane dane używane w zapytaniach.

🔍

Przeskanuj swój kod w poszukiwaniu Command Injection

Shoulder CLI znajduje podatne wzorce w całym Twoim kodzie.