Skip to content

Maldev-Academy/TrapFlagForSyscalling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

TrapFlagForSyscalling: Bypass user-land hooks by syscall tampering via the Trap Flag


Quick Links

Maldev Academy Home

Maldev Academy Syllabus

Maldev Academy Pricing


What Is The Trap Flag

The Trap Flag (TF) is a special bit in the CPU's EFLAGS register that forces the processor to generate a single-step exception after every instruction. This behavior is commonly used in debugging to trace program flow one instruction at a time.


How Does It Work?

  • Locate the address of the target syscall, for example, NtAllocateVirtualMemory.
  • Enable the Trap Flag on the current thread using GetThreadContext and SetThreadContext.
  • Invoke the NtAllocateVirtualMemory syscall with random dummy parameters. When execution reaches the syscall instruction, the VEH will capture the syscall number of NtAllocateVirtualMemory.
  • Obtain the address of a whitelisted syscall. These are syscalls rarely monitored by security software, such as NtDrawText.
  • Call NtDrawText with the original parameters intended for NtAllocateVirtualMemory. Here, the VEH replaces the syscall number of NtDrawText with that of NtAllocateVirtualMemory when it reaches the syscall instruction.

This approach bypasses user-land hooks placed on NtAllocateVirtualMemory, while also feeding any security software hooking it with invalid, random parameters.


Usage

Use the INVOKE_SYSCALL macro by passing:

  • dwSyscallHash - The Murmur Hash of the target syscall.
  • STATUS - An NTSTATUS variable that will hold the result returned by the syscall.
  • ... - The actual parameters to be passed to the syscall identified by dwSyscallHash.


Demo

The image below showcases the invocation of NtAllocateVirtualMemory, NtProtectVirtualMemory, and NtCreateThreadEx syscalls using the INVOKE_SYSCALL macro.

image

About

Bypass user-land hooks by syscall tampering via the Trap Flag

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages