Skip to main content

demo/
demo.rs

1//! # PMSF Framework Demo
2//!
3//! Demonstrates how to initialize the PMSF framework, load optional configuration,
4//! set up telemetry, and run chains of techniques for each stage.
5//!
6//! **Usage:**
7//! ```
8//! cargo run --example demo
9//! ```
10
11use env_logger;
12use log::LevelFilter;
13use pmsf::{
14    FrameworkConfig,
15    StageContext,
16    set_telemetry_callback,
17    TelemetryEvent,
18    run_persistence_chain,
19    run_execution_chain,
20    run_c2_chain,
21    run_anti_analysis_chain,
22};
23
24/// Simple telemetry implementation that prints events to the console.
25struct ConsoleTelemetry;
26
27impl TelemetryEvent for ConsoleTelemetry {
28    fn on_event(&self, stage: &str, technique: &str, status: &str) {
29        println!("[Telemetry] {}::{}, status={}", stage, technique, status);
30    }
31}
32
33fn main() {
34    // 1. Set up logging at INFO level
35    env_logger::builder().filter_level(LevelFilter::Info).init();
36
37    // 2. Register a telemetry callback for event monitoring
38    set_telemetry_callback(Box::new(ConsoleTelemetry));
39
40    // 3. Load configuration file if present (e.g., `config.toml` in project root)
41    let config = FrameworkConfig::from_file("config.toml");
42    println!("Loaded configuration: {:?}", config);
43
44    // 4. Prepare a default context for stages (no payload, empty metadata)
45    let ctx = StageContext { payload: None, metadata: Default::default() };
46
47    // 5. Demonstrate persistence stage chain
48    println!("--> Running persistence chain...");
49    let _ = run_persistence_chain(&["RegistryRunKeys", "ScheduledTasks"]);
50
51    // 6. Demonstrate execution stage chain
52    println!("--> Running execution chain...");
53    let _ = run_execution_chain(&["ClassicProcessInjection", "MappingInjection"]);
54
55    // 7. Demonstrate C2 stage chain
56    println!("--> Running C2 chain...");
57    let _ = run_c2_chain(&["HTTPSCommunication", "DNSTunneling"]);
58
59    // 8. Demonstrate anti-analysis stage chain
60    println!("--> Running anti-analysis chain...");
61    let _ = run_anti_analysis_chain(&["AntiDebugging", "VMDetection"]);
62
63    println!("Demo completed successfully.");
64}