# πŸ› οΈ Developer Documentation: RouterSploit-Rust Framework > This document details the internal architecture, auto-dispatch system, proxy retry logic, and step-by-step guide to writing modules for the Rust rewrite of RouterSploit. --- ## 🧠 Framework Philosophy RouterSploit-Rust is a modular, async-capable, Rust-based rewrite of RouterSploit. Each module is standalone, invoked via: - πŸ“Ÿ CLI (`cargo run -- --command ...`) - πŸ–₯️ Shell (`rsf>` prompt) Goals: - πŸ”’ Safe-by-default - πŸ“¦ Cleanly separated modules - ⚑ Async concurrency - 🌐 Proxy-aware execution --- ## πŸ—‚οΈ Directory Structure ``` routersploit_rust/ β”œβ”€β”€ Cargo.toml β”œβ”€β”€ build.rs └── src/ β”œβ”€β”€ main.rs # Entrypoint β”œβ”€β”€ cli.rs # CLI argument parser β”œβ”€β”€ shell.rs # Interactive shell logic β”œβ”€β”€ commands/ # Module dispatch logic β”‚ β”œβ”€β”€ mod.rs β”‚ β”œβ”€β”€ scanner.rs β”‚ β”œβ”€β”€ scanner_gen.rs β”‚ β”œβ”€β”€ exploit.rs β”‚ β”œβ”€β”€ exploit_gen.rs β”‚ β”œβ”€β”€ creds_gen.rs β”‚ └── creds.rs β”œβ”€β”€ modules/ # All attack modules β”‚ β”œβ”€β”€ mod.rs β”‚ β”œβ”€β”€ exploits/ β”‚ β”œβ”€β”€ scanners/ β”‚ └── creds/ └── utils.rs # Common utilities ``` --- ## πŸ”— Module System Each module is a Rust file with a required `run()` entry point: ```rust pub async fn run(target: &str) -> anyhow::Result<()> ``` ### Optional: ```rust pub async fn run_interactive(target: &str) -> anyhow::Result<()> { // internal prompts or logic } ``` ### Placement: - Exploits: `src/modules/exploits/` - Scanners: `src/modules/scanners/` - Credentials: `src/modules/creds/` Subfolders are supported: - `exploits/routers/tplink.rs` β†’ `tplink` or `routers/tplink` - `scanners/http/title.rs` β†’ `title` or `http/title` --- ## βœ… Adding a New Module ### 1. Create File ```rust // src/modules/scanners/ftp_weak_login.rs use anyhow::Result; pub async fn run(target: &str) -> Result<()> { run_interactive(target).await } pub async fn run_interactive(target: &str) -> Result<()> { println!("[*] Checking FTP on {}", target); Ok(()) } ``` ### 2. Register in `mod.rs` ```rust pub mod ftp_weak_login; ``` --- ## 🧠 Auto-Dispatch System The CLI/shell can call: ```bash cargo run -- --command scanner --module ftp_weak_login --target 192.168.1.1 ``` Or in the shell: ``` rsf> use scanners/ftp_weak_login rsf> set target 192.168.1.1 rsf> run ``` Behind the scenes: 1. `build.rs` scans `src/modules/` recursively 2. Detects files with `pub async fn run(...)` 3. Generates: - `exploit_dispatch.rs` - `scanner_dispatch.rs` - `creds_dispatch.rs` 4. Registers short + full names (e.g., `ftp_weak_login` + `scanners/ftp_weak_login`) --- ## ❌ What Not To Do - ❌ No `run()` β†’ won’t dispatch - ❌ Don’t name multiple functions `run()` in one file - ❌ Don’t use `mod.rs` as a module β€” ignored by generator - ❌ Don’t forget to update `mod.rs` when adding modules --- ## βš™οΈ CLI Usage ```bash cargo run -- --command exploit --module my_exploit --target 10.0.0.1 ``` ### Args: - `--command`: exploit | scanner | creds - `--module`: file name of module - `--target`: IP or host --- ## πŸ–₯️ Shell Usage ```bash cargo run ``` Then: ``` rsf> help rsf> modules rsf> use scanners/ping_sweep rsf> set target 192.168.0.1 rsf> run ``` Maintains internal state: - `current_module` - `current_target` - `proxy_list` - `proxy_enabled` --- ## πŸ” Proxy Retry Logic (Shell Only) Proxy logic only applies in shell mode (`rsf>`). ### Flow: 1. User types `run` 2. Shell checks: - Module is selected? - Target is set? - Proxy enabled? --- ### Case 1: Proxy ON, Proxies LOADED - Create `HashSet` β†’ `tried_proxies` - Loop: - Pick random untried proxy - Set `ALL_PROXY` using: ```rust env::set_var("ALL_PROXY", proxy); ``` - Call `commands::run_module(...)` - On success: stop - On error: mark proxy as failed, try another - If all proxies fail: - Clear proxy env: ```rust env::remove_var("ALL_PROXY"); ``` - Try once directly --- ### Case 2: Proxy ON, No Proxies Loaded - Show warning - Clear `ALL_PROXY` - Run once directly --- ### Case 3: Proxy OFF - Clear proxy vars - Run module once --- ### Summary Flow: ``` If proxy_enabled: while untried proxies: pick β†’ set env β†’ run β†’ if fail β†’ mark tried if none work β†’ clear env β†’ try direct else: clear env β†’ try direct ``` --- ## πŸ§ͺ Module Execution Flow Whether via CLI or shell: 1. `commands::run_module(...)` 2. Determines type: `exploit`, `scanner`, or `cred` 3. Calls correct dispatcher 4. Dispatcher calls `run(target).await` 5. Output shown to user --- ## πŸ›‘ Error Handling - All modules must return `anyhow::Result<()>` - Errors are caught and shown cleanly in CLI or shell --- ## ⚑ Async Features - Entire framework is powered by `tokio` - All I/O modules are `async` - Use `tokio::spawn`, `FuturesUnordered`, etc. for concurrency --- ## πŸ“‘ Making Requests Use `reqwest`: ```rust let resp = reqwest::get(&url).await?.text().await?; ``` Or with client: ```rust let client = reqwest::Client::new(); let resp = client.post(&url).json(&data).send().await?; ``` βœ… All requests respect `ALL_PROXY` --- ## πŸ§ͺ Example Use Cases ### CLI ```bash cargo run -- --command creds --module ftp_weak_login --target 192.168.1.100 ``` ### Shell ```bash rsf> use creds/ftp_weak_login rsf> set target 192.168.1.100 rsf> run ``` --- ## 🧼 Shell Reset No session data persists. When restarted, shell forgets all settings β€” no saved targets or modules (by design). --- ## πŸ” Adapting CVEs To build a real-world exploit: - Convert PoC to async Rust logic - Validate by checking known response headers/content - Place it in the right folder and wire `run()` TCP/UDP logic: ```rust use tokio::net::{TcpStream, UdpSocket}; ``` --- ## πŸ’‘ Feature Roadmap add more exploits etc --- ## πŸ‘₯ Contributors - **Main Developer**: me. - **Language**: 100% Rust. - **Inspired by**: RouterSploit, Metasploit, pwntools. Would you like this exported as a `DEVELOPER_GUIDE.md` file now? I can generate it for you in exact GitHub-flavored markdown.