up/src/shells.rs
2024-12-22 19:29:45 -08:00

28 lines
818 B
Rust

use axum::{
body::Body,
extract::Path,
http::{Request, StatusCode},
response::IntoResponse
};
use crate::config;
pub async fn shells_handler(Path(shell): Path<String>, req: Request<Body>) -> 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(&shell) {
Some(res) => {
let cmd = res.replace("{LHOST}", ip)
.replace("{LPORT}", &conf.shell_port.to_string());
(StatusCode::OK, cmd)
},
None => (StatusCode::NOT_FOUND, "Invalid shell name.".to_string()),
}
}