Skip to content

tanviet12/vbsec / skills/antigravity/vbs-scan-security

vbs-scan-security

Flagged

Use when scanning code for security vulnerabilities. Use when user says "scan security", "kiểm tra bảo mật", "security audit", "review security", or invokes `/vbs-scan-security`. For large scans (>20 main-language files OR >30 total OR >14 days) processes chunks sequentially. Outputs bilingual reports (vi/en). Optional `--auto-fix` (agentic patch + verify loop) and `--sca` (live CVE lookup via OSV.dev).

FileKindSize
SKILL.mdskill md28.2 KB
VERSIONother6 B
references/chunking-strategy.mdmarkdown7.2 KB
references/data-flow-classification.mdmarkdown9.5 KB
references/dependency-scan.mdmarkdown9.7 KB
references/i18n/en.mdmarkdown8.7 KB
references/i18n/vi.mdmarkdown9.4 KB
references/language-detection.mdmarkdown7.5 KB
references/load-rules.shexecutablescript5.2 KB
references/output-format.mdmarkdown26.1 KB
references/project-context.mdmarkdown2.7 KB
references/sub-agent-prompts.mdmarkdown16.5 KB
references/validate-report.pyexecutablescript8.7 KB
rules/generic/01-hardcoded-secret.mdmarkdown5.4 KB
rules/generic/02-sql-injection.mdmarkdown5.2 KB
rules/generic/03-xss.mdmarkdown4.9 KB
rules/generic/04-idor.mdmarkdown5.7 KB
rules/generic/05-slopsquatting.mdmarkdown6.1 KB
rules/generic/06-brute-force.mdmarkdown6.9 KB
rules/generic/07-mass-assignment.mdmarkdown6.3 KB
rules/generic/08-insecure-deserialization.mdmarkdown6.3 KB
rules/generic/09-ssrf.mdmarkdown6.7 KB
rules/generic/10-path-traversal.mdmarkdown6.3 KB
rules/generic/11-csrf.mdmarkdown7.8 KB
rules/generic/12-broken-access-control.mdmarkdown7.9 KB
rules/generic/13-weak-password-hashing.mdmarkdown5.2 KB
rules/generic/14-jwt-none-algorithm.mdmarkdown5.3 KB
rules/generic/15-cors-misconfig.mdmarkdown5.3 KB
rules/generic/16-unrestricted-file-upload.mdmarkdown5.9 KB
rules/generic/17-verbose-error-debug-mode.mdmarkdown5.8 KB
rules/generic/18-missing-rate-limit.mdmarkdown10.7 KB
rules/generic/19-race-condition.mdmarkdown11.5 KB
rules/generic/20-outdated-dependency.mdmarkdown7.2 KB
rules/generic/21-command-injection.mdmarkdown6.6 KB
rules/generic/22-vulnerable-dependency.mdmarkdown5.3 KB
rules/generic/23-llm-prompt-injection.mdmarkdown9.7 KB
rules/generic/24-excessive-agency.mdmarkdown10.1 KB
rules/generic/25-tenant-isolation.mdmarkdown10.1 KB
rules/generic/26-authz-path-parity.mdmarkdown10.9 KB
rules/generic/27-excessive-data-exposure.mdmarkdown10.4 KB
rules/generic/28-business-state-integrity.mdmarkdown9.5 KB
rules/generic/29-sensitive-data-in-logs.mdmarkdown9.1 KB
rules/generic/30-auth-session-lifecycle.mdmarkdown9.4 KB
rules/generic/31-resource-exhaustion.mdmarkdown9.0 KB
rules/languages/README.mdmarkdown8.5 KB
rules/languages/dart/01-hardcoded-secret.mdmarkdown7.9 KB
rules/languages/dart/03-xss.mdmarkdown5.2 KB
rules/languages/dart/05-slopsquatting.mdmarkdown4.6 KB
rules/languages/dart/10-path-traversal.mdmarkdown6.3 KB
rules/languages/dart/12-broken-access-control.mdmarkdown8.3 KB
rules/languages/dart/17-verbose-error-debug-mode.mdmarkdown6.7 KB
rules/languages/dart/20-outdated-dependency.mdmarkdown4.7 KB
rules/languages/dart/README.mdmarkdown3.7 KB
rules/languages/dotnet/02-sql-injection.mdmarkdown5.7 KB
rules/languages/dotnet/07-mass-assignment.mdmarkdown6.0 KB
rules/languages/dotnet/08-insecure-deserialization.mdmarkdown5.7 KB
rules/languages/dotnet/17-verbose-error-debug-mode.mdmarkdown5.0 KB
rules/languages/dotnet/21-command-injection.mdmarkdown5.3 KB
rules/languages/dotnet/README.mdmarkdown1.7 KB
rules/languages/go/02-sql-injection.mdmarkdown5.2 KB
rules/languages/go/08-insecure-deserialization.mdmarkdown5.0 KB
rules/languages/go/09-ssrf.mdmarkdown5.8 KB
rules/languages/go/17-verbose-error-debug-mode.mdmarkdown6.1 KB
rules/languages/go/21-command-injection.mdmarkdown5.2 KB
rules/languages/go/README.mdmarkdown2.7 KB
rules/languages/php/02-sql-injection.mdmarkdown5.8 KB
rules/languages/php/08-insecure-deserialization.mdmarkdown6.2 KB
rules/languages/php/11-csrf.mdmarkdown6.2 KB
rules/languages/php/17-verbose-error-debug-mode.mdmarkdown6.5 KB
rules/languages/php/21-command-injection.mdmarkdown6.7 KB
rules/languages/php/README.mdmarkdown2.9 KB
rules/languages/python/02-sql-injection.mdmarkdown7.2 KB
rules/languages/python/07-mass-assignment.mdmarkdown7.3 KB
rules/languages/python/08-insecure-deserialization.mdmarkdown7.3 KB
rules/languages/python/09-ssrf.mdmarkdown7.5 KB
rules/languages/python/11-csrf.mdmarkdown7.6 KB
rules/languages/python/14-jwt-none-algorithm.mdmarkdown7.5 KB
rules/languages/python/15-cors-misconfig.mdmarkdown8.0 KB
rules/languages/python/17-verbose-error-debug-mode.mdmarkdown8.4 KB
rules/languages/python/21-command-injection.mdmarkdown8.5 KB
rules/languages/python/README.mdmarkdown3.4 KB
rules/languages/typescript/02-sql-injection.mdmarkdown7.5 KB
rules/languages/typescript/03-xss.mdmarkdown6.7 KB
rules/languages/typescript/07-mass-assignment.mdmarkdown7.4 KB
rules/languages/typescript/08-insecure-deserialization.mdmarkdown7.0 KB
rules/languages/typescript/09-ssrf.mdmarkdown7.5 KB
rules/languages/typescript/11-csrf.mdmarkdown7.3 KB
rules/languages/typescript/14-jwt-none-algorithm.mdmarkdown7.0 KB
rules/languages/typescript/15-cors-misconfig.mdmarkdown7.2 KB
rules/languages/typescript/17-verbose-error-debug-mode.mdmarkdown7.2 KB
rules/languages/typescript/21-command-injection.mdmarkdown6.7 KB
rules/languages/typescript/README.mdmarkdown3.3 KB
workflows/auto-fix.mdmarkdown18.9 KB
workflows/large-review-sequential.mdmarkdown14.8 KB
workflows/small-review.mdmarkdown10.1 KB

rules/languages/php/21-command-injection.md

View on GitHub
---
id: COMMAND-INJECTION
severity_max: CRITICAL
applies_to: php
---

# Command Injection (PHP)

## Intent

PHP có **6 nhóm function exec shell**:
- `system($cmd)` — chạy + echo output
- `exec($cmd, $output, $code)` — chạy, output vào array
- `shell_exec($cmd)` — chạy, return output string
- `passthru($cmd)` — chạy, binary output thẳng vào response
- Backticks `` `$cmd` `` — alias `shell_exec`
- `popen($cmd, $mode)`, `proc_open($cmd, ...)`

**Tất cả** đều spawn shell `/bin/sh -c $cmd` mặc định → string `$cmd` bị shell parse → attacker chèn `;`, `|`, `&&`, `$()`, backtick → RCE.

PHP vibe code đặc biệt dính vì:
- ImageMagick wrapper: `system("convert " . $_GET['file'] . " out.jpg")`
- FFmpeg: `shell_exec("ffmpeg -i $input output.mp4")`
- Git command: `exec("git clone $repo")`
- Ping check: `shell_exec("ping -c 1 $host")`

`escapeshellarg()` / `escapeshellcmd()` help nhưng **vẫn có bypass** (option injection: `-o ProxyCommand=...` cho ssh, `-f` for find).

## Khi nào CRITICAL

- L1 input ghép vào string truyền `system`/`exec`/`shell_exec`/`passthru`/backticks
- Không có escape hoặc whitelist
- Web server chạy với quyền `www-data` có thể đọc file app + DB credential

## Khi nào HIGH

- Có `escapeshellarg()` quanh biến NHƯNG vẫn dùng `system(...)` — chống basic injection NHƯNG nếu command nhận option (`-o`, `-f`, `--`) thì attacker vẫn chèn argument: `escapeshellarg("--upload-pack=/bin/sh")` vẫn nguy hiểm với `git clone`
- `escapeshellcmd()` toàn câu — escape metachar nhưng KHÔNG escape option, vẫn argument injection

## Khi nào MEDIUM

- Whitelist regex chặt (`^[a-zA-Z0-9._-]+$`) + escapeshellarg — chống cả command + argument injection
- Endpoint chỉ admin với re-auth

## Cách reasoning (KHÔNG pattern-match thuần)

1. **Grep** sinks: `system\s*\(`, `exec\s*\(`, `shell_exec`, `passthru`, `popen`, `proc_open`, backtick literal
2. **Read** call site:
   - Argument có chứa biến từ L1?
   - Có `escapeshellarg` / `escapeshellcmd`?
   - Lưu ý: `escapeshellarg($x)` trả về `'$x'` (quoted) — chống command injection cơ bản, nhưng nếu $x bắt đầu bằng `-` thì shell treat như option của command tiếp theo
3. **Trace L1**: `$_GET`, `$_POST`, `$_FILES['x']['name']` (cực untrusted), Laravel `$request->input`, `Request::file()->getClientOriginalName()`
4. **Verify**:
   - Có whitelist regex?
   - Có `proc_open` với array args (PHP 7.4+ `proc_open(['cmd','arg'], ...)` không qua shell) — safer pattern
   - Có dùng dedicated PHP library thay vì exec? (vd: `Intervention/Image` thay vì `convert` CLI)

## Search patterns (PHP-specific)

