File Header
Optional headers
Data Directories
Sections
typedef struct _IMAGE_OPTIONAL_HEADER {
WORD Magic;
BYTE MajorLinkerVersion;
BYTE MinorLinkerVersion;
DWORD SizeOfCode;
DWORD SizeOfInitializedData;
DWORD SizeOfUninitializedData;
DWORD AddressOfEntryPoint;
DWORD BaseOfCode;
DWORD BaseOfData;
DWORD ImageBase;
DWORD SectionAlignment;
DWORD FileAlignment;
WORD MajorOperatingSystemVersion;
WORD MinorOperatingSystemVersion;
WORD MajorImageVersion;
WORD MinorImageVersion;
WORD MajorSubsystemVersion;
WORD MinorSubsystemVersion;
DWORD Win32VersionValue;
DWORD SizeOfImage;
DWORD SizeOfHeaders;
DWORD CheckSum;
WORD Subsystem;
WORD DllCharacteristics;
DWORD SizeOfStackReserve;
DWORD SizeOfStackCommit;
DWORD SizeOfHeapReserve;
DWORD SizeOfHeapCommit;
DWORD LoaderFlags;
DWORD NumberOfRvaAndSizes;
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
} IMAGE_OPTIONAL_HEADER32, *PIMAGE_OPTIONAL_HEADER32;typedef struct _IMAGE_OPTIONAL_HEADER {
WORD Magic;
BYTE MajorLinkerVersion;
BYTE MinorLinkerVersion;
DWORD SizeOfCode;
DWORD SizeOfInitializedData;
DWORD SizeOfUninitializedData;
DWORD AddressOfEntryPoint;
DWORD BaseOfCode;
DWORD BaseOfData;
DWORD ImageBase;
DWORD SectionAlignment;
DWORD FileAlignment;
WORD MajorOperatingSystemVersion;
WORD MinorOperatingSystemVersion;
WORD MajorImageVersion;
WORD MinorImageVersion;
WORD MajorSubsystemVersion;
WORD MinorSubsystemVersion;
DWORD Win32VersionValue;
DWORD SizeOfImage;
DWORD SizeOfHeaders;
DWORD CheckSum;
WORD Subsystem;
WORD DllCharacteristics;
DWORD SizeOfStackReserve;
DWORD SizeOfStackCommit;
DWORD SizeOfHeapReserve;
DWORD SizeOfHeapCommit;
DWORD LoaderFlags;
DWORD NumberOfRvaAndSizes;
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
} IMAGE_OPTIONAL_HEADER32, *PIMAGE_OPTIONAL_HEADER32;NT Signatures
DOS STUB
MS DOS
This first header of a PE file is always prefixed with two bytes, 0x4D and 0x5A
ALWAYS REFERENCE:
1. Win32 API Documentation: https://visualstudio.microsoft.com/msdn-platforms/
Just search for the API name then MSDN next to it (e.g. CreateProcessA msdn)
2. Ntdoc: https://ntdoc.m417z.com/
Use this for NT API calls as some of them are not documented by Microsoft
3. Win32 Calc Shellcodes: https://github.com/peterferrie/win-exec-calc-shellcode
I like to use these shellcodes to test if my loader injection methods work
https://github.com/peterferrie/win-exec-calc-shellcode/blob/master/build/bin/win-exec-calc-shellcode-clean-func.bin
- Convert to hex using Shellcrypt: https://github.com/iilegacyyii/Shellcrypt
python .\shellcrypt.py -i 'win-exec-calc-shellcode-esp-clean-func.bin' -f c -e xor -k 00
TASKS:
- Simple MessageBox popup with Hello World, experiment with different flags
- Shellcode Execution via CreateRemoteThread
- Change CreateRemoteThread to a Fiber (OPTIONAL)
- Thread Hijacking
- Start process in suspended state
- Get handle to thread of created process
- Grab entrypoint
- Write shellcode into entrypoint
- Resume Thread
- PE Parsing
- Take executable path as argv
- List all header fields (DOS Headers, NT Headers, Image Headers, Opt. Headers, IAT, EAT)
- Self implementation of GetProcAddress and GetModuleHandle
Once you're done with these, see if you can build a modular loader that has different injection methods rolled into one project, I can send you a minimal version of this when youre ready
<@1406016700108767394>