mirror of
https://github.com/Noratrieb/cluelessh.git
synced 2026-01-16 17:35:04 +01:00
trace
This commit is contained in:
parent
fe7407362b
commit
51fe414821
3 changed files with 29 additions and 10 deletions
33
src/main.rs
33
src/main.rs
|
|
@ -5,7 +5,7 @@ use tokio::{
|
||||||
io::{AsyncReadExt, AsyncWriteExt},
|
io::{AsyncReadExt, AsyncWriteExt},
|
||||||
net::{TcpListener, TcpStream},
|
net::{TcpListener, TcpStream},
|
||||||
};
|
};
|
||||||
use tracing::{debug, error, info};
|
use tracing::{debug, error, info, info_span, Instrument};
|
||||||
|
|
||||||
use ssh_protocol::{
|
use ssh_protocol::{
|
||||||
connection::{ChannelOpen, ChannelOperationKind, ChannelRequestKind},
|
connection::{ChannelOpen, ChannelOperationKind, ChannelRequestKind},
|
||||||
|
|
@ -34,16 +34,26 @@ async fn main() -> eyre::Result<()> {
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let next = listener.accept().await?;
|
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, &mut total_sent_data).await {
|
||||||
if let Err(err) = handle_connection(next).await {
|
error!(?err, "error handling connection");
|
||||||
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<u8>,
|
||||||
|
) -> Result<()> {
|
||||||
let (mut conn, addr) = next;
|
let (mut conn, addr) = next;
|
||||||
|
|
||||||
info!(?addr, "Received a new connection");
|
info!(?addr, "Received a new connection");
|
||||||
|
|
@ -94,7 +104,7 @@ async fn handle_connection(next: (TcpStream, SocketAddr)) -> Result<()> {
|
||||||
match update.kind {
|
match update.kind {
|
||||||
ChannelUpdateKind::Open(kind) => match kind {
|
ChannelUpdateKind::Open(kind) => match kind {
|
||||||
ChannelOpen::Session => {
|
ChannelOpen::Session => {
|
||||||
session_channels.insert(update.number, 0);
|
session_channels.insert(update.number, ());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ChannelUpdateKind::Request(req) => {
|
ChannelUpdateKind::Request(req) => {
|
||||||
|
|
@ -113,8 +123,13 @@ async fn handle_connection(next: (TcpStream, SocketAddr)) -> Result<()> {
|
||||||
let is_eof = data.contains(&0x03 /*EOF, Ctrl-C*/);
|
let is_eof = data.contains(&0x03 /*EOF, Ctrl-C*/);
|
||||||
|
|
||||||
// echo :3
|
// echo :3
|
||||||
state
|
// state
|
||||||
.do_operation(update.number.construct_op(ChannelOperationKind::Data(data)));
|
// .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 {
|
if is_eof {
|
||||||
debug!(channel = ?update.number, "Received EOF, closing channel");
|
debug!(channel = ?update.number, "Received EOF, closing channel");
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,8 @@ impl ServerChannelsState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn recv_packet(&mut self, packet: Packet) -> Result<()> {
|
pub fn recv_packet(&mut self, packet: Packet) -> Result<()> {
|
||||||
|
// TODO: window
|
||||||
|
|
||||||
let mut packet = packet.payload_parser();
|
let mut packet = packet.payload_parser();
|
||||||
let packet_type = packet.u8()?;
|
let packet_type = packet.u8()?;
|
||||||
match packet_type {
|
match packet_type {
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,9 @@ pub mod auth {
|
||||||
|
|
||||||
self.queue_packet(Packet::new_msg_userauth_banner(
|
self.queue_packet(Packet::new_msg_userauth_banner(
|
||||||
b"!! this system ONLY allows catgirls to enter !!\r\n\
|
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"",
|
b"",
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue