| Crates.io | pmsf |
| lib.rs | pmsf |
| version | 0.1.0 |
| created_at | 2025-04-19 01:13:42.174339+00 |
| updated_at | 2025-04-19 01:13:42.174339+00 |
| description | Polymorphic Malware Stage Framework (PMSF): a research-grade Rust framework for simulating and analyzing modular malware stages. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1640207 |
| size | 55,273 |
⚠️ DISCLAIMER: This framework is a proof‑of‑concept for educational and research use only. The author does not condone or support malicious or unauthorized activities.
PMSF is a robust, research-grade Rust framework engineered for the simulation and analysis of modular malware stages. Designed with a focus on safety, extensibility, and clarity, PMSF empowers security researchers, educators, and students to explore advanced malware staging, evasion, and polymorphism techniques in a controlled, observable environment. All real-world actions are stubbed by default, ensuring a safe and risk-free experience for experimentation and learning.
⚠️ Security Warning
This framework is designed solely for safe simulation of malware stages in research and educational contexts.
Because PMSF is open source, it is possible for someone to modify the code to perform real malicious actions. Always review the code before running it, especially if you received it from an untrusted source.
To verify the code is safe:
- Open
src/lib.rs.- Search for the following function names:
establish_persistenceexecute_codecommunicate_c2perform_anti_analysis- Inside each function, look for comments like
// Placeholder.- If you see only logging and
Ok(())orOk(true)being returned, it's safe.- If you see real system calls, file operations, network connections, or anything that changes your system, that's a red flag.
Never run code you do not trust or understand.
rustmorphism crate to generate multiple binaries at build time, enabling diverse technique selection.config.toml).register_* functions.FrameworkError enum.StageContext abstraction.log crate and env_logger integration.TelemetryEvent trait for custom callbacks.run_*_chain, aggregating results and errors.weighted_random_choice) and conditional (environment/config) selection utilities for flexible technique orchestration.examples/demo.rs showcasing all major capabilities.Add this to your Cargo.toml:
[dependencies]
pmsf = "0.1.0"
Then import in Rust:
use pmsf::*;
use pmsf::{
establish_persistence_poly,
execute_code_poly,
communicate_c2_poly,
perform_anti_analysis_poly,
StageContext,
};
fn main() {
// Initialize a default stage context (no payload, empty metadata)
let ctx = StageContext::default();
// Select and execute the persistence stage
let persistence = establish_persistence_poly();
persistence.establish_persistence(&ctx).expect("Persistence stage failed");
// Select and execute the anti-analysis stage
let anti_analysis = perform_anti_analysis_poly();
anti_analysis.perform_anti_analysis(&ctx).expect("Anti-analysis stage failed");
// Select and execute the code execution stage
let execution = execute_code_poly();
execution.execute_code(&ctx).expect("Execution stage failed");
// Select and execute the C2 communication stage
let c2 = communicate_c2_poly();
c2.communicate_c2(&ctx).expect("C2 stage failed");
}
To customize stage selection, create a config.toml file in your project root. This allows you to explicitly specify which technique to use for each stage, or omit entries to enable random selection.
# config.toml
# Specify one technique per stage, or omit to use random selection.
persistence = "ScheduledTasks"
execution = "MappingInjection"
c2 = "DNSTunneling"
anti_analysis = "VMDetection"
Load the configuration at runtime:
let config = FrameworkConfig::from_file("config.toml");
println!("Loaded config: {:?}", config);
You can register your own custom technique at runtime, enabling rapid prototyping and extension:
// Define and implement your stage trait
struct MyTechnique;
impl PersistenceStage for MyTechnique { /* ... */ }
// Register it under a unique name
register_persistence("MyTechnique", || Box::new(MyTechnique));
// Retrieve and use the registered technique by name
if let Some(inst) = get_persistence_by_name("MyTechnique") {
inst.establish_persistence(&ctx)?;
}
PMSF supports integrated logging and custom telemetry callbacks for enhanced observability:
use log::LevelFilter;
use env_logger;
env_logger::builder().filter_level(LevelFilter::Info).init();
struct ConsoleTelemetry;
impl TelemetryEvent for ConsoleTelemetry {
fn on_event(&self, stage: &str, tech: &str, status: &str) {
println!("Telemetry: {}::{}, {}", stage, tech, status);
}
}
set_telemetry_callback(Box::new(ConsoleTelemetry));
All stages emit info! logs and trigger on_event(...) on success, or error! on failure.
You can execute multiple techniques in sequence and collect any errors for robust, multi-step simulations:
let errs = run_persistence_chain(&["RegistryRunKeys", "ScheduledTasks"]);
match errs {
Ok(_) => println!("All persistence steps succeeded."),
Err(e) => println!("Errors: {:?}", e),
}
PMSF provides utility functions for advanced technique selection:
weighted_random_choice(&[("A", 70), ("B", 30)])
select_technique_by_condition(&choices, "ENV_VAR")
Build and run the comprehensive demo:
cargo run --example demo
This example demonstrates config loading, registration, logging, telemetry, and chaining.
Issues, pull requests, and suggestions are welcome. Please follow standard Rust project conventions.
The MIT License — see LICENSE for details.