functionality offered by the operating system. In case of most UNIX systems, the asmcodes use
direct invocation of system calls through appropriate use of interrupts, gates or traps. The MS
Windows systems also export a set of system calls (may be invoked through 0x2e interrupt).
However, they have different architecture of OS kernel that us based on the concept of subsystems,
and in result there is no simple mapping of some operations (necessary for the asmcodes) to system
calls.
This is the main reason why the assembly components for MS Windows operating systems are
designed and implemented to use higher level functions located in dynamic libraries. This solution
has some additional advantage, as it enables easy access to extended functionality of Windows API
implemented in shared libraries.
1
In order to invoke any Windows API function, its actual address in memory space of a given
process must be known. Although MS Windows operating systems use mechanism of prelocated
libraries
2
, the base address (and therefore addresses of all of the exported functions) may differ in
case of various operating systems versions, installed service packs and last but not least versions
of the library itse lf. The development of methods for dynamic localization of function addresses in
any process is therefore one of the most critical issues, as it has direct impact on independence,
flexibility and effectiveness of the assembly component.
The most intuitive solution for finding addresses of required Windows API functions is connected
with the use of LoadLibrary() and GetProcAddress() routines from kernel32.dll library. The
first function enables loading any dynamic library to process memory s pace and returns a handler,
which in fact is the base address where the library was mapped. In order to retrieve an actual
address of any exported API function from the library, the GetProcAddress() function is used
with the base address provided as an argument. However there is still a problem, as to use these
two nice functions, the information about their actual addresses is also required.
There are several techniques for solving this problem. Hackers which tend to use the simplest and
often not elegant solutions, commonly hardcode these addresse s, what obviously limits the usage
to the systems of similar configurations or forces to tune the code during the attack. The most
commonly hardcoded address is the base of kernel32.dll library, from which the addresses of
LoadLibrary() and GetProcAddress() routines are later calculated at runtime. Sometimes, the
base address of spe cific application containing a vulnerability is hardcoded. In such a case, the im-
port table of the application is used during a runtime to obtain address of getmodulehandle() func-
tion, which is used further to retrieve the base address of kernel32.dll library. Next, the export ta-
ble of the kernel32.dll is used to obtain the addresses for LoadLibrary() and GetProcAddress()
routines.
There are obviously other techniques that retrieve the base address of kernel32.dll on the fly
and therefore achieve greater independence from the operating system and application versions.
These techniques are mainly used by virus coders and are based on scanning selected parts of
memory and looking for signatures of dynamic libraries headers ("PE\x00\x00" for PE format of
MS Windows executables and "MZ" in the case of MS-DOS) [1], [7]. The interesting way of using
this technique has been already introduced in one of earlier assembly c omponents for MS Windows
[4]. In that case, this technique was combined with automatic estimation of the base address of
loaded kernel32.dll library, by walking through SEH (Structured Exception Handling) chain and
looking for the address of library exception handling procedure.
However, it seems that the shortest and most effective technique for automatic localization of
addresses of the libraries mapped into process memory space is based on scanning through a list
of loaded modules, which is available in PEB (Process Environment Block) [10]. The application
of this technique enables retrieving the address of kernel32.dll library loaded into the address
1
For example, it is possible to download a file through HTTP protocol from any server with a call at a single
function.
2
The base address where library should be loaded is specified during link time and saved in the library.
7