Loopus

Pro Content

This lesson requires Loopus Pro access. Upgrade to unlock all courses, labs, and challenges.

Web Application HackingServer-Side Vulnerabilities

Command Injection

25 min
lab
+60 XP

Learning Objectives

  • Understand command injection vulnerabilities
  • Learn to identify injection points in applications
  • Master blind command injection techniques

Command Injection

Command injection occurs when applications pass unsanitized user input to system shell commands. This vulnerability grants attackers the ability to execute arbitrary commands on the server, potentially leading to complete system compromise.

How Command Injection Works

Applications sometimes need to interact with the operating system for running commands, processing files, or managing services. When user input becomes part of these commands without proper sanitization, injection becomes possible.

Command Separators

Different operating systems support various command separators:

Unix/Linux:

  • Semicolon separates commands

  • Pipe uses output of first command

  • Double pipe runs second if first fails

  • Ampersand runs in background

  • Double ampersand runs second if first succeeds


Windows:
  • Ampersand separates commands

  • Pipe chains output

  • Double operators work similar to Unix


Basic Exploitation

Testing for command injection involves appending command separators followed by test commands like whoami or id. Response timing with sleep commands helps detect blind injection.

Blind Command Injection

When output is not visible, use alternative detection methods such as time-based detection using sleep or ping commands, and out-of-band detection using DNS exfiltration or HTTP callbacks.

Prevention

Secure applications avoid shell commands entirely when possible. When necessary, use language-native libraries instead of shell commands, implement strict input validation with whitelists, and use parameterized APIs that do not invoke shells.

Answer the Questions0 / 4 completed

📚 KnowledgeQuestion 1

Running OS instructions via app input is?

Format: *********(9 chars)
Exact match required
⌨️ Hands-OnQuestion 2

What Linux command prints the user ID?

Format: **(2 chars)
Exact match required
📚 KnowledgeQuestion 3

What character pipes output between commands?

Format: |
Exact match required
⌨️ Hands-OnQuestion 4

What network tool creates reverse shells?

Format: **(2 chars)
Exact match required
Answer all questions correctly to unlock the next lesson

Interactive Sandbox

Loading sandbox...

Submit Flag

Found the flag? Submit it below to complete this lesson.
Format: LOOPUS{...}

Previous
Answer all questions to continue