---
title: "CAPEC-640: Inclusion of Code in Existing Process"
url: https://radicalnotion.ai/capec/capec-640
type: capec
description: "The adversary takes advantage of a bug in an application failing to verify the integrity of the running process to execute arbitrary code in the address space of a separate live process. The adversary could use running code in the context of another process to try to access process's memory, system/network resources, etc. The goal of this attack is to evade detection defenses and escalate privileges by masking the malicious code under an existing legitimate process. Examples of approaches include but not limited to: dynamic-link library (DLL) injection, portable executable injection, thread execution hijacking, ptrace system calls, VDSO hijacking, function hooking, reflective code loading, and more."
updated: 2026-06-01
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CAPEC-640: Inclusion of Code in Existing Process

- **Abstraction:** Detailed
- **Status:** Stable
- **Typical severity:** High
- **Likelihood of attack:** Low
- **CAPEC catalog version:** 3.9

## Description

The adversary takes advantage of a bug in an application failing to verify the integrity of the running process to execute arbitrary code in the address space of a separate live process. The adversary could use running code in the context of another process to try to access process's memory, system/network resources, etc. The goal of this attack is to evade detection defenses and escalate privileges by masking the malicious code under an existing legitimate process. Examples of approaches include but not limited to: dynamic-link library (DLL) injection, portable executable injection, thread execution hijacking, ptrace system calls, VDSO hijacking, function hooking, reflective code loading, and more.

## Execution flow

### Step 1: Explore

\[Determine target process\] The adversary determines a process with sufficient privileges that they wish to include code into.

- On Windows, use the process explorer's security tab to see if a process is running with administror privileges.
- On Linux, use the ps command to view running processes and pipe the output to a search for a particular user, or the root user.

### Step 2: Experiment

\[Attempt to include simple code with known output\] The adversary attempts to include very simple code into the existing process to determine if the code inclusion worked. The code will differ based on the approach used to include code into an existing process.

### Step 3: Exploit

\[Include arbitrary code into existing process\] Once an adversary has determined that including code into the existing process is possible, they will include code for a targeted purpose, such as accessing that process's memory.

## Prerequisites

- The targeted application fails to verify the integrity of the running process that allows an adversary to execute arbitrary code.

## Skills required

- **High:** Knowledge of how to load malicious code into the memory space of a running process, as well as the ability to have the running process execute this code. For example, with DLL injection, the adversary must know how to load a DLL into the memory space of another running process, and cause this process to execute the code inside of the DLL.

## Consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity, Confidentiality | Execute Unauthorized Commands, Read Data | - |

## Mitigations

- Prevent unknown or malicious software from loading through using an allowlist policy.
- Properly restrict the location of the software being used.
- Leverage security kernel modules providing advanced access control and process restrictions like SELinux.
- Monitor API calls like CreateRemoteThread, SuspendThread/SetThreadContext/ResumeThread, QueueUserAPC, and similar for Windows.
- Monitor API calls like ptrace system call, use of LD\_PRELOAD environment variable, dlfcn dynamic linking API calls, and similar for Linux.
- Monitor API calls like SetWindowsHookEx and SetWinEventHook which install hook procedures for Windows.
- Monitor processes and command-line arguments for unknown behavior related to code injection.

## Related weaknesses (CWE)

- [CWE-114](https://radicalnotion.ai/cwe/cwe-114): Process Control
- [CWE-829](https://radicalnotion.ai/cwe/cwe-829): Inclusion of Functionality from Untrusted Control Sphere

## Related attack patterns

| Relationship | CAPEC | Name |
| --- | --- | --- |
| Parent | [CAPEC-251](https://radicalnotion.ai/capec/capec-251) | Local Code Inclusion |

## Taxonomy mappings

| Taxonomy | Entry | Id |
| --- | --- | --- |
| ATTACK | Server Software Component: Terminal Services DLL | 1505.005 |
| ATTACK | Hijack Execution Flow: Dynamic Linker Hijacking | 1574.006 |
| ATTACK | Hijack Execution Flow: KernelCallbackTable | 1574.013 |
| ATTACK | Reflective Code Loading | 1620 |

## Frequently asked questions

### What is CAPEC-640?

The adversary takes advantage of a bug in an application failing to verify the integrity of the running process to execute arbitrary code in the address space of a separate live process. The adversary could use running code in the context of another process to try to access process's memory, system/network resources, etc. The goal of this attack is to evade detection defenses and escalate privileges by masking the malicious code under an existing legitimate process. Examples of approaches include but not limited to: dynamic-link library (DLL) injection, portable executable injection, thread execution hijacking, ptrace system calls, VDSO hijacking, function hooking, reflective code loading, and more.

### How does a Inclusion of Code in Existing Process attack work?

It typically unfolds over 3 phases. It begins with: \[Determine target process\] The adversary determines a process with sufficient privileges that they wish to include code into.

### How do you prevent CAPEC-640?

Prevent unknown or malicious software from loading through using an allowlist policy.

### What weaknesses does CAPEC-640 target?

CAPEC-640 exploits 2 CWE weaknesses: CWE-114 (Process Control) and CWE-829 (Inclusion of Functionality from Untrusted Control Sphere).

### How severe is CAPEC-640?

MITRE rates CAPEC-640 as High severity with low likelihood of attack.

Primary source: [MITRE CAPEC](https://capec.mitre.org/data/definitions/640.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/capec/capec-640). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
