Cross-compiler. Useful to compile exploit code.
Table of Contents
Installation
Kali Linux
sudo apt install mingw-w64
Windows
Download MinGW-w64 via MSYS2, which provides up-to-date native builds of GCC, MinGW-w64, and other helpful C++ tools and libraries.
Compilation

Command to use is dependent on the target’s architecture. Issue command “uname -m” on the target.
The prefix i686=32-bit x86_64=64-bit shows what kind of binaries the toolchain builds. The suffix shows what OS the toolchain is built for. If you need to build 32-bit binaries on Windows, it is recommended to use the i686…win32 package.
Compile C code (.c)
ls -la /usr/bin/*mingw*-gcc
Compile C code into Windows PE file
i686-w64-mingw32-gcc exploit.c -o exploit.exe
x86_64-w64-mingw32-gcc exploit.c -o exploit.exe
Compile C++ code (.cpp)
ls -la /usr/bin/*mingw*-g++
i686-w64-mingw32-g++ exploit.cpp -o exploit.exe
x86_64-w64-mingw32-g++ exploit.cpp -o exploit.exe
Multiple files
i686-w64-mingw32-g++ file1.cpp file2.cpp file3.cpp -o exploit.exe
Execute the compiled exploit
See Wine.
wine exploit.exe
Missing Libraries
When these libraries are part of the exploit code.
Windows.h
Replace “Windows.h” by “windows.h” in the code and retry compilation.
TLHelp32.h
wget https://raw.githubusercontent.com/Alexpux/mingw-w64/master/mingw-w64-headers/include/tlhelp32.h
winsock.h

Look for #pragma in .c file, it should contain the library to add! “ws2_32” is -lws2_32
grep winsock exploit.c
i686-w64-mingw32-gcc exploit.c -o exploit.exe -lws2_32
stdafx.h
cp /home/kali/lab/impacket-share/stdafx.h.gch .
Or:
nano stdafx.h
#include <string>
#include <stdio.h>
i686-w64-mingw32-g++ stdafx.h -o stdafx.h.gch
Then compile exploit as usual.
i686-w64-mingw32-g++ privesc.cpp -o privesc.exe
Reference
- Official Documentation (mingw-w64)
- Using GCC with MinGW (Visual Studio)