diff --git a/src/shells.rs b/src/shells.rs index e69de29..acb6018 100644 --- a/src/shells.rs +++ b/src/shells.rs @@ -0,0 +1,29 @@ +use std::net::SocketAddr; +use axum::{ + body::Body, + http::{Request, StatusCode}, + response::IntoResponse +}; + +use crate::config; + +fn replace_shell_params(cmd: &str, lhost: &str, lport: &u16) -> String { + cmd.replace("{LHOST}", lhost) + .replace("{LPORT}", &lport.to_string()) +} + +pub async fn shells_handler(req: Request) -> impl IntoResponse { + let conf = config::load_config(); + let Some(host) = req.headers() + .get("host") + .and_then(|v| v.to_str().ok()) else { + return (StatusCode::BAD_REQUEST, "Unable to determine LHOST.".to_string()); + }; + + let ip = host.split(":").next().unwrap(); + match conf.get_shell("bash") { + Some(res) => (StatusCode::OK, replace_shell_params(&res, ip, &conf.shell_port)), + None => (StatusCode::NOT_FOUND, "Invalid shell name.".to_string()), + } + +}