OS Command Injection

It allows an attacker to run arbitrary commands on a web server's operating system.

Testing for OS Command Injection example

# Below is an example of a specific scenario.
# Visit the page at: 
http://192.168.209.189:8000/
# You will see that we are allowed to run the 'git clone repo_url' command.

# For tring, Run any git clone command
git clone https://github.com/gouravkhator/temp-git.git
# Intercept the request using burp suite.
# See if your request worked successfully or not.

# In my case i am seeing that value is passed using variable named "Archive="
# We can experiment using burp suite or curl.
# I know how to use burp or i will use curl command.

Checking which is underlying OS.

Using Both methods that is Powercat Reverse Shell and Encoded PowerShell Command we got the shell but Encoded PowerShell Command is a stealthier approach and also minimizes dependencies.

Blind Command Injection

Sometimes we don't get output for commands run by us. But it does run internally.

Vulnerable Function

  • The back-end uses a vulnerable function (e.g., popen(), eval()) that allows appending additional shell commands via user input.

  • Example injection: test%22%26%26whoami%22 (which is effectively test" && whoami").

Why Output Is Not Shown

  • The function might not return stdout to the web response, so you don’t see the command's output.

  • You might only see errors (stderr), which explains why there’s an error message but no result from whoami.

Trial & Error

  • Different payloads (; whoami, | whoami, backticks, etc.) might be needed due to filtering or shell differences.

  • Escaping or encoding techniques may be necessary if certain characters get stripped or sanitized.

Last updated