From 0c433943ffa6def6cb630057be9e311a1356d21d Mon Sep 17 00:00:00 2001 From: Simone Margaritelli Date: Wed, 31 Jan 2024 18:23:33 +0100 Subject: [PATCH] new: tcp.ports line grabber will send some data with newlines at the beginning --- src/plugins/tcp_ports/grabbers/line.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/plugins/tcp_ports/grabbers/line.rs b/src/plugins/tcp_ports/grabbers/line.rs index 87ea5f2..2b8ef70 100644 --- a/src/plugins/tcp_ports/grabbers/line.rs +++ b/src/plugins/tcp_ports/grabbers/line.rs @@ -1,4 +1,4 @@ -use tokio::io::AsyncReadExt; +use tokio::io::{AsyncReadExt, AsyncWriteExt}; use super::Banner; use crate::utils::net::StreamLike; @@ -29,13 +29,16 @@ async fn read_line_from(mut stream: Box) -> String { pub(crate) async fn line_grabber( address: &str, port: u16, - stream: Box, + mut stream: Box, timeout: Duration, ) -> Banner { log::debug!("grabbing line banner from {}:{} ...", address, port); let mut banner = Banner::default(); + // send something + let _ = stream.write_all("hello\r\n\r\n".as_bytes()).await; + let timeout = std::time::Duration::from_millis((timeout.as_millis() / 2) as u64); if let Ok(line) = tokio::time::timeout(timeout, read_line_from(stream)).await { if !line.is_empty() {