5 - On Cross Compilation
Topics
Introduction to the Windows Shells
Windows Permissions
Reverse Shells in Windows
SeImpersonatePrivilege Exploitation
On Cross Compilation
Windows Services
Weak Service Permissions
Unquoted Service Path
DLL Hijacking
Always Install Elevated
Files with Sensitive Data
Windows Hashes
Stored Credentials and the Windows Vault
Scheduled Task
Critical Registry Paths
Useful Tools
AMSI Bypass
On Compilation
Compilation is the process of translating source code written in a high-level programming language (e.g., C, C++, Python) into machine code that can execute on a specific CPU architecture.
Overview of the Compilation Process
Source code -> Compilation -> Binary
Binaries generated through compilation are tailored for a specific environment, which includes:
Hardware Architecture: The type of CPU (e.g., x86, ARM, MIPS).
Operating System: The platform (e.g., Windows, Linux, macOS).
User-Space Programs and Configurations: Dependencies, libraries, or runtime environments.
Modern compilation often involves several stages, such as preprocessing, parsing, optimization, and code generation, to produce efficient executables.
On Cross Compilation
Cross compilation refers to compiling source code on one system (the "host") to produce binaries for another system (the "target"). This technique is essential when the target environment differs from the host, such as:
Developing software for embedded systems (e.g., IoT devices).
Compiling Windows binaries on a Linux system.
This process requires a cross-compiler, which is a compiler configured to generate code for the target platform.
Compiling for Windows on Linux
Practical Example - Scenario
You are running Linux (which uses the ELF binary format) and need to compile a program to run on a Windows machine (which uses the PE binary format).
Key Binary Formats
ELF: Executable and Linkable Format (used on Linux).
PE: Portable Executable (used on Windows).
Example Source Code
Here is a simple hello.c
program:
Compiling for the Host Environment (Linux)
If you compile this code on Linux using gcc
, the output will be an ELF binary:
Check the binary format:
Output:
This binary will not work on a Windows machine.
Cross-Compiling for the Target Environment (Windows)
To compile for Windows, you need a cross-compiler such as mingw-w64. Install it on your Linux system:
Compile the program for Windows using the x86_64-w64-mingw32-g++
compiler:
Use
x86_64-w64-mingw32-g++
for 64-bit architectures.Use
i686-w64-mingw32-gcc
for 32-bit architectures.
Check the binary format of the output:
Output:
Transferring the Compiled Binary
Once the binary is ready, transfer it to the target Windows machine.
Using Netcat: On the Linux machine:
On the Windows machine:
Alternative Methods:
Use
scp
for secure transfer.Host an HTTP server on Linux (e.g.,
python3 -m http.server
) and download the file on Windows.
Disclaimer
❗ Never use tools and techniques on real IP addresses, hosts or networks without proper authorization!❗
Last updated