What Is Remote Code Execution?
Remote code execution (RCE) is a vulnerability outcome in which an attacker runs their own code or commands on a target system over a network, without physical access to the machine. The code usually runs with the privileges of the vulnerable process, so one flaw can expose data, credentials and connected systems.
Also known as:
What Remote Code Execution Means
RCE describes what an attacker can do, not one specific coding mistake. Several different weaknesses can end in the same result: input from outside the application ends up being executed as code or as an operating system command. That is why a CVE may be described as RCE while its root cause is recorded as a more precise CWE, such as code injection or unsafe deserialization.
Common Weaknesses That Lead to RCE
- Code injection (CWE-94). The application builds part of a code segment from external input without neutralizing syntax that changes what the code does. Dynamic evaluation with calls like
evalis the classic case. - OS command injection (CWE-78). The application builds an operating system command from external input, so an attacker can add commands of their own.
- Deserialization of untrusted data (CWE-502). The application rebuilds objects from attacker-controlled data without ensuring the result is valid, which can trigger dangerous behavior in some formats and libraries.
- Unsafe file upload. An attacker uploads a file the server later executes, such as a script placed in a web-accessible directory.
A Simple RCE Example
Imagine an image service that passes a user-supplied filename to a shell: subprocess.run(f"convert {name} out.png", shell=True). If an attacker submits a filename containing a shell separator followed by another command, the shell runs that command too. The fix is to avoid the shell and pass arguments as a list, so the filename stays data: subprocess.run(["convert", name, "out.png"]).
Why RCE Is So Severe
Code execution gives an attacker a foothold inside your environment. From there they can read secrets and environment variables, reach internal services, change data, install persistence or move to other systems. The real impact depends on what the process can access, which is why running services with least privilege limits the damage even when a flaw is exploited.
How to Prevent Remote Code Execution
- Use library functions that separate commands from arguments instead of building shell strings, as CISA recommends for OS command injection.
- Avoid dynamic evaluation of input. Where code must be generated, allow only a strict list of permitted constructs.
- Avoid native serialization formats for untrusted data, prefer plain data formats such as JSON and verify signatures on anything you must deserialize.
- Restrict uploaded file types and store uploads where they cannot be executed.
- Run services with least privilege and patch exploitable dependencies first.
How Nullify Helps Find RCE Risks
Nullify code analysis covers common weaknesses behind RCE, including code injection (dynamic evaluation, template injection and remote code download), OS command injection and unsafe deserialization. Nullify pentests can then test injection flaws and malicious file upload and execution against a running application, and validate exploitable dependency CVEs. Explore Nullify Code Security.
Key Takeaways
- Remote code execution lets an attacker run code or commands on a system over a network.
- RCE is an outcome that can come from code injection, command injection, unsafe deserialization or file upload flaws.
- The code typically runs with the privileges of the vulnerable process.
- Separating code from data and applying least privilege are the strongest defenses.
Read More About Remote Code Execution
Code Security
See Nullify in Action
Find the code injection, command injection and deserialization flaws that can lead to RCE.