<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Piyusha Akash</title>
    <description>The latest articles on DEV Community by Piyusha Akash (@mr-lowlevel).</description>
    <link>https://dev.to/mr-lowlevel</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4119754%2F629b4496-2063-44c8-8471-e9712fca2077.jpg</url>
      <title>DEV Community: Piyusha Akash</title>
      <link>https://dev.to/mr-lowlevel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mr-lowlevel"/>
    <language>en</language>
    <item>
      <title>Windows Syscalls: Direct vs Indirect, and Why Malware Researchers Care</title>
      <dc:creator>Piyusha Akash</dc:creator>
      <pubDate>Fri, 11 Sep 2026 13:21:39 +0000</pubDate>
      <link>https://dev.to/mr-lowlevel/windows-syscalls-direct-vs-indirect-and-why-malware-researchers-care-5fjl</link>
      <guid>https://dev.to/mr-lowlevel/windows-syscalls-direct-vs-indirect-and-why-malware-researchers-care-5fjl</guid>
      <description>&lt;p&gt;When I started working more deeply with Windows internals, one thing became obvious very quickly:&lt;/p&gt;

&lt;p&gt;If you only understand Win32 APIs, you are still looking at Windows from a fairly high level.&lt;/p&gt;

&lt;p&gt;Functions such as &lt;code&gt;VirtualAlloc&lt;/code&gt;, &lt;code&gt;VirtualProtect&lt;/code&gt;, &lt;code&gt;CreateThread&lt;/code&gt;, &lt;code&gt;NtAllocateVirtualMemory&lt;/code&gt;, and &lt;code&gt;NtProtectVirtualMemory&lt;/code&gt; eventually lead into the Windows kernel. The interesting part is what happens between the application and the kernel.&lt;/p&gt;

&lt;p&gt;That is where syscalls come in.&lt;/p&gt;

&lt;p&gt;For malware research, reverse engineering, EDR research, and offensive security, understanding this boundary is important because modern security products do not simply look at whether a process called a suspicious API.&lt;/p&gt;

&lt;p&gt;They look at what the process is actually doing.&lt;/p&gt;

&lt;p&gt;And this is also where the difference between direct and indirect syscalls becomes interesting.&lt;/p&gt;




&lt;h2&gt;
  
  
  First: AV is not the same as EDR
&lt;/h2&gt;

&lt;p&gt;I see these two terms mixed together quite often.&lt;/p&gt;

&lt;p&gt;Antivirus and EDR overlap, but they are not the same thing.&lt;/p&gt;

&lt;p&gt;Traditional antivirus has historically focused heavily on identifying malicious files, signatures, known patterns, suspicious behavior, and other indicators.&lt;/p&gt;

&lt;p&gt;Modern AV products do considerably more than simple signature matching, but the basic distinction is still useful.&lt;/p&gt;

&lt;p&gt;EDR is much more focused on visibility and behavioral telemetry.&lt;/p&gt;

&lt;p&gt;An EDR can observe things such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Process creation&lt;/li&gt;
&lt;li&gt;Parent-child process relationships&lt;/li&gt;
&lt;li&gt;Image loading&lt;/li&gt;
&lt;li&gt;Memory allocation&lt;/li&gt;
&lt;li&gt;Memory protection changes&lt;/li&gt;
&lt;li&gt;Thread creation&lt;/li&gt;
&lt;li&gt;Handle operations&lt;/li&gt;
&lt;li&gt;Registry activity&lt;/li&gt;
&lt;li&gt;File activity&lt;/li&gt;
&lt;li&gt;Network connections&lt;/li&gt;
&lt;li&gt;Authentication activity&lt;/li&gt;
&lt;li&gt;Suspicious sequences of behavior&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The important part is that an EDR does not necessarily care only about the API name.&lt;/p&gt;

&lt;p&gt;For example, imagine a process eventually causes executable memory to exist inside another process.&lt;/p&gt;

&lt;p&gt;Changing the exact API used does not magically make that behavior legitimate.&lt;/p&gt;

&lt;p&gt;The telemetry can still exist somewhere else.&lt;/p&gt;

&lt;p&gt;This is why syscall research should not be viewed simply as:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"How do I bypass EDR?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A better question is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Where does Windows transition from user mode into the kernel, and what can security software observe before and after that transition?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is the interesting part.&lt;/p&gt;




&lt;h1&gt;
  
  
  What is a syscall?
