windows-internals-dev
Auth/lab dev: Windows internals; PE loading and CRT startup, PEB/TEB, PE/COFF, syscalls, unwinding, memory/heap, tokens, kernel objects, ETW/AMSI telemetry.
v2026.11.13-21cd5683 installs+3 in 7 days39 StarsMITsynced 10 hours ago
Install
No NotHoly CLI yet? Install it first.
$ curl -fsSL https://notholy.com/install.sh | sh$ notholy skills install aeondave/windows-internals-devWrites to ~/.notholy/skills after checking the signature and the SHA-256.
SignatureSigned, ed25519
Package57c30437…e1ded9c0
57c304377e41…126fe1ded9c012 files · 90.1 KBScanLow1 finding
- Links to outside domains
Sourcegithub.com/AeonDave/malskill/tree/main/offensive-coding/windows-internals-dev@21cd568
On this page
Foundational Windows internals for programmatic work: writing implants and loaders, reversing your own binaries, building EDR/AV tooling, or understanding what the kernel actually does under a Win32 call. This is structural and mechanical knowledge — if you need tool usage, look in offensive-tools/; if you need language-specific patterns, look in *-patterns skills.
Check private layouts and behavior against the exact image and matching symbols. A source example or a diagnostic survey does not establish support across a Windows release family. Use Microsoft release information to identify the release and edition lifecycle; do not infer either from a remembered build label.
Rule of thumb: if your code uses any Win32 API that is documented, this skill is not needed. If you are walking a PEB pointer, parsing UNWIND_INFO, resolving SSNs, spoofing a call stack, patching ETW-TI, or touching a kernel object directly — start here.
When to activate
- Writing an implant, loader, or BOF that cannot use traditional imports
- Building indirect syscall dispatch (Hell's / Halo's / Tartarus / Recycled Gate)
- Reversing your own release binary to verify ASM stubs land correctly
- Tracing native execution before
main/WinMainor checking PE entry, TLS, and CRT initialization against the target toolchain - Implementing call-stack spoofing (SilentMoonwalk / Draugr / CHRYSALIS)
- Patching AMSI, ETW, or ETW-TI in userland; understanding what kernel telemetry remains
- Writing a kernel driver that registers process/thread/image/registry callbacks
- Designing around mitigations: CFG, XFG, CET shadow stack, HVCI, Credential Guard
- Reasoning about detection surface when designing an offensive technique
If the question is "what function do I call" — wrong skill. If the question is "what does the OS actually do when I call this, and what can I touch directly instead" — right skill.
Map of the territory
Everything below is a pointer into a reference file. Load only what you need.
| Domain | File | Covers |
|---|---|---|
| Process/thread state blocks | references/peb-teb.md |
PEB, TEB, LDR data, InMemoryOrderModuleList, ApiSetMap, module walking, hash-based resolution |
| Build survey evidence | references/build-survey.md | Load when comparing x64 Windows survey logs: per-run observations, provenance, collection status, and bounded diagnostic checks |
| PE / COFF and startup | references/pe-format.md |
Load for PE parsing or before-user-entry diagnosis: headers, TLS/CRT boundaries, matching source, symbols, and debugger steps |
| Syscalls | references/syscalls.md |
Syscall ABI (x64/ARM64), SSN resolution strategies, direct/indirect dispatch, gate variants, stub layout |
| Exception handling | references/exception-unwind.md |
SEH, VEH, UNWIND_INFO, RtlLookupFunctionEntry, RtlVirtualUnwind, KiUserExceptionDispatcher, call-stack spoofing frames |
| Memory | references/memory-management.md |
Virtual memory (NtAllocate/Protect/Write/Read), sections, VADs, NT heap vs Segment heap, LFH |
| Threads / APCs | references/threads-apcs.md |
Thread creation, suspension, CONTEXT struct, user/kernel/Special APCs, thread hijacking primitives |
| Tokens / privileges | references/tokens-privileges.md |
TOKEN struct, privileges, integrity levels, impersonation vs primary, DuplicateTokenEx semantics |
| Kernel objects | references/kernel-objects.md |
EPROCESS, ETHREAD, KPCR/KPRCB, handle table, object manager namespace, kernel callbacks |
| Mitigation surface | references/evasion-surface.md |
ETW/ETW-TI, AMSI, CFG/XFG/CET, VBS/HVCI/CG, userland hook detection/unhooking |
Quick-reference: x86-64 Windows ABI
Non-negotiable invariants. Violating any of these causes silent corruption that surfaces later.
| Invariant | Rule |
|---|---|
| Stack alignment | rsp % 16 == 0 at every call site |
| Shadow space | 32 bytes reserved by caller before every call (sub rsp, 0x28 min with alignment) |
| Integer args (1–4) | rcx, rdx, r8, r9 |
| Integer args (5+) | Stack, caller-allocated |
| Float args (1–4) | xmm0–xmm3 |
| Integer return | rax |
| Callee-saved (int) | rbx, rbp, rsi, rdi, r12–r15 |
| Callee-saved (xmm) | xmm6–xmm15 |
| Syscall number | rax (user-mode SSN before syscall) |
| Syscall arg 4 | r10 — kernel clobbers rcx, so userland stub must mov r10, rcx |
| TEB | gs:[0x30] |
| PEB | gs:[0x60] (or [[gs:0x30] + 0x60]) |
Quick-reference: ARM64 Windows ABI
| Invariant | Rule |
|---|---|
| Stack alignment | sp % 16 == 0 (hardware enforced at PSTATE transitions) |
| Integer args (1–8) | x0–x7 |
| Float args (1–8) | d0–d7 |
| Integer return | x0 |
| Callee-saved (int) | x19–x28, x29 (fp), x30 (lr) |
| Callee-saved (vec) | d8–d15 |
| Syscall number | x8 |
| Syscall instruction | svc #0 |
| TEB | x18 (platform register, reserved by Windows) |
| PEB | [x18 + 0x60] |
ARM64EC (x64 emulation compatible) uses a modified register mapping — x0..x15 map to rcx,rdx,r8,r9 etc. If writing ARM64EC ASM, consult the Microsoft ARM64EC ABI doc, not this table.
Common structure offsets (x64, Windows 10–11)
These are the 12 offsets you will look up most often. Full layouts in references/peb-teb.md.
| Structure | Field | Offset | Notes |
|---|---|---|---|
| TEB | ProcessEnvironmentBlock | 0x60 | PEB pointer |
| TEB | ThreadLocalStoragePointer | 0x58 | TLS slot array |
| TEB | LastErrorValue | 0x68 | GetLastError storage |
| PEB | BeingDebugged | 0x02 | 1 byte |
| PEB | ImageBaseAddress | 0x10 | Main .exe base |
| PEB | Ldr | 0x18 | PEB_LDR_DATA pointer |
| PEB | ProcessParameters | 0x20 | RTL_USER_PROCESS_PARAMETERS |
| PEB | ApiSetMap | 0x68 | API_SET_NAMESPACE pointer |
| PEB_LDR_DATA | InLoadOrderModuleList | 0x10 | Head of load order list |
| PEB_LDR_DATA | InMemoryOrderModuleList | 0x20 | Head of memory order list |
| LDR_DATA_TABLE_ENTRY | DllBase | 0x30 | Module base address |
| LDR_DATA_TABLE_ENTRY | BaseDllName | 0x58 | UNICODE_STRING |
When walking
InMemoryOrderModuleList, theFlinkyou dereference points intoInMemoryOrderLinks(offset 0x10) of the next entry, not its base. Subtract 0x10 to get the entry pointer.
The 10 things you will do over and over
- Get a module base without LoadLibrary — walk PEB → Ldr → InMemoryOrderModuleList, hash
BaseDllName, compare. Seepeb-teb.md§Module Walk. - Resolve an export by hash — parse target module's PE headers →
DataDirectory[0]→ iterate AddressOfNames / AddressOfOrdinals / AddressOfFunctions. Seepe-format.md§Export Walk. - Resolve an SSN — Hell's Gate reads the function stub at the resolved Nt* address and extracts the immediate after
mov eax, imm32. Halo's / Tartarus Gate fall back when the stub is hooked. Recycled Gate enumerates allZw*exports and sorts by RVA to derive SSN from index. Seesyscalls.md. - Find a
syscall; retgadget — scan any Nt* stub body for the byte sequence0F 05 C3. Used by Recycled Gate / indirect syscall paths to route all syscalls through ntdll. Seesyscalls.md§Indirect Dispatch. - Parse UNWIND_INFO for a function — binary-search
.pdata(DataDirectory[3]) for aRUNTIME_FUNCTIONwhose[BeginAddress, EndAddress)contains your RIP. WalkUnwindCodes[]to derive frame size and saved registers. Seeexception-unwind.md. - Build a spoofed call stack — find two chained unwind frames (
UWOP_SET_FPREGterminator +UWOP_PUSH_NONVOL(rbp)second frame), plant fake return addresses on the real RSP matching those unwinders, thenjmpinto the target. The unwinder validates; the scanner walks the frame list and sees legitimate module addresses. Seeexception-unwind.md§Call-stack Spoofing. - Open a token, check elevation, impersonate —
NtOpenProcessToken→NtQueryInformationToken(TokenElevation)/TokenUser→NtDuplicateToken(SecurityImpersonation)→NtSetInformationThread(ThreadImpersonationToken). Seetokens-privileges.md. - Inject into another process — allocate remote memory (
NtAllocateVirtualMemoryor section +NtMapViewOfSection), write payload, create thread (NtCreateThreadEx) or queue APC (NtQueueApcThread[Ex2]). Seethreads-apcs.md. - Patch AMSI / ETW in-process — locate
AmsiScanBuffer(amsi.dll) orEtwEventWrite/NtTraceEvent(ntdll.dll), flip page protection RW, write a 1-byteretormov eax, 0x80070057; retprologue, restore protection. Seeevasion-surface.md. - Walk the PSP callback list (kernel) — kernel shellcode iterates
PspCreateProcessNotifyRoutine(array of 64EX_CALLBACK_ROUTINE_BLOCKpointers with low-bit tagging) and nulls entries belonging to EDR drivers. Seekernel-objects.md§Kernel Callbacks.
Syscall dispatch decision tree
Need to invoke an Nt* function without touching ntdll's hooked stub?
│
├── Can ntdll.dll be walked?
│ │
│ ├── YES → Use PEB walk to resolve Nt* address
│ │ │
│ │ ├── Stub unhooked? → Hell's Gate (read SSN from stub at +4)
│ │ │
│ │ └── Stub hooked? → Halo's/Tartarus Gate (walk neighbors ±1)
│ │ OR Recycled Gate (sort Zw* exports by RVA)
│ │
│ └── NO (unusual — stripped PEB or sandbox) → Hard-coded SSN table
│ (brittle, version-specific)
│
├── Executing the syscall:
│ │
│ ├── Direct → Emit `syscall` instruction in your own .text
│ │ • Callstack has your module → red flag
│ │
│ ├── Indirect → Emit `call <syscall;ret gadget inside ntdll>`
│ │ • Callstack shows ntdll frame → clean
│ │ • Requires gadget discovery pass
│ │
│ └── Desync → Build spoofed 3-frame call stack, `jmp` into gadget
│ • Callstack shows chain of legit frames
│ • Full UNWIND_INFO math required
│
└── 6+ args? → 5th arg onwards goes on stack after shadow space
Stubs vary: see syscalls.md §Multi-arg variantsArchitectural lifecycles you must understand
DLL load (LdrLoadDll)
For startup analysis, use the documented boundary: an image's TLS callbacks run before that image's PE entry point. With default MSVC DLL startup, the PE entry point is _DllMainCRTStartup, which initializes the CRT before calling the user's DllMain. Dependencies are initialized before the executable reaches its own PE entry point; keep exact cross-image loader event ordering build-specific. See references/pe-format.md for the WinDbg observation method.
For DLL_THREAD_ATTACH, Microsoft documents that a DLL loaded with LoadLibrary receives notifications only for threads created after that load; existing threads do not receive a retroactive thread-attach call. Do not generalize this rule into undocumented TLS callback timing for every loader path.
Thread creation (NtCreateThreadEx)
- Kernel allocates ETHREAD, creates TEB in process VA space
- Initial context populated from caller params (start address, parameter, stack info)
- If
THREAD_CREATE_FLAGS_CREATE_SUSPENDEDset → thread placed in waiting state - Otherwise queued for execution
- First user-mode code on thread is
LdrInitializeThunk(unlessTHREAD_CREATE_FLAGS_SKIP_LOADER_INIT) — runs DLL TLS callbacks,DllMain(DLL_THREAD_ATTACH)for every loaded DLL, then jumps to start address
Offensive note: SKIP_LOADER_INIT (0x20) skips the entire LdrInit chain — useful for shellcode threads that must not run DLL_THREAD_ATTACH across every loaded DLL. SKIP_THREAD_ATTACH (0x2) skips only the DLL_THREAD_ATTACH notifications, not TLS callbacks or the loader chain.
Exception dispatch (user-mode)
- Hardware or software raises → kernel transfers to
KiUserExceptionDispatcherin ntdll RtlDispatchExceptionwalks the function table starting at faulting RIP- For each frame:
RtlLookupFunctionEntry→RtlVirtualUnwind→ check for registered handler - Handler decides:
ExceptionContinueSearch/ContinueExecution - If unhandled →
UnhandledExceptionFilter→ VEH chain → process terminate viaNtTerminateProcess
Offensive use: VEH registration (RtlAddVectoredExceptionHandler) is a pre-SEH hook, runs before stack-based handlers. Common abuse: register VEH, trigger a fault, have VEH set ContextRecord->Rip to shellcode, return ExceptionContinueExecution. Leaves minimal forensic trace compared to thread creation.
Detection surface to reason about
When you apply any technique, the following signals are potentially visible. This is a high-level map; details in evasion-surface.md.
| Signal | Who sees it | What triggers it |
|---|---|---|
| Userland hooks | EDR in-process agent | Calling Nt* via ntdll stub |
| ETW (userland) | EDR agent or Microsoft-Windows-* consumers |
EtwEventWrite inside ntdll/kernel32 wrappers |
| ETW-TI (kernel) | PPL service consuming kernel events | Memory writes to remote processes, SUSPEND/RESUME, APC queue, etc. |
| AMSI | Registered AMSI providers (Defender) | Script content scanned by AmsiScanBuffer |
| Kernel callbacks | EDR driver | Process/thread/image/registry create, handle open |
| Minifilter | EDR filesystem driver | File open/read/write/create |
| Handle open audit | Kernel | Any NtOpen* on protected process (LSASS, etc.) |
| CFG violation | Process | Indirect call to non-valid target |
| Shadow stack mismatch | CET-enabled process | ret address mismatches shadow stack top |
Important reality: modern advanced EDRs (Defender for Endpoint, Elastic, CrowdStrike recent builds) rely primarily on kernel callbacks and ETW-TI. Userland unhooking by itself does nothing against them. Plan your technique accordingly — see evasion-surface.md §EDR Architecture.
Pitfalls and invariants
PEB walk checks
- List positions and counts describe the sampled process; do not identify modules by a fixed ordinal. For diagnostic plausibility checks, load
references/peb-teb.md. BaseDllNameis aUNICODE_STRING(16 bytes: Length, MaximumLength, Buffer). Length is in bytes, not chars- Module name comparisons must be case-insensitive (use lowercase for both operands of hash)
PE parsing invariants
- Validate
e_magic == 0x5A4D("MZ") ande_lfanew > 0 && e_lfanew < PE_file_size - Validate
NT_Signature == 0x00004550("PE\0\0") - On 64-bit PE,
OptionalHeader.Magic == 0x20B;DataDirectorystarts atOptionalHeader + 0x70(= NT_HEADERS64 + 0x88), so the export directory RVA isOptionalHeader + 0x70. OptionalHeader + 0x88 is DataDirectory[3] (.pdata), not the export directory - Forwarded exports: if an export RVA is within
DataDirectory[0]range, it is a forwarder string"dll.function"— recursively resolve
Manual mapping / reflective DLL invariants
- The OS loader normally runs TLS callbacks and calls the PE
AddressOfEntryPoint, which is usually CRT startup before userDllMain. - A custom reflective loader may define a different contract: exported
DllMaincan be a minimal shellcode attach gate, followed by an explicit reflective start export. Do not replace that withAddressOfEntryPointjust because it resembles the OS loader; verify the payload'sreservedsemantics and runtime markers first. - For Rust cdylibs, distinguish loader lifecycle bugs from runtime-library boundary bugs. If profile decode, session encode, and DNS resolve already work, a crash in
TcpStream::connect_timeoutis more likely a socket/runtime primitive issue than an earlier PE entrypoint issue. - Generated shellcode arrays are build artifacts. After changing a reflective loader, regenerate and rebuild the final wrapper before testing; source edits alone do not change the payload under test.
Syscall invariants
- On x64, before
syscall:r10 = rcx. Kernel clobbersrcxwith return address - Wow64 processes have a 32→64 transition through
wow64cpu!CpupReturnFromSimulatedCode; directsyscallfrom 32-bit code does not work — must go through the transition - SSN drift between builds: hard-coded SSNs break on the first Patch Tuesday. Always resolve at runtime
- On ARM64:
svc #0is the instruction; SSN goes inx8(notw8), args inx0–x7, then stack
Unwind invariants
UNWIND_INFO.CountOfCodesis rounded up to even; iterate in pairsUWOP_ALLOC_SMALL: size encoded asOpInfo * 8 + 8(range 8..128)UWOP_ALLOC_LARGE: size in following 2 or 4 bytes;OpInfo == 0→ 2-byte scaled by 8,OpInfo == 1→ 4-byte raw- Chained unwind info (
UNW_FLAG_CHAININFO): last code entry isRUNTIME_FUNCTIONof parent, not a code — follow it - Functions without
.pdata(leaf functions with no prologue) cannot be unwound — useless as spoof frames
Token invariants
NtOpenProcessToken(NtCurrentProcess(), TOKEN_QUERY, ...)always succeeds — you own your own tokenNtOpenProcessTokenon another process requires at minimumPROCESS_QUERY_LIMITED_INFORMATIONon the process handle andTOKEN_DUPLICATEfor impersonation- Primary tokens cannot be assigned to threads — must
DuplicateTokenExwithTokenImpersonationfirst, or useCreateProcessWithTokenWfor new process - Impersonation token integrity cannot exceed thread's primary token integrity without
SeImpersonatePrivilege
Memory invariants
NtProtectVirtualMemoryrounds up to page granularity — querying the old protection returns the protection of the first page in the rangeNtAllocateVirtualMemorywithMEM_COMMITover an already-committed region succeeds (idempotent commit) and preserves contents; over a reserved-but-not-committed region zero-fills- Writing to a
PAGE_NOACCESSguard page raisesSTATUS_GUARD_PAGE_VIOLATIONonce, then converts to normal access — useful for trap-then-continue primitives
Resources
Companion skills
stack-spoofing— Building call-stack spoof trampolines (Draugr / SilentMoonwalk / CHRYSALIS): frame-size math withSAVE_NONVOLsafety filter,FF 23gadget scanner with debug instrumentation, Win11 22H2+ empirical gadget inventory, C/Rust/Go trampoline skeletons.indirect-syscall— Building indirect syscall dispatchers: SSN resolution (Hell's / Halo's / Tartarus / RecycledGate / DWhisper),syscall;retgadget discovery with caching, name obfuscation, per-language dispatcher implementations with arg-count variants.
Use those skills when writing code; use this one for the underlying structures and invariants.
Reference files in this skill
references/peb-teb.md— PEB, TEB, LDR data, ApiSetMap, module walking, hash-based resolutionreferences/pe-format.md— load for PE parsing or native startup diagnosis beforemain/WinMain/userDllMain, with source/disassembly/debugger correlationreferences/syscalls.md— Syscall ABI, SSN resolution (Hell's/Halo's/Tartarus/Recycled/HWSyscall), direct/indirect dispatchreferences/exception-unwind.md— SEH/VEH, UNWIND_INFO, RtlVirtualUnwind, KiUserExceptionDispatcher, call-stack spoofingreferences/memory-management.md— Virtual memory, sections, VADs, NT heap / Segment heap / LFHreferences/threads-apcs.md— Thread creation, CONTEXT, user/kernel/Special APCs, thread hijackingreferences/tokens-privileges.md— TOKEN struct, privileges, integrity levels, impersonationreferences/kernel-objects.md— EPROCESS, ETHREAD, KPCR/KPRCB, handle table, object manager, kernel callbacksreferences/evasion-surface.md— ETW/ETW-TI, AMSI, CFG/XFG/CET, VBS/HVCI/CG, hook detection/unhooking- Start with the narrowest subsystem reference that matches the current primitive; expand only when the chain crosses subsystems.
Files in this version
assets/12.5 KB
- windows-survey-v5-2026-10.csv2.5 KB
references/10217.5 KB
- build-survey.md5.9 KB
- evasion-surface.md31.3 KB
- exception-unwind.md22.4 KB
- kernel-objects.md28.6 KB
- memory-management.md20.3 KB
- peb-teb.md16.0 KB
- pe-format.md25.0 KB
- syscalls.md21.6 KB
- threads-apcs.md18.5 KB
- tokens-privileges.md28.0 KB
- SKILL.md20.3 KB
Permissions
| Permission | Declared | Found by the scan |
|---|---|---|
| Reads files | No | No |
| Writes files | Yes | Yes |
| Runs shell commands | Yes | Yes |
| Uses the network | Yes | Yes |
| Uses connectors | No | No |
| Drives a browser | No | No |
Scan findings
Reviewed on Nov 13, 2026
- InfoLink · Links to outside domains
A clean scan lowers the risk but does not prove a package is safe. Read what you install.
| Version | Published | Commit | SHA-256 | Signature | Permission change |
|---|---|---|---|---|---|
| v2026.11.13-21cd568 | Nov 13, 2026 | 21cd568 | 57c30437 | Signed | – |
More from AeonDave
All from this publisherMore in Active Directory and Windows
See the category- offensive-windows-mitigationssnailsploit/offensive-windows-mitigations4
- active-directory-attack-pathssecurityskills/active-directory-attack-paths3
- analyzing-powershell-script-block-loggingmukul975/analyzing-powershell-script-block-logging3
- offensive-windows-boundariessnailsploit/offensive-windows-boundaries3
- evil-winrmaeondave/evil-winrm3
- bloodyadaeondave/bloodyad3
Ask anything your scope allows.
Create an account, add credits and ask the first question in the chat or the terminal.
- 1/3
Create the account
Individual or company. You can switch to a company later without losing balance or keys.
IndividualCompany - 2/3
Add credits
By card. Pay per token, no subscription.
$5.00minimum deposit - 3/3
Ask
In the chat, or install the CLI and run notholy login in your terminal.
$ notholy login