बीटा Shoulder बीटा में है — परिणाम कभी-कभी गलत हो सकते हैं। आपकी प्रतिक्रिया तय करती है कि हम आगे क्या ठीक करें। प्रतिक्रिया साझा करें
💻

Command Injection

Review child_process usage
🛡️ 3 नियम इसे पहचानते हैं

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.

व्यापकता
Common
Found in many applications
प्रभाव
Critical
Full server compromise
रोकथाम
Avoid shell
Use execFile, not exec
2 रोकथाम
2 रोकथाम

इस भेद्यता को कैसे ठीक करें

3 Shoulder डिटेक्शन नियमों पर आधारित OS Command Injection के लिए रोकथाम रणनीतियाँ।

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 पहचान
3 पहचान

अपने कोड में भेद्यताएँ खोजें

Command Injection पैटर्न के लिए अपने कोडबेस को स्कैन करने के लिए Shoulder का उपयोग करें। 3 नियम.

टर्मिनल
# Scan with Shoulder CLI
npx @shoulderdev/cli trust --cwe=78

# Or scan entire project
npx @shoulderdev/cli trust .
4 चेतावनी संकेत
4 चेतावनी संकेत

कोड समीक्षा में किन बातों पर ध्यान दें

ये पैटर्न संभावित Command Injection भेद्यताओं का संकेत देते हैं। कोड समीक्षा और सुरक्षा ऑडिट के दौरान इन्हें देखें।

🔴
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 कोड ऑडिट
5 कोड ऑडिट

मैनुअल समीक्षा पैटर्न

मैन्युअल रूप से कोड की समीक्षा करते समय, इन खतरनाक पैटर्न को खोजें।

खोजने के लिए चेतावनी संकेत
query = + स्ट्रिंग कॉन्कैटनेशन
execute(f"... or execute("..." +
raw_query, rawQuery, executeRaw
${ or #{ SQL स्ट्रिंग्स के अंदर
6 विशेषज्ञ विश्लेषण
6 विशेषज्ञ विश्लेषण

सुरक्षा विशेषज्ञ कैसे सोचते हैं

इस भेद्यता की समीक्षा करते समय सुरक्षा पेशेवर जिस मानसिक मॉडल का उपयोग करते हैं।

1

एंट्री पॉइंट्स मैप करें

URL पैरामीटर, POST बॉडी, हेडर, कुकीज़, फ़ाइल अपलोड।

2

डेटा प्रवाह को ट्रेस करें

इनपुट को कोड के माध्यम से ट्रैक करें। क्या इसे सैनिटाइज़ किया जाता है?

3

सिंक्स की पहचान करें

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

4

विश्वास सीमाओं की जाँच करें

क्वेरीज़ में उपयोग किए गए संग्रहीत डेटा पर ध्यान दें।

🔍

अपने कोडबेस को इसके लिए स्कैन करें: Command Injection

Shoulder CLI आपके पूरे कोडबेस में भेद्य पैटर्न खोजता है।