From 877d25beab88a784e33fb629c791210841c9a15b Mon Sep 17 00:00:00 2001 From: Nereuxofficial <37740907+Nereuxofficial@users.noreply.github.com> Date: Fri, 13 Oct 2023 10:52:55 +0200 Subject: [PATCH] fix: updated dependencies, fixed tcpconnect timeout --- Cargo.toml | 12 ++++++------ lib/packet_pool.toml | 5 +++++ lib/src/mqtt/mod.rs | 4 ++-- lib/src/network.rs | 11 ++++++++--- lib/src/runtime/mod.rs | 2 +- src/main.rs | 5 ++--- 6 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 lib/packet_pool.toml diff --git a/Cargo.toml b/Cargo.toml index 6e065d3..399c20b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ color-eyre = "0.6.2" tracing = "0.1.37" tracing-subscriber = "0.3.17" # Futures -tokio = { version = "1.32.0", features = ["full"] } +tokio = { version = "1.33.0", features = ["full"] } futures = "0.3.28" # Hex en/decoding hex = "0.4.3" @@ -26,15 +26,15 @@ mqtt-protocol = "0.11.2" rand = "0.8.5" rand_xoshiro = "0.6.0" # Command line interface -clap = { version = "4.4.3", features = ["derive"] } +clap = { version = "4.4.6", features = ["derive"] } # For serialization -serde = { version = "1.0.186", features = ["derive"] } -toml = "0.8.0" +serde = { version = "1.0.189", features = ["derive"] } +toml = "0.8.2" # For serialization of raw bytes -serde_with = {version="3.1.0", features = ["hex"]} +serde_with = {version="3.3.0", features = ["hex"]} # Tokio Console Support -console-subscriber = "0.1.10" +console-subscriber = "0.2.0" [profile.release] debug = true codegen-units = 1 diff --git a/lib/packet_pool.toml b/lib/packet_pool.toml new file mode 100644 index 0000000..894f8cc --- /dev/null +++ b/lib/packet_pool.toml @@ -0,0 +1,5 @@ +[inner."16,96,0,4,77,81,84,84,5,192,93,85,34,21,0,15,98,99,82,85,100,109,83,68,89,117,119,98,86,54,50,22,0,6,72,55,70,79,120,77,23,0,25,1,34,234,35,0,25,118,116,78,87,72,80,101,56,48,98,52,99,86,120,102,85,107,110,114,116,86,89,68,122,88,0,14,86,52,86,108,79,115,54,55,73,100,84,81,70,68,0,6,90,48,53,99,79,57,112,4,122,230,236,0,112,24,205,229,136,20,38,12,49,107,51,69,111,109,83,86,119,70,114,0,3,50,75,86,64,54,206,187,210,50,38,0,24,57,105,111,113,118,80,115,53,68,85,111,97,56,115,79,43,81,54,86,103,77,49,54,112,21,100,50,84,116,114,75,66,73,116,88,103,106,56,97,84,84,81,89,107,81,118"] +inner = ["16,96,0,4,77,81,84,84,5,192,93,85,34,21,0,15,98,99,82,85,100,109,83,68,89,117,119,98,86,54,50,22,0,6,72,55,70,79,120,77,23,0,25,1,34,234,35,0,25,118,116,78,87,72,80,101,56,48,98,52,99,86,120,102,85,107,110,114,116,86,89,68,122,88,0,14,86,52,86,108,79,115,54,55,73,100,84,81,70,68,0,6,90,48,53,99,79,57,112,4,122,230,236,0,112,24,205,229,136,20,38,12,49,107,51,69,111,109,83,86,119,70,114,0,3,50,75,86,64,54,206,187,210,50,38,0,24,57,105,111,113,118,80,115,53,68,85,111,97,56,115,79,43,81,54,86,103,77,49,54,112,21,100,50,84,116,114,75,66,73,116,88,103,106,56,97,84,84,81,89,107,81,118", "", "", "", "", "", "", "", "", ""] + +[inner."48,10,0,0,116,101,115,116,116,101,115,116"] +inner = ["16,60,0,4,77,81,84,84,4,4,0,0,0,17,72,101,108,108,111,32,77,81,84,84,32,66,114,111,107,101,114,0,5,116,111,112,105,99,0,22,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,72,255,50,0,0,0", "48,10,0,0,116,101,115,116,116,101,115,116", "224", "", "", "", "", "", "", ""] diff --git a/lib/src/mqtt/mod.rs b/lib/src/mqtt/mod.rs index a070637..a8b974a 100644 --- a/lib/src/mqtt/mod.rs +++ b/lib/src/mqtt/mod.rs @@ -38,8 +38,8 @@ pub(crate) fn generate_pingreq_packet() -> [u8; 2] { [192, 0] } -pub async fn test_conn_from_address(address: &str) -> color_eyre::Result<()> { - let mut stream = connect_to_broker(address).await?; +pub async fn test_conn_from_address(address: &str, timeout: u16) -> color_eyre::Result<()> { + let mut stream = connect_to_broker(address, timeout).await?; test_connection(&mut stream).await?; Ok(()) } diff --git a/lib/src/network.rs b/lib/src/network.rs index d1e6e0b..0719360 100644 --- a/lib/src/network.rs +++ b/lib/src/network.rs @@ -23,11 +23,16 @@ pub use tcp::*; #[cfg(feature = "tcp")] mod tcp { use super::*; + use std::time::Duration; use tokio::net::{TcpStream, ToSocketAddrs}; - pub async fn connect_to_broker(address: impl ToSocketAddrs) -> Result { - let tcpstream = TcpStream::connect(address).await?; - Ok(tcpstream) + pub async fn connect_to_broker(address: impl ToSocketAddrs, timeout: u16) -> Result { + let tcp_stream = tokio::time::timeout( + Duration::from_millis(timeout as u64), + TcpStream::connect(address), + ) + .await; + Ok(tcp_stream??) } } diff --git a/lib/src/runtime/mod.rs b/lib/src/runtime/mod.rs index 6d33b92..22e4119 100644 --- a/lib/src/runtime/mod.rs +++ b/lib/src/runtime/mod.rs @@ -29,7 +29,7 @@ pub async fn run_thread( let mut counter: u64 = 0; let mut rng = Xoshiro256PlusPlus::seed_from_u64(seed); while counter < iterations { - let new_stream = connect_to_broker(&address.clone()).await; + let new_stream = connect_to_broker(&address.clone(), timeout).await; if new_stream.is_err() { // Workaround for connections not being closed fast enough. See https://stackoverflow.com/questions/76238841/cant-assign-requested-address-in-request error!( diff --git a/src/main.rs b/src/main.rs index 35c1bc5..cc92c6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,6 @@ struct Cli { #[derive(Subcommand, Debug)] enum SubCommands { - // TODO: Do Fuzzing args like threads, chances etc Fuzz { #[arg(short, long, default_value_t = 100)] threads: u64, @@ -59,7 +58,7 @@ async fn main() -> color_eyre::Result<()> { } start_supervised_process(sender, cli.broker_command).await?; let address = cli.target.clone(); - test_conn_from_address(&address).await?; + test_conn_from_address(&address, cli.timeout).await?; info!("Connection established, starting fuzzing!"); let mut rng = thread_rng(); let _ = fs::create_dir("./threads").await; @@ -101,7 +100,7 @@ async fn main() -> color_eyre::Result<()> { subscribers.push(sender.subscribe()); } start_supervised_process(sender, cli.broker_command).await?; - test_conn_from_address(&cli.target).await?; + test_conn_from_address(&cli.target, cli.timeout).await?; debug!("Starting replay with {} seeds", filtered_files.len()); let mut threads = vec![]; let unused_it_channel = mpsc_channel::(filtered_files.len()).0;