diff --git a/src/main.rs b/src/main.rs index 0524c25..fb7deaf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use tokio::{ io::{AsyncReadExt, AsyncWriteExt}, net::{TcpListener, TcpStream}, }; -use tracing::{debug, error, info}; +use tracing::{debug, error, info, info_span, Instrument}; use ssh_protocol::{ connection::{ChannelOpen, ChannelOperationKind, ChannelRequestKind}, @@ -34,16 +34,26 @@ async fn main() -> eyre::Result<()> { loop { let next = listener.accept().await?; + let span = info_span!("connection", ?addr); + tokio::spawn( + async { + let mut total_sent_data = Vec::new(); - tokio::spawn(async { - if let Err(err) = handle_connection(next).await { - error!(?err, "error handling connection"); + if let Err(err) = handle_connection(next, &mut total_sent_data).await { + error!(?err, "error handling connection"); + } + + info!(data = ?String::from_utf8_lossy(&total_sent_data), "Finished connection"); } - }); + .instrument(span), + ); } } -async fn handle_connection(next: (TcpStream, SocketAddr)) -> Result<()> { +async fn handle_connection( + next: (TcpStream, SocketAddr), + total_sent_data: &mut Vec, +) -> Result<()> { let (mut conn, addr) = next; info!(?addr, "Received a new connection"); @@ -94,7 +104,7 @@ async fn handle_connection(next: (TcpStream, SocketAddr)) -> Result<()> { match update.kind { ChannelUpdateKind::Open(kind) => match kind { ChannelOpen::Session => { - session_channels.insert(update.number, 0); + session_channels.insert(update.number, ()); } }, ChannelUpdateKind::Request(req) => { @@ -113,8 +123,13 @@ async fn handle_connection(next: (TcpStream, SocketAddr)) -> Result<()> { let is_eof = data.contains(&0x03 /*EOF, Ctrl-C*/); // echo :3 - state - .do_operation(update.number.construct_op(ChannelOperationKind::Data(data))); + // state + // .do_operation(update.number.construct_op(ChannelOperationKind::Data(data))); + + // arbitrary limit + if total_sent_data.len() < 500_000 { + total_sent_data.extend_from_slice(&data); + } if is_eof { debug!(channel = ?update.number, "Received EOF, closing channel"); diff --git a/ssh-connection/src/lib.rs b/ssh-connection/src/lib.rs index 0829519..d215366 100644 --- a/ssh-connection/src/lib.rs +++ b/ssh-connection/src/lib.rs @@ -95,6 +95,8 @@ impl ServerChannelsState { } pub fn recv_packet(&mut self, packet: Packet) -> Result<()> { + // TODO: window + let mut packet = packet.payload_parser(); let packet_type = packet.u8()?; match packet_type { diff --git a/ssh-protocol/src/lib.rs b/ssh-protocol/src/lib.rs index 17864e3..9b8a1df 100644 --- a/ssh-protocol/src/lib.rs +++ b/ssh-protocol/src/lib.rs @@ -154,7 +154,9 @@ pub mod auth { self.queue_packet(Packet::new_msg_userauth_banner( b"!! this system ONLY allows catgirls to enter !!\r\n\ - !! all other attempts WILL be prosecuted to the full extent of the rawr !!\r\n", + !! all other attempts WILL be prosecuted to the full extent of the rawr !!\r\n\ + !! THIS SYTEM WILL LOG AND STORE YOUR CLEARTEXT PASSWORD !!\r\n\ + !! DO NOT ENTER PASSWORDS YOU DON'T WANT STOLEN !!\r\n", b"", ));