Cross-Compiling Exploit Code
To avoid compilation issues, it is general recommended to use native compilers
for the specific operating system targeted by the code;
however, this is not always an option.
In some scenarios, we might only have access to a single attack environment,
but need to leverage an exploit coded for a different platform.
In these cases, a cross-compiler can be extremely helpful.
We can use mingw-w64 to compile the code into a Windows Portable Executable file.
The first step is to determine if the exploit code compiles without errors.
We can do this by invoking the cross-compiler,
passing the C source file as the first argument,
and the output PE file name as the second argument, prepended by the -o parameter.
Something went wrong during the compilation process
although the errors may be unfamiliar, a simple Google search for the first error
related to “WSAStartup” reveals that this is a function found in winsock.h.
Further research indicates that these errors occur when the linker
cannot find the winsock library,
and that adding an extra parameter to the command should fix the problem.
This time, we produced an executable without generating any compilation errors.
We already know that this exploit targets a remotely-accessible vulnerability, which
means that our code needs to establish a connection to the target at some point.
Inspecting the C code,
we notice that it uses hard-coded values for the IP address and port fields:
These will be the first values we’ll need to adjust in our exploit.