WINDOWS · LESSON 03

Threads, Fibers & Scheduling

20 min

Learning Objectives

  • Distinguish threads, fibers, and jobs
  • Understand thread context and why it matters
  • Recognize injection via thread creation
  • Read synchronization primitives (mutexes, events)

Threads Are the Execution Units

A thread is what actually runs code. A process can host many threads. Each thread has its own:

  • Stack — for locals and return addresses.
  • Context — registers, including RIP and RSP.
  • Thread Environment Block (TEB) — thread-local data (and the PEB is reachable from it).

The Thread Context

A thread’s context is its full register snapshot. GetThreadContext / SetThreadContext read/write it. This is the mechanism behind:

  • CreateRemoteThread — start a thread in another process (injection).
  • QueueUserAPC — queue a function to run in a target thread.
  • Hijacking — suspend a thread, rewrite its RIP, resume it.

Any API that manipulates another process’s thread context is injection-adjacent.

Fibers

Fibers are cooperative user-mode “threads” scheduled by the program, not the kernel. ConvertThreadToFiber / SwitchToFiber swap execution contexts manually. Malware uses fibers to hide execution flow from tools that only track threads.

Jobs and Scheduling

Jobs group processes and can limit them (CPU, memory). Analysts see jobs when a sandbox or a service controls a process tree.

Synchronization Primitives

Named objects coordinate across processes and are themselves IOCs:

ObjectPurposeMalware use
Mutexmutual exclusionsingle-instance guard (name = IOC)
Eventsignalingcoordination between threads
Semaphorecountingresource limiting
Named pipeIPClocal C2 / privilege handoff

A named mutex like Global\MalwareGuard_7F3A is both an indicator and a persistence/anti-double-run marker.

Takeaway

Injection is thread manipulation. Learn the thread APIs, and you can spot every injection primitive.

Next: DLLs & the Loader.