用于调查 Windows 系统调用的工具和 PoC。
Tools and PoCs for Windows syscall investigation.
This directory is for Heaven's Gate technique. See README.md
This tool is to dump Windows syscall from ntdll.dll or win32u.dll:
…To dump syscall numbers from ntdll.dll or win32u.dll, use -d (--dump) option.
If you don't specifies source DLL, this tool dumps syscall numbers from C:\Windows\System32\ntdll.dll and C:\Windows\System32\win32u.dll:
…If you want to filter syscall name from dump result, use -s (--search) option.
And you can save result to a file with -o (--output) option as follows:
…Using -n (--number) option, you can lookup syscall name by syscall number as follows.
If you want to specifies the syscall number in hex format, should be start with "0x".
…If you want to change output format, use -f (--format) option.
Currently, C/C++ (c), CSharp (cs) and Python (py) are supported:
…To take difference between 2 DLL's syscall tables, use -D (--diff) option as follows:
…The purpose of this project is to investigate how attackers resolve and execute Windows syscall.
All PoCs try to list kernel modules by NtQuerySystemInformation syscall.
| PoC Name | Description |
|---|---|
| PhysicalResolvePoC | This PoC simply resolves the syscall numbers of NtQuerySystemInformation from C:\Windows\System32\ntdll.dll. |
| HellsGatePoC | This PoC resolves the syscall numbers of NtQuerySystemInformation by the Hell's Gate technique. |
| HalosGatePoC | This PoC resolves the syscall numbers of NtQuerySystemInformation by the Halo's Gate technique. |
The purpose of this project is to help to learn how in-memory syscall number resolve techniques work:
| PoC Name | Description |
|---|---|
| HellsGateResolver | This PoC resolves the syscall numbers in ntdll.dll by the Hell's Gate technique. Not works for functions patched with anti-virus products. |
| HalosGateResolver | This PoC resolves the syscall numbers in ntdll.dll by the Halo's Gate technique. |
| InitialProcessResolver | This PoC resolves syscall numbers in ntdll.dll from initial process which created by NtCreateUserProcess. |
| KnownDllsResolver | This PoC resolves syscall numbers in ntdll.dll with \KnownDlls\ntdll.dll. |
The following figure shows the difference between Hell's Gate and Halo's Gate in anti-virus software installed environment.
Hell's Gate technique does not work for patched NtCreateProcessEx function.
On the other hand, Halo's Gate technique works for patched NtCreateProcessEx function:
In some anti-virus software installed machine, some ntdll.dll code is hooked as following debugger output:
0:001> u ntdll!ntcreateprocessex
ntdll!NtCreateProcessEx:
00007fff`b33ef700 e9930a1800 jmp 00007fff`b3570198
00007fff`b33ef705 cc int 3
00007fff`b33ef706 cc int 3
00007fff`b33ef707 cc int 3
00007fff`b33ef708 f604250803fe7f01 test byte ptr [SharedUserData+0x308 (00000000`7ffe0308)],1
00007fff`b33ef710 7503 jne ntdll!NtCreateProcessEx+0x15 (00007fff`b33ef715)
00007fff`b33ef712 0f05 syscall
00007fff`b33ef714 c3 retBut process which created by NtCreateUserProcess or NtCreateProcessEx are loaded only non-hooked ntdll.dll in initial state.
We can confirm it with scanning suspended initial process memory.
Suspended process cannot be attached with debugger, so I wrote a small tool ProcMemScan.
To test it, I implemented -d flag which can pause initial process to the InitialProcessResolver after syscall number detection:
PS C:\Dev> .\InitialProcessResolver.exe -n ntcreateprocessex -d
[>] Trying to create initial process.
[+] Initial process is created successfully.
[*] Process Name : svchost
[*] Process ID : 1336
[>] Trying to dump Nt API address.
[*] ntdll.dll @ 0x00007FFFB3350000
[+] Got 491 entries (Architecure: AMD64).
[+] NtCreateProcessEx @ 0x00007FFFB33EF700
[+] Syscall number for NtCreateProcessEx is 77 (0x4D).
[*] Debug break. To exit this program, hit [ENTER] key.We can confirm that the syscall number for NtCreateProcessEx is 77 from output, and svchost process is created by InitialProcessResolver is 1336.
By scanning this svchost with ProcMemScan, we can see that the svchost process loads only ntdll.dll as follows:
…And NtCreateProcessEx code is not hooked:
…In this script, following 3 functions are implemented:
Get-ModuleHandle : As the name implies, this function resolve loaded module's base address as GetModuleHandle API.
Get-ProcAddress : As the name implies, this function resolve export function's address as GetProcAddress API.
Get-SyscallNumber : This function resolve syscall number with Hell's Gate or Halo's Gate technique.
If you want to resolve module base address such as ntdll.dll, set the module name as 1st arguments or -ModuleName option:
PS C:\> Import-Module C:\dev\Get-SyscallNumber.ps1
PS C:\> Get-ModuleHandle ntdll.dll
140720055189504
PS C:\> (140720055189504).ToString("X16")
00007FFBF0E70000
PS C:\> Get-ModuleHandle -ModuleName kernel32.dll
140720022028288
PS C:\> (140720022028288).ToString("X16")
00007FFBEEED0000
PS C:\>To resolve export function address in a module, set base address of the module and export function name for Get-ProcAddress function.
The base address of the module should be specified with 1st argument or -Module option.
The export function name should be specified with 2nd argument or -ProcName option as follows:
PS C:\> $ntdll = Get-ModuleHandle -ModuleName ntdll.dll
PS C:\> Get-ProcAddress $ntdll NtCreateToken
140720055839008
PS C:\> (140720055839008).ToString("X16")
00007FFBF0F0E920
PS C:\> Get-ProcAddress -ProcName ntcreatetoken -Module $ntdll
140720055839008
PS C:\>If you want to know syscall number, set the syscall name to 1st argument or -SyscallName option for Get-SyscallNumber function:
PS C:\> Get-SyscallNumber ntcreateuserprocess
Syscall Number : 0xC8
200
PS C:\> Get-SyscallNumber -SyscallName ntcreateprocessex
Syscall Number : 0x4D
77
PS C:\>https://medium.com/@fsx30/hooking-heavens-gate-a-wow64-hooking-technique-5235e1aeed73
https://www.mandiant.com/resources/blog/wow64-subsystem-internals-and-hooking-techniques
https://www.malwaretech.com/2014/02/the-0x33-segment-selector-heavens-gate.html
https://modexp.wordpress.com/2015/11/19/dllpic-injection-on-windows-from-wow64-process/
Thanks for your research and blog posts:
Paul Laîné (@am0nsec)
smelly__vx (@smelly__vx)
reenz0h (@sektor7net)
Jack Halon (@jack_halon)
暂无开放 Issues,或尚未同步最近议题。