# Command Injection (CWE-78) User input is passed unsanitized to system shell commands, allowing attackers to execute arbitrary commands on the server. **Stack:** JavaScript - Prevalence: Common Found in many applications - Impact: Critical Full server compromise - Prevention: Avoid shell Use execFile, not exec **OWASP:** Injection (A03:2021-Injection) - #3 ## Description This could allow attackers to execute unexpected, dangerous commands directly on the operating system. This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system. ## Prevention 1개의 Shoulder 탐지 규칙을 기반으로 한 OS Command Injection 예방 전략. ### JavaScript Use execFile/spawn with array arguments instead of exec with string commands ## Warning Signs - [CRITICAL] user input flowing to shell command execution functions ## Consequences - 승인되지 않은 명령 실행 - 애플리케이션 데이터 읽기 - 보호 메커니즘 우회 ## Mitigations - 외부 프로세스 대신 라이브러리 호출을 사용하세요 - Runtime.exec()를 사용한다면 인수 배열을 받는 버전을 사용하세요 - 데이터와 코드의 분리를 자동으로 강제하는 구조화된 메커니즘을 사용하세요 ## Detection - Total rules: 3 - Critical: 3 - Languages: go, javascript, typescript, python ## Rules by Language ### Javascript (1 rules) - **Command Injection via child_process** [CRITICAL]: Detects user input flowing to shell command execution functions. - Remediation: Use execFile() with argument arrays instead of exec() with string commands. ```javascript const { execFile } = require('child_process'); execFile('ls', ['-la', directory]); ``` Learn more: https://shoulder.dev/learn/javascript/cwe-78/command-injection ### Typescript (1 rules) - **Command Injection via child_process** [CRITICAL]: Detects user input flowing to shell command execution functions. - Remediation: Use execFile() with argument arrays instead of exec() with string commands. ```javascript const { execFile } = require('child_process'); execFile('ls', ['-la', directory]); ``` Learn more: https://shoulder.dev/learn/javascript/cwe-78/command-injection