&lt;/h1&gt;

&lt;p&gt;A syscall is the mechanism used by user-mode software to request services from the Windows kernel.&lt;/p&gt;

&lt;p&gt;Applications normally execute in user mode.&lt;/p&gt;

&lt;p&gt;The Windows kernel executes in kernel mode.&lt;/p&gt;

&lt;p&gt;These are different privilege levels.&lt;/p&gt;

&lt;p&gt;User-mode applications cannot simply execute arbitrary kernel operations whenever they want. Instead, they request kernel services through defined interfaces.&lt;/p&gt;

&lt;p&gt;A simplified view looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
    |
    v
Win32 API
    |
    v
ntdll.dll
    |
    v
System Call
    |
    v
Windows Kernel
    |
    v
Kernel operation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, an application might call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;VirtualAlloc()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That eventually reaches lower-level Windows functionality.&lt;/p&gt;

&lt;p&gt;At the Native API layer you may encounter functions such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NtAllocateVirtualMemory()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Eventually the execution reaches the system-call boundary.&lt;/p&gt;

&lt;p&gt;The exact internal path depends on the operation and Windows version, but conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Mode
------------------------------------------------
Application
    |
    | Win32 API
    v
Kernel32 / KernelBase
    |
    v
ntdll.dll
    |
    | syscall transition
    v
------------------------------------------------
Kernel Mode
    |
    v
System service handling
    |
    v
Kernel implementation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important boundary is the transition between user mode and kernel mode.&lt;/p&gt;




&lt;h1&gt;
  
  
  What is inside ntdll?
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;ntdll.dll&lt;/code&gt; is extremely important when studying Windows internals.&lt;/p&gt;

&lt;p&gt;It contains a large portion of the Native API exposed to user-mode applications.&lt;/p&gt;

&lt;p&gt;You will encounter functions with names such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NtOpenProcess
NtAllocateVirtualMemory
NtProtectVirtualMemory
NtCreateThreadEx
NtReadVirtualMemory
NtWriteVirtualMemory
NtQueryInformationProcess
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These functions are not equivalent to the entire kernel implementation.&lt;/p&gt;

&lt;p&gt;They are user-mode entry points into the Native API.&lt;/p&gt;

&lt;p&gt;A simplified example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
    |
    v
NtAllocateVirtualMemory
    |
    v
syscall
    |
    v
Kernel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The interesting part is that the small user-mode stub eventually performs the transition into kernel mode.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why does the syscall number matter?
&lt;/h1&gt;

&lt;p&gt;Windows needs a way to identify which kernel service the caller is requesting.&lt;/p&gt;

&lt;p&gt;This is where the system service number comes into the picture.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Syscall instruction
        |
        +---- System Service Number
        |
        v
Kernel system-service dispatcher
        |
        v
Requested kernel service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will often see researchers referring to this as the SSN, or System Service Number.&lt;/p&gt;

&lt;p&gt;The important detail is that syscall numbers are not something you should treat as permanent constants across Windows versions.&lt;/p&gt;

&lt;p&gt;They can change between builds.&lt;/p&gt;

&lt;p&gt;That is one reason serious syscall research normally involves resolving the appropriate information for the running system rather than blindly assuming that a number from one Windows build will work everywhere.&lt;/p&gt;




&lt;h1&gt;
  
  
  What is a direct syscall?
&lt;/h1&gt;

&lt;p&gt;A direct syscall means that code in the process invokes the system-call transition without first calling the normal higher-level API path.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
    |
    v
Custom code
    |
    v
syscall
    |
    v
Kernel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
    |
    v
Win32 API
    |
    v
ntdll
    |
    v
syscall
    |
    v
Kernel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The distinction is important when studying user-mode monitoring.&lt;/p&gt;

&lt;p&gt;Security software can place instrumentation or hooks at different locations in user mode.&lt;/p&gt;

&lt;p&gt;For example, a security product may monitor certain functions inside &lt;code&gt;ntdll.dll&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A traditional API call could therefore look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
     |
     v
ntdll!NtSomething
     |
     v
EDR instrumentation / hook
     |
     v
syscall
     |
     v
Kernel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A direct syscall changes the user-mode path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
     |
     v
custom syscall stub
     |
     v
syscall
     |
     v
Kernel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is why direct syscalls became interesting in malware research.&lt;/p&gt;

&lt;p&gt;They can avoid certain user-mode interception points.&lt;/p&gt;

