Code Injection and Hooking 2
Code Injection and Hooking 2
and Hooking
Code Injection
and Hooking
• In this chapter, you will learn how
malicious programs inject code into
another process (called target process
or remote process) to perform
malicious actions. The technique of
injecting malicious code into a target
process's memory and executing the
malicious code within the context of
the target process is called code
injection (or process injection).
An attacker typically chooses a legitimate process (such as
explorer.exe or svchost.exe) as the target process.
Once the malicious code is injected into the target process, it can
then perform malicious actions, such as logging keystrokes, stealing
passwords, and exfiltrating data, within the context of the target
process.
After injecting the code into the memory of the target process, the
malware component responsible for injecting code can either
continue to persist on the system, thereby injecting code into the
target process every time the system reboots, or it can delete itself
from the filesystem, keeping the malicious code in memory only.
Virtual Memory
• Virtual memory is a memory management technique
used by modern operating systems to provide each
process with the illusion of a large, contiguous address
space, even if physical memory (RAM) is limited. It
allows multiple processes to run concurrently while
efficiently utilizing available memory resources.
• Windows memory manager, with the help of hardware,
translates the virtual address into the physical address
(in RAM) where the actual data resides; to manage the
memory, it pages some of the memory to the disk.
• Virtual memory is segregated into process memory
(process space or user space) and kernel memory
(kernel space or system space).
• The size of the virtual memory address space
depends on the hardware platform.
• For example, on a 32-bit architecture, by default,
the total virtual address space (for both process and
kernel memory) is a maximum of 4 GB.
• On a 32-bit system, out of the 4 GB virtual address
space, each process thinks that it has 2 GB of process
memory, ranging from 0x00000000 - 0x7FFFFFFF.
• Since each process thinks that it has its own private
virtual address space (which ultimately gets mapped
to physical memory), the total virtual address gets
much larger than the available physical memory
(RAM).
• The Windows memory manager addresses this by
paging some of the memory to the disk; this frees the
physical memory, which can be used for other
processes, or for the operating system itself.
• Even though each Windows process has its own private
memory space, the kernel memory is, for the most part,
common, and is shared by all the processes.
The following diagram shows the memory layout of 32-bit
architecture. You may notice a 64 KB gap between the
user and kernel space; this region is not accessible and
ensures that the kernel does not accidentally cross the
boundary and corrupt the user-space.
Even though the virtual address range is the same for
each process (x00000000 - 0x7FFFFFFF), both the
hardware and Windows make sure that the physical
addresses mapped to this range are different for each
process.
Unlike stored injections, reflected attacks are not permanently housed on the
server. Instead, they trick users into executing malicious code via a URL. This
is often achieved through phishing emails or messages that lure users into
clicking on a compromised link.For instance, an attacker might send an email
posing as a trusted entity, urging the recipient to click on a link. This link
contains the malicious payload, which gets executed once clicked, leading to
the desired malicious outcome.
DOM-based HTML Injection