From 7ccb819f867493f8ec202ea3b39c94c198c64584 Mon Sep 17 00:00:00 2001 From: JustSomePwner Date: Thu, 30 Aug 2018 14:01:54 +0200 Subject: first --- injector/main.cpp | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 injector/main.cpp (limited to 'injector/main.cpp') diff --git a/injector/main.cpp b/injector/main.cpp new file mode 100644 index 0000000..f3d3511 --- /dev/null +++ b/injector/main.cpp @@ -0,0 +1,121 @@ +#include +#include "winapi.h" + +const wchar_t* const kernel32_str = L"KERNEL32.DLL"; +const wchar_t* const ucrtbase_str = L"ucrtbase.dll"; +const char* const loadlib_str = "LoadLibraryA"; +const char* const printf_str = "printf"; + +const char* const printf_fmt = "print: %08x\n\0"; +const char* const fail_msg = "k32 null\n"; +const char* const pause_str = "pause"; +const char* const system_str = "system"; + +uintptr_t printf_addr = ( uintptr_t )&printf; +uintptr_t system_addr = 0; + +//i dont even +//unfinished btw + +__declspec( naked ) int print_var( uint32_t var ) { + __asm { + push ebp + mov ebp, esp + sub esp, __LOCAL_SIZE + + mov eax, var + push eax + push printf_fmt + call printf_addr + + add esp, 8 + mov esp, ebp + pop ebp + + mov eax, 0 + ret + } +} + +__declspec( naked ) void print_error( const char* err ) { + __asm { + push ebp + mov ebp, esp + sub esp, __LOCAL_SIZE + + mov eax, err + push eax + call printf_addr + + add esp, 8 + mov esp, ebp + pop ebp + } +} + +__declspec( naked ) int main( void ) { + void* k32; + void* ucrtbase; + uintptr_t loadlib; + + __asm { + push ebp + mov ebp, esp + sub esp, __LOCAL_SIZE + + mov eax, ds:ucrtbase_str + push eax + call winapi::k32::get_module_handle + add esp, 4 + mov ucrtbase, eax + + mov eax, ds:system_str + push eax + mov ecx, ucrtbase + push ecx + call winapi::k32::get_proc_address + add esp, 4 + mov system_addr, eax + + mov eax, ds:kernel32_str + push eax + call winapi::k32::get_module_handle + add esp, 4 + mov k32, eax + + mov eax, k32 + push eax + call print_var + + cmp k32, 0 + je K32_FAIL + + mov eax, ds:loadlib_str + push eax + mov ecx, k32 + push ecx + call winapi::k32::get_proc_address + + add esp, 8 + mov loadlib, eax + + mov eax, loadlib + push eax + call print_var + + jmp END + + K32_FAIL: + mov eax, fail_msg + push eax + call printf_addr + + END: + mov eax, pause_str + push eax + call system_addr + mov esp, ebp + pop ebp + ret + } +} \ No newline at end of file -- cgit v1.2.3