&lt;p&gt;But this does &lt;strong&gt;not&lt;/strong&gt; mean:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Direct syscalls bypass EDR."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That statement is too simplistic.&lt;/p&gt;

&lt;p&gt;They can bypass a particular user-mode hook or instrumentation point.&lt;/p&gt;

&lt;p&gt;They do not make the underlying operation invisible.&lt;/p&gt;




&lt;h1&gt;
  
  
  Direct syscalls do not make malware invisible
&lt;/h1&gt;

&lt;p&gt;This is one of the most important things to understand.&lt;/p&gt;

&lt;p&gt;Suppose a program performs suspicious memory operations.&lt;/p&gt;

&lt;p&gt;Changing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NtAllocateVirtualMemory()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to a custom syscall does not change the fact that memory was allocated.&lt;/p&gt;

&lt;p&gt;Likewise, changing the user-mode entry path does not automatically erase:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Kernel telemetry&lt;/li&gt;
&lt;li&gt;ETW-related visibility&lt;/li&gt;
&lt;li&gt;Process activity&lt;/li&gt;
&lt;li&gt;Memory state&lt;/li&gt;
&lt;li&gt;Thread activity&lt;/li&gt;
&lt;li&gt;Image information&lt;/li&gt;
&lt;li&gt;Handle activity&lt;/li&gt;
&lt;li&gt;Behavioral correlations&lt;/li&gt;
&lt;li&gt;Security callbacks&lt;/li&gt;
&lt;li&gt;Other EDR sensors&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Modern endpoint security is not dependent on a single hook.&lt;/p&gt;

&lt;p&gt;This is why I don't consider syscall techniques a magic "EDR bypass."&lt;/p&gt;

&lt;p&gt;They are better understood as a way of changing the execution path and reducing dependence on particular user-mode instrumentation points.&lt;/p&gt;




&lt;h1&gt;
  
  
  Then what is an indirect syscall?
&lt;/h1&gt;

&lt;p&gt;The terminology can be confusing.&lt;/p&gt;

&lt;p&gt;An indirect syscall generally refers to performing the syscall transition through a syscall instruction located in an existing legitimate &lt;code&gt;ntdll.dll&lt;/code&gt; syscall stub rather than placing the syscall instruction directly inside custom code.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Custom code
    |
    v
Resolve legitimate ntdll syscall stub
    |
    v
syscall instruction
    |
    v
Kernel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compare that with a direct approach:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Custom code
    |
    v
custom syscall stub
    |
    v
syscall
    |
    v
Kernel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The distinction is primarily about where the actual syscall transition occurs.&lt;/p&gt;

&lt;p&gt;This becomes interesting because the return address and surrounding user-mode execution context can look different from a completely custom syscall stub.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why are indirect syscalls interesting to EDR research?
&lt;/h1&gt;

&lt;p&gt;Imagine an EDR is monitoring a normal Native API function.&lt;/p&gt;

&lt;p&gt;The normal path might be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
    |
    v
ntdll!NtAllocateVirtualMemory
    |
    v
hook
    |
    v
syscall
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the process instead reaches a legitimate syscall instruction elsewhere in &lt;code&gt;ntdll&lt;/code&gt;, the execution path through the monitored function can be different.&lt;/p&gt;

&lt;p&gt;This is one reason indirect syscall techniques became popular in offensive security research.&lt;/p&gt;

&lt;p&gt;But again, this does not mean:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Indirect syscall = invisible
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It means:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Different user-mode execution path
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That distinction matters.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why do malware developers care about this?
&lt;/h1&gt;

&lt;p&gt;Malware is an excellent environment for understanding defensive technology because malware authors constantly try to understand where their activity becomes observable.&lt;/p&gt;

&lt;p&gt;For example, consider process injection.&lt;/p&gt;

&lt;p&gt;At a high level, the operation may involve:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Open target process
        |
        v
Allocate memory
        |
        v
Write data
        |
        v
Change memory protection
        |
        v
Create/execute a thread
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The API names can change.&lt;/p&gt;

&lt;p&gt;The syscall path can change.&lt;/p&gt;

&lt;p&gt;The implementation can change.&lt;/p&gt;

&lt;p&gt;But the underlying behavior remains.&lt;/p&gt;

&lt;p&gt;That is exactly why studying the syscall layer is useful.&lt;/p&gt;

&lt;p&gt;It teaches you to separate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;from:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;operation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and from:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;observable behavior
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those are three different things.&lt;/p&gt;