```
# Direct sinks
system\s*\(
exec\s*\(
shell_exec\s*\(
passthru\s*\(
popen\s*\(
proc_open\s*\(
pcntl_exec\s*\(

# Backtick — khó grep nhưng có thể tìm
=\s*`[^`]*\$\w+

# Sprintf-style build
sprintf\s*\([^,]+,\s*\$_(GET|POST|FILES)

# Common patterns
"\s*\$_(GET|POST|REQUEST)\[[^\]]+\]\s*"     # superglobal in shell string
".*"\s*\.\s*\$_(GET|POST|REQUEST)

# Filename from upload
\$_FILES\[[^\]]+\]\['name'\]
->getClientOriginalName\s*\(

# Laravel
shell_exec\s*\(.*request\(\)
Process::run\s*\(                            # Symfony Process — safer if array args
```

## Examples

### CRITICAL — flag

```php
<?php
// ImageMagick wrapper
$file = $_GET['file'];
system("convert " . $file . " /tmp/out.jpg");
// ?file=x.jpg;cat /etc/passwd → RCE
```

```php
<?php
// Ping check
$host = $_POST['host'];
echo shell_exec("ping -c 1 " . $host);
// host=8.8.8.8;id → output append id
```

```php
<?php
// Backtick
$repo = $_GET['repo'];
$output = `git clone $repo /tmp/repo`;
// repo=x.git;rm -rf /
```

```php
// Laravel — file upload + ffmpeg
$file = $request->file('video');
$name = $file->getClientOriginalName();  // attacker control name
$path = $file->store('videos');
shell_exec("ffmpeg -i {$path} out.mp4");
// Filename: "; rm -rf /tmp; #.mp4" → RCE
```

```php
<?php
// escapeshellarg nhưng vẫn argument injection
$file = escapeshellarg($_GET['file']);
system("convert $file out.jpg");
// ?file=-version → convert nhận -version → tùy command, có thể leak
// Với git clone: ?repo=--upload-pack=/tmp/x.sh → RCE
```

### NOT critical — safer

```php
<?php
// Whitelist + escapeshellarg
$file = $_GET['file'];
if (!preg_match('/^[a-zA-Z0-9._-]+$/', $file)) {
    http_response_code(400);
    die('bad filename');
}
$safe = escapeshellarg('/uploads/' . $file);
system("convert $safe /tmp/out.jpg");
// Whitelist chặn `-` ở đầu nên không argument injection
```

```php
// proc_open với array args (PHP 7.4+) — KHÔNG qua shell
$proc = proc_open(
    ['ffmpeg', '-i', $inputPath, '-y', $outputPath],
    [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']],
    $pipes
);
// args tách rời, không bị shell parse
```

```php
// Dùng thư viện PHP thay vì exec
use Intervention\Image\ImageManagerStatic as Image;
Image::make($inputPath)->resize(800, 600)->save($outputPath);
// Không exec shell
```

```php
// Symfony Process với array — safer
use Symfony\Component\Process\Process;
$process = new Process(['git', 'clone', $repoUrl, $destDir]);
$process->run();
// Tuy nhiên vẫn cần validate $repoUrl chống option injection (`-o ProxyCommand`)
```

## Fix recommendation

1. **Tránh exec hoàn toàn**: dùng PHP library thuần (`Intervention/Image`, `getID3`, `League\Flysystem`, `ZipArchive`).
2. **Nếu phải exec**, dùng `proc_open` với **array args** (PHP 7.4+) hoặc Symfony `Process` với array — KHÔNG qua shell, không bị command injection. CHỈ còn nguy cơ argument injection (chèn option).
3. **Chống argument injection**: thêm `--` separator (`convert -- $file out.jpg`) để command không parse arg sau như option. Validate biến KHÔNG bắt đầu bằng `-`.
4. **Whitelist regex chặt**: `^[a-zA-Z0-9._-]+$` cho filename, `^[a-zA-Z0-9.]+$` cho hostname.
5. **`escapeshellarg` cho mọi argument**, KHÔNG dùng `escapeshellcmd` cho cả câu (kém hiệu quả).
6. **Drop privileges**: PHP-FPM chạy với user riêng, `disable_functions = exec,system,shell_exec,passthru,popen,proc_open` trong php.ini cho user-facing scope (nếu app không cần exec).
7. **chroot / container**: limit scope nếu exec bắt buộc.
8. **KHÔNG dùng filename gốc của upload** (`getClientOriginalName`) — generate UUID + extension whitelist.

## Cross-references

- Rule `01-hardcoded-secret`: env var leak qua subprocess inherit (PHP-FPM environment)
- Rule `12-broken-access-control`: cmd injection trên endpoint public = RCE full server
- Rule `17-verbose-error-debug-mode`: stderr/stdout của exec đưa vào response (`passthru`) leak command
- Rule `08-insecure-deserialization`: cùng họ "code execution" — PHP có nhiều con đường RCE
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 470kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 470kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 470kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall