Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Using IDA Free, Part 3, Investigate Windows syscall

views
     
TSFlierMate
post Jun 12 2023, 11:19 PM, updated 3y ago

On my way
****
Validating
543 posts

Joined: Nov 2020
Today I will investigate syscall function in Windows. As we know, Windows library are provided through its API, but actually can skip the Windows API and use syscall directly, just like in Linux x64.
But the syscall numbers on Windows, from release to release, are not stable.

For syscall table in Windows, see: https://github.com/j00ru/windows-syscalls

So I will try my luck for my version of Windows, by debugging two EXEs (PE 64-bit) using IDA Freeware 8.3.

Below is the normal code for a program to exit with errorlevel 7:
CODE
format PE64 console
entry start

include "win64a.inc"

section ".code" code executable readable

start:

   mov  rcx, 7
   call [ExitProcess]

section ".idata" import readable

   library kernel, "kernel32.dll"

   import kernel, ExitProcess, "ExitProcess"


As you see from above, there is an extra section called "idata", which is import table mandatory for every Win32 programs to be useful.

But today I will just hack it so that the newly created program will be even smaller, and without the import table at all.

After loading the exit.exe (source code listed above), I step into "call [ExitProcess]", and this is what I entered into, RtlExitUserProcess:

RtlExitUserProcess
user posted image
user posted image

If I further step into NtTerminateProcess, this is what we see:
Now it uses "syscall" with ID "0x2C" (the syscall number varies from one release of Windows to another)

NtTerminateProcess
user posted image

After some investigation, I came up with this program, also exit with errorlevel 7:

CODE
format PE64 console
entry start

section ".code" code executable readable

start:

   mov rdx, 7
   or  rcx, 0xFFFFFFFFFFFFFFFF
  ;xor rcx, rcx
   mov r10, rcx
   mov rax, 0x2C
   syscall  


And after I load it in IDA Freeware, this is the output.

Disassembly of NtExit.exe (source code above):
user posted image

The file size:
CODE
Directory of C:\Users\BOO\Projects

06/12/2023  10:48 PM             1,536 exit.EXE
06/12/2023  10:59 PM             1,024 ntexit.EXE
              2 File(s)          2,560 bytes
              0 Dir(s)  91,136,335,872 bytes free


The NtExit.exe is without extra 512 bytes section of import table.

In summary, it is not practical to use syscall number directly in a Windows program, but I heard some malware are using it. @junyian @KLKS

Thank you for reading!


 

Change to:
| Lo-Fi Version
0.0143sec    0.38    6 queries    GZIP Disabled
Time is now: 25th November 2025 - 09:05 AM