WINDOWS · LESSON 05

Windows API & Native Layer

25 min

Learning Objectives

  • Navigate the Win32 → Native (NT) API stack
  • Recognize the most analysis-relevant APIs
  • Understand syscalls and ntdll
  • Trace suspicious API chains

The API Stack

Windows exposes multiple layers:

Application
   └─ Win32 API     (kernel32.dll, user32.dll, advapi32.dll ...)
        └─ Native API  (ntdll.dll — Nt/Zw functions)
             └─ syscall  (into the kernel)

Most programs call Win32; the Win32 functions forward to ntdll’s native functions, which make the actual syscalls.

Why the Layers Matter

  • Win32 is documented and stable; it’s what imports show.
  • Native (ntdll) is semi-documented; NtCreateFile, NtAllocateVirtualMemory, etc.
  • Syscalls are numbered per-version; direct syscall malware bypasses ntdll hooks.

When a binary imports from ntdll.dll directly (or makes raw syscalls), it’s trying to stay below the Win32 surface — a common evasion technique.

The Analysis-Relevant APIs

CategoryAPIs
Process injectionOpenProcess, VirtualAllocEx, WriteProcessMemory, CreateRemoteThread, NtCreateThreadEx
PersistenceRegSetValueEx, CreateService, SetFileAttributes
C2 / networkInternetOpen, InternetConnect, WSAStartup, connect
CryptoCryptAcquireContext, CryptEncrypt, BCryptEncrypt
Anti-analysisIsDebuggerPresent, CheckRemoteDebuggerPresent, GetTickCount
File opsCreateFile, ReadFile, WriteFile, DeleteFile

Tracing a Suspicious Chain

Don’t read imports in isolation — read them as a narrative:

VirtualAllocEx → WriteProcessMemory → CreateRemoteThread

That’s a sentence: “allocate, write, execute” — injection. Reading the chain tells you what the binary does; the strings and XREFs tell you why.

Direct Syscalls

Advanced malware emits syscall instructions directly (or calls ntdll stubs with syscall numbers), avoiding import-table visibility and user-mode hooks. Detection requires inspecting ntdll or watching for syscall instructions in unusual locations.

Interactive: Import Chains

The PE below shows a set of imports. Read the names as a capability narrative.

Takeaway

The API is a language. Learn the vocabulary, and imports read like sentences.

Lab 13: Suspicious API Chains → Suspicious API Chains

Interactive

LAB

lab-13

Apply what you learned in a hands-on challenge.

Open Lab