Contents

Bypass Address Space Layout Randomization (ASLR)

DLL Characteristics

To know if a PE file will use ASLR, you can check the DLL Characteristics in the Optional Header PE headers. If the field contains the value 0x0040( cf Microsoft Documentation - DLL characteristics), it means that the image base address can be relocated at load time.

For example, if we check with PE-bear:

/images/tips/bypass_aslr/2023-10-08-143417.png
PE Bear DLL characteritics
Warning
You can modify this value in a hex editor, however this is not recommended as you will modify the file itself and it may behave differently.

Rebase in Ghidra

If you are working on a sample in both a debugger and a disassembler, you can modify the image base address of the binary in the disassembler to have the same alignment than the one from memory found in the debugger.

First, find the virtual address in the debugger. In x64dbg, go to Memory Map, and then find the address related to the name of the sample:

/images/tips/bypass_aslr/2023-10-08-144705.png
x64dbg base image address

In Ghidra, go to Window -> Memory Map:

/images/tips/bypass_aslr/2023-10-08-155126.png
Memory map in Ghidra

Then click on the Home icon and specify the address in the new window:

/images/tips/bypass_aslr/2023-10-08-155310.png
Modify base address in Ghidra

Warning
This would need to be done every time the address changes (reboot of the system). This may not be the case when the program is restarted, as mentioned here: each DLL or EXE image gets assigned a random load address by the kernel the first time it is used, and as additional instances of the DLL or EXE are loaded, they receive the same load address. If all instances of an image are unloaded and that image is subsequently loaded again, the image may or may not receive the same base address. Only rebooting can guarantee fresh base addresses for all images systemwide.

Disable ASLR at Operating System level

In Windows, you can disable ALSR by going into the Exploit Protection security settings windows and disable all ASLR related settings:

/images/tips/bypass_aslr/2023-10-08-160742.png
Disable ASLR in Exploit Protection Windows Security settings

Note
Modifying those settings will require a system reboot for them to be applied.

References