&lt;h1&gt;
  
  
  User-mode hooks
&lt;/h1&gt;

&lt;p&gt;One of the first concepts you encounter when studying EDR internals is user-mode hooking.&lt;/p&gt;

&lt;p&gt;A simplified example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Normal:

Application
    |
    v
NtFunction
    |
    v
syscall
    |
    v
Kernel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With instrumentation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
    |
    v
NtFunction
    |
    v
EDR hook
    |
    v
original function
    |
    v
syscall
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The hook gives the security product an opportunity to inspect the operation.&lt;/p&gt;

&lt;p&gt;Depending on the product and technique, it can collect information about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Calling process&lt;/li&gt;
&lt;li&gt;Arguments&lt;/li&gt;
&lt;li&gt;Call stack&lt;/li&gt;
&lt;li&gt;Target process&lt;/li&gt;
&lt;li&gt;Memory addresses&lt;/li&gt;
&lt;li&gt;Requested permissions&lt;/li&gt;
&lt;li&gt;Thread information&lt;/li&gt;
&lt;li&gt;Other contextual information&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is extremely useful for behavioral detection.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why malware researchers study clean ntdll
&lt;/h1&gt;

&lt;p&gt;When researching syscalls, one of the things researchers often examine is the syscall stub itself.&lt;/p&gt;

&lt;p&gt;A simplified Native API stub can conceptually look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NtFunction:
    move system service number
    prepare registers
    syscall
    return
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact instructions depend on the Windows architecture and version.&lt;/p&gt;

&lt;p&gt;Researchers can compare the in-memory implementation of &lt;code&gt;ntdll.dll&lt;/code&gt; with a known clean copy.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because security products may instrument user-mode functions.&lt;/p&gt;

&lt;p&gt;This is useful for both sides.&lt;/p&gt;

&lt;p&gt;An offensive researcher wants to understand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Where is the interception?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A defensive researcher wants to understand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;How can I detect when the normal execution path has been manipulated?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same technical knowledge applies to both.&lt;/p&gt;




&lt;h1&gt;
  
  
  Syscalls and call stacks
&lt;/h1&gt;

&lt;p&gt;Another important concept is the call stack.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
    |
    v
SomeFunction()
    |
    v
NtAllocateVirtualMemory()
    |
    v
syscall
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An EDR can potentially use stack information as part of its detection logic.&lt;/p&gt;

&lt;p&gt;If a syscall originates from an unusual memory region or an unexpected module, that itself can become suspicious.&lt;/p&gt;

&lt;p&gt;This is one reason simply replacing the normal API call with a syscall instruction does not automatically solve the problem.&lt;/p&gt;

&lt;p&gt;Security software can look at more than the immediate function.&lt;/p&gt;

&lt;p&gt;It can correlate context.&lt;/p&gt;




&lt;h1&gt;
  
  
  The kernel changes the game
&lt;/h1&gt;

&lt;p&gt;Once execution reaches kernel mode, the security model becomes very different.&lt;/p&gt;

&lt;p&gt;The kernel has access to information that user-mode code does not have.&lt;/p&gt;

&lt;p&gt;It can observe or participate in mechanisms surrounding:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Processes&lt;/li&gt;
&lt;li&gt;Threads&lt;/li&gt;
&lt;li&gt;Virtual memory&lt;/li&gt;
&lt;li&gt;Handles&lt;/li&gt;
&lt;li&gt;Drivers&lt;/li&gt;
&lt;li&gt;File systems&lt;/li&gt;
&lt;li&gt;Networking&lt;/li&gt;
&lt;li&gt;Security tokens&lt;/li&gt;
&lt;li&gt;System configuration&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is why modern EDR architecture is not simply:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hook API -&amp;gt; detect malware
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is closer to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        Process activity
              |
     +--------+--------+
     |        |        |
     v        v        v
 User-mode  Kernel   ETW / other
 telemetry  telemetry  telemetry
     |        |        |
     +--------+--------+
              |
              v
       Correlation engine
              |
              v
       Detection / response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact architecture differs between vendors, but the general idea is important.&lt;/p&gt;




&lt;h1&gt;
  
  
  Direct syscall vs indirect syscall
&lt;/h1&gt;

&lt;p&gt;A simple comparison:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Technique&lt;/th&gt;
&lt;th&gt;User-mode path&lt;/th&gt;
&lt;th&gt;Main research interest&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Normal API&lt;/td&gt;
&lt;td&gt;Win32 -&amp;gt; ntdll -&amp;gt; syscall&lt;/td&gt;
&lt;td&gt;Standard Windows execution&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Direct syscall&lt;/td&gt;
&lt;td&gt;Custom code -&amp;gt; syscall&lt;/td&gt;
&lt;td&gt;Avoid specific user-mode interception points&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Indirect syscall&lt;/td&gt;
&lt;td&gt;Custom code -&amp;gt; legitimate syscall stub -&amp;gt; syscall&lt;/td&gt;
&lt;td&gt;Different syscall execution path&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The important thing is not which one is "better."&lt;/p&gt;

&lt;p&gt;The important question is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What part of the security visibility model changes when the execution path changes?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is the question I care about when researching this topic.&lt;/p&gt;




&lt;h1&gt;
  
  
  Syscalls are not the same thing as Native APIs
&lt;/h1&gt;

&lt;p&gt;These terms are also frequently mixed together.&lt;/p&gt;

&lt;p&gt;Native API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NtCreateFile
NtOpenProcess
NtQueryInformationProcess
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Syscall:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The transition from user mode into kernel mode
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They are related, but they are not identical concepts.&lt;/p&gt;

&lt;p&gt;You can think about it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NtFunction
    |
    | user-mode interface
    v
syscall instruction
    |
    | privilege transition
    v
Windows kernel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Native API function is the user-mode interface.&lt;/p&gt;

&lt;p&gt;The syscall is the transition mechanism.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why I study this from a malware perspective
&lt;/h1&gt;

&lt;p&gt;I don't study syscalls just because they are commonly associated with malware.&lt;/p&gt;

&lt;p&gt;I study them because malware forces you to understand Windows at a deeper level.&lt;/p&gt;

&lt;p&gt;If I want to understand why a process injection technique is detected, I need to understand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What API was called?
        |
        v
What Native API was reached?
        |
        v
What syscall occurred?
        |
        v
What happened inside the kernel?
        |
        v
What telemetry was generated?
        |
        v
What behavior did the EDR correlate?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is much more useful than memorizing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Use this API to do X."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second approach teaches you a technique.&lt;/p&gt;

&lt;p&gt;The first teaches you the system.&lt;/p&gt;




&lt;h1&gt;
  
  
  The bigger lesson
&lt;/h1&gt;

&lt;p&gt;Direct and indirect syscalls are interesting because they expose an important weakness in simplistic security thinking.&lt;/p&gt;

&lt;p&gt;Security is not determined by the name of a function.&lt;/p&gt;

&lt;p&gt;Changing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;VirtualAlloc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NtAllocateVirtualMemory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;doesn't fundamentally change what the system is doing.&lt;/p&gt;

&lt;p&gt;Changing that again to a custom syscall does not fundamentally change the resulting kernel operation either.&lt;/p&gt;

&lt;p&gt;The execution path changes.&lt;/p&gt;

&lt;p&gt;The observability can change.&lt;/p&gt;

&lt;p&gt;The telemetry can change.&lt;/p&gt;

&lt;p&gt;But the underlying operation still exists.&lt;/p&gt;

&lt;p&gt;That is why modern EDR research is much more interesting than simply learning API hooking.&lt;/p&gt;

&lt;p&gt;You need to understand the entire chain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
      |
      v
Win32
      |
      v
Native API
      |
      v
Syscall
      |
      v
Kernel
      |
      v
System activity
      |
      v
Telemetry
      |
      v
EDR correlation
      |
      v
Detection / response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you understand that chain, direct and indirect syscalls stop looking like mysterious malware tricks.&lt;/p&gt;

&lt;p&gt;They become what they really are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;different ways of reaching the same operating-system boundary while changing parts of the user-mode execution path.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And that is exactly why they are worth studying.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;For me, syscall research is less about finding a magical way around an EDR and more about understanding where security visibility actually comes from.&lt;/p&gt;

&lt;p&gt;If an EDR hooks a user-mode function, I want to understand the hook.&lt;/p&gt;

&lt;p&gt;If malware avoids that hook, I want to understand the new execution path.&lt;/p&gt;

&lt;p&gt;If the EDR still detects the activity, I want to know which telemetry exposed it.&lt;/p&gt;

&lt;p&gt;If detection happens in the kernel, I want to understand the kernel-side visibility.&lt;/p&gt;

&lt;p&gt;That mindset turns syscall research into Windows internals research.&lt;/p&gt;

&lt;p&gt;And once you start looking at Windows this way, things like &lt;code&gt;ntdll&lt;/code&gt;, Native APIs, SSNs, system-service dispatching, user/kernel transitions, EPROCESS, threads, handles, memory management, and EDR telemetry all start connecting together.&lt;/p&gt;

&lt;p&gt;That is where the real learning begins.&lt;/p&gt;

</description>
      <category>edrinternals</category>
      <category>windowsinternals</category>
      <category>malwaredevelopment</category>
      <category>ethicalhacking</category>
    </item>
    <item>
      <title>What is API Hooking in a EDR?</title>
      <dc:creator>Piyusha Akash</dc:creator>
      <pubDate>Fri, 11 Sep 2026 13:16:10 +0000</pubDate>
      <link>https://dev.to/mr-lowlevel/what-is-api-hooking-in-a-edr-4eng</link>
      <guid>https://dev.to/mr-lowlevel/what-is-api-hooking-in-a-edr-4eng</guid>
      <description>&lt;p&gt;So you know there is a big different between Traditional Anti Virus and EDR (Endpoint Detection and Response) system.&lt;/p&gt;

&lt;p&gt;Traditional AV was mostly about finding known bad files, signatures, hashes and doing scans. But EDR is more about what is happening inside the system.&lt;/p&gt;

&lt;p&gt;For example, a process is running.&lt;/p&gt;

&lt;p&gt;It opens a file.&lt;/p&gt;

&lt;p&gt;It allocates memory.&lt;/p&gt;

&lt;p&gt;It creates another process.&lt;/p&gt;

&lt;p&gt;It loads a DLL.&lt;/p&gt;

&lt;p&gt;It starts a thread.&lt;/p&gt;

&lt;p&gt;It connects to a remote system.&lt;/p&gt;

&lt;p&gt;For an EDR, all these things can become useful information.&lt;/p&gt;

&lt;p&gt;But how does EDR actually see these things?&lt;/p&gt;

&lt;p&gt;One of the techniques used for user mode visibility is &lt;strong&gt;API hooking&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is API Hooking?
&lt;/h2&gt;

&lt;p&gt;API hooking basically means changing the normal execution path of a function so something else can observe or handle the call before the original function continues.&lt;/p&gt;

&lt;p&gt;Let's take a simple Windows API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;CreateFileW&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Normally your program calls &lt;code&gt;CreateFileW&lt;/code&gt;, and Windows handles the request.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
    |
    v
CreateFileW()
    |
    v
Windows
    |
    v
File System
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With a hook installed, the execution path can look more like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
    |
    v
CreateFileW()
    |
    v
EDR Hook
    |
    +----&amp;gt; Collect information
    |
    +----&amp;gt; Analyze the operation
    |
    v
Original CreateFileW()
    |
    v
Windows
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important part here is that the EDR is not necessarily replacing the entire Windows API.&lt;/p&gt;

&lt;p&gt;It can intercept the call, collect information about it, and then allow the original function to continue.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why would an EDR hook an API?
&lt;/h2&gt;

&lt;p&gt;Think about a process doing this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;CreateFileW&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;L"C:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;Users&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;Public&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;test.exe"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The EDR may be interested in things like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Which process made the call?
Which file is being accessed?
What operation is being performed?
What is the process doing before and after this?
Does this behavior look suspicious?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One API call alone usually does not tell the whole story.&lt;/p&gt;

&lt;p&gt;That is important.&lt;/p&gt;

&lt;p&gt;If a normal application opens a file, that does not mean the application is malicious.&lt;/p&gt;

&lt;p&gt;But imagine a process doing something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Open suspicious file
        |
Allocate executable memory
        |
Write data into memory
        |
Change memory permissions
        |
Create a thread
        |
Execute the memory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the EDR has a much more interesting sequence of events.&lt;/p&gt;

&lt;p&gt;This is one of the main ideas behind behavioral detection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where does the hook actually exist?
&lt;/h2&gt;

&lt;p&gt;This is where things become more interesting.&lt;/p&gt;

&lt;p&gt;On Windows, many applications interact with the operating system through user mode APIs.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
    |
    v
kernel32.dll
    |
    v
kernelbase.dll
    |
    v
ntdll.dll
    |
    v
System Call
    |
    v
Windows Kernel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact path depends on the API and Windows version, but &lt;code&gt;ntdll.dll&lt;/code&gt; is especially important because it contains the user mode system call stubs for many Native API functions.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NtCreateFile
NtOpenProcess
NtAllocateVirtualMemory
NtProtectVirtualMemory
NtWriteVirtualMemory
NtCreateThreadEx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An EDR operating in user mode can place hooks at different points in this path.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
    |
    v
WinAPI
    |
    v
EDR instrumentation
    |
    v
Native API
    |
    v
System call
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gives the EDR visibility into operations performed by applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inline Hooking
&lt;/h2&gt;

&lt;p&gt;One common type of API hook is an inline hook.&lt;/p&gt;

&lt;p&gt;The basic idea is simple.&lt;/p&gt;

&lt;p&gt;The beginning of a function is modified so execution is redirected somewhere else.&lt;/p&gt;

&lt;p&gt;For example, imagine a function starts like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Function:
    instruction 1
    instruction 2
    instruction 3
    instruction 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A hook can change the beginning so it becomes conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Function:
    JMP EDR_HANDLER
    instruction 2
    instruction 3
    instruction 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now when the program calls the function, execution first goes to the handler.&lt;/p&gt;

&lt;p&gt;Something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
     |
     v
Target Function
     |
     v
JMP
     |
     v
EDR Handler
     |
     v
Original Instructions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Of course, real implementations are more complicated than this.&lt;/p&gt;

&lt;p&gt;On x64 Windows, instruction boundaries, relative addressing, register state, calling conventions and executable memory all matter.&lt;/p&gt;

&lt;p&gt;You cannot just overwrite random bytes and expect everything to work.&lt;/p&gt;

&lt;h2&gt;
  
  
  What happens inside the hook?
&lt;/h2&gt;

&lt;p&gt;The hook can collect information about the current execution.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Process ID
Thread ID
Function being called
Arguments
Return value
Call stack
Loaded modules
Process information
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Depending on the EDR architecture, this information can be sent to another component for further processing.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Process
   |
   v
Hook
   |
   v
Telemetry
   |
   v
EDR Sensor
   |
   v
Detection Engine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The interesting part is the telemetry.&lt;/p&gt;

&lt;p&gt;The EDR is trying to build a picture of what the process is doing.&lt;/p&gt;

&lt;h2&gt;
  
  
  API Hooking is not the same thing as Kernel Monitoring
&lt;/h2&gt;

&lt;p&gt;This is a very important distinction.&lt;/p&gt;

&lt;p&gt;An EDR can have user mode components and kernel mode components.&lt;/p&gt;

&lt;p&gt;User mode hooking gives visibility into operations happening through hooked user mode functions.&lt;/p&gt;

&lt;p&gt;Kernel components can provide visibility much closer to the operating system itself.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 EDR
                  |
        +---------+---------+
        |                   |
    User Mode           Kernel Mode
        |                   |
     API Hooks          Kernel callbacks
        |                   |
        +---------+---------+
                  |
             Telemetry
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is one reason modern EDR products are much more complicated than simply putting hooks inside &lt;code&gt;kernel32.dll&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;They usually combine multiple visibility mechanisms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why API Hooking can be useful for EDR research
&lt;/h2&gt;

&lt;p&gt;If you want to understand EDR internals, API hooking is a good place to start because it forces you to understand what happens between an application and the Windows kernel.&lt;/p&gt;

&lt;p&gt;You start with something simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;CreateFileW&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you start asking questions.&lt;/p&gt;

&lt;p&gt;Where does this function actually live?&lt;/p&gt;

&lt;p&gt;What DLL exports it?&lt;/p&gt;

&lt;p&gt;Does it call another function?&lt;/p&gt;

&lt;p&gt;Does it eventually reach &lt;code&gt;ntdll.dll&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;What does the assembly look like?&lt;/p&gt;

&lt;p&gt;Where does the system call happen?&lt;/p&gt;

&lt;p&gt;What happens to the arguments?&lt;/p&gt;

&lt;p&gt;What happens when the function returns?&lt;/p&gt;

&lt;p&gt;You can investigate these questions with tools like WinDbg, System Informer and a debugger.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WinAPI
  |
  +-- kernel32.dll
  |
  +-- kernelbase.dll
  |
  +-- ntdll.dll
          |
          +-- Nt*
          |
          +-- syscall
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you understand this path, EDR internals start becoming much easier to understand.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do you identify a hook?
&lt;/h2&gt;

&lt;p&gt;This is where reverse engineering becomes useful.&lt;/p&gt;

&lt;p&gt;Suppose you expect the beginning of a function to look like normal Windows code.&lt;/p&gt;

&lt;p&gt;Instead, the first instructions look unusual.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Expected:

mov r10, rcx
mov eax, &amp;lt;SSN&amp;gt;
syscall
ret
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But the memory you are looking at contains a jump to another address.&lt;/p&gt;

&lt;p&gt;That is something worth investigating.&lt;/p&gt;

&lt;p&gt;The destination may belong to another module or another executable memory region.&lt;/p&gt;

&lt;p&gt;You can inspect:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Module name
Memory address
Memory protection
Instruction bytes
Call target
Call stack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A debugger can help you trace the execution.&lt;/p&gt;

&lt;p&gt;The goal is not simply:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"I found a JMP."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The interesting question is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Why is execution being redirected here?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is the difference between looking at bytes and actually doing reverse engineering.&lt;/p&gt;

&lt;h2&gt;
  
  
  What about malware and API hooking?
&lt;/h2&gt;

&lt;p&gt;Malware authors also care about API hooks.&lt;/p&gt;

&lt;p&gt;If a security product hooks a function inside a process, modifying or bypassing that hook can potentially change what the security product observes.&lt;/p&gt;

&lt;p&gt;This is one reason API hooking becomes an important subject when studying EDR internals.&lt;/p&gt;

&lt;p&gt;But there is another side to this.&lt;/p&gt;

&lt;p&gt;From the defender's point of view, attempts to interfere with security instrumentation can themselves become useful telemetry.&lt;/p&gt;

&lt;p&gt;So you can end up with something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;EDR installs instrumentation
          |
          v
Process executes
          |
          v
Suspicious behavior
          |
          v
Process interacts with instrumentation
          |
          v
EDR observes the activity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is why modern EDR research should not be reduced to "find the hook and remove it."&lt;/p&gt;

&lt;p&gt;The real question is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What visibility does the EDR have, where does that visibility come from, and what happens when one visibility mechanism is no longer available?&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  API Hooking is only one piece
&lt;/h2&gt;

&lt;p&gt;This is probably the most important thing to understand.&lt;/p&gt;

&lt;p&gt;A modern EDR is not just:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API Hooks = EDR
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is much closer to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 EDR
                  |
       +----------+----------+
       |          |          |
    User Mode  Kernel     Network
       |        Mode         |
       |          |          |
    API hooks  Callbacks   Traffic
       |          |          |
       +----------+----------+
                  |
              Telemetry
                  |
                  v
          Detection Engine
                  |
                  v
               Alert
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Different products use different combinations of technologies.&lt;/p&gt;

&lt;p&gt;Some visibility can happen in user mode.&lt;/p&gt;

&lt;p&gt;Some can happen in the kernel.&lt;/p&gt;

&lt;p&gt;Some information can come from Windows event sources, ETW, network telemetry, memory inspection and other sensors.&lt;/p&gt;

&lt;p&gt;That is why learning EDR internals requires learning Windows internals first.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I am studying next
&lt;/h2&gt;

&lt;p&gt;For me, API hooking is not really the final topic.&lt;/p&gt;

&lt;p&gt;It is the beginning of understanding how an EDR sees a process.&lt;/p&gt;

&lt;p&gt;The next questions become much more interesting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;How are hooks installed?

How are hooked functions detected?

How does the EDR capture arguments?

How does it collect call stacks?

How does it correlate multiple events?

What happens when a process does not use the expected API?

How does kernel telemetry complement user mode telemetry?

How does the EDR detect behavior instead of individual API calls?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And eventually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Process
   |
   v
User Mode
   |
   +---- API
   |
   +---- Native API
   |
   +---- Syscall
   |
   v
Kernel
   |
   v
EDR Telemetry
   |
   v
Detection
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Understanding this entire path is much more useful than simply memorizing API names.&lt;/p&gt;

&lt;p&gt;That is basically where I am starting my EDR internals research.&lt;/p&gt;

&lt;p&gt;API hooking is just one part of the bigger picture.&lt;/p&gt;

</description>
      <category>windowsinternals</category>
      <category>malwaredevelopment</category>
      <category>edrinternals</category>
      <category>ethicalhacking</category>
    </item>
  </channel>
</rss>
