mirror of
https://github.com/Noratrieb/cluelessh.git
synced 2026-01-14 16:35:06 +01:00
improvements
This commit is contained in:
parent
193f762ae9
commit
890feee6d1
4 changed files with 33 additions and 27 deletions
10
src/main.rs
10
src/main.rs
|
|
@ -33,13 +33,13 @@ async fn main() -> eyre::Result<()> {
|
||||||
.parse::<SocketAddr>()
|
.parse::<SocketAddr>()
|
||||||
.wrap_err_with(|| format!("failed to parse listen addr '{addr}'"))?;
|
.wrap_err_with(|| format!("failed to parse listen addr '{addr}'"))?;
|
||||||
|
|
||||||
info!(?addr, "Starting server");
|
info!(%addr, "Starting server");
|
||||||
|
|
||||||
let listener = TcpListener::bind(addr).await.wrap_err("binding listener")?;
|
let listener = TcpListener::bind(addr).await.wrap_err("binding listener")?;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let next = listener.accept().await?;
|
let next = listener.accept().await?;
|
||||||
let span = info_span!("connection", addr = ?next.1);
|
let span = info_span!("connection", addr = %next.1);
|
||||||
tokio::spawn(
|
tokio::spawn(
|
||||||
async {
|
async {
|
||||||
let mut total_sent_data = Vec::new();
|
let mut total_sent_data = Vec::new();
|
||||||
|
|
@ -48,7 +48,7 @@ async fn main() -> eyre::Result<()> {
|
||||||
error!(?err, "error handling connection");
|
error!(?err, "error handling connection");
|
||||||
}
|
}
|
||||||
|
|
||||||
info!(stdin = ?String::from_utf8_lossy(&total_sent_data), "Finished connection");
|
info!(stdin = %String::from_utf8_lossy(&total_sent_data), "Finished connection");
|
||||||
}
|
}
|
||||||
.instrument(span),
|
.instrument(span),
|
||||||
);
|
);
|
||||||
|
|
@ -61,7 +61,7 @@ async fn handle_connection(
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let (mut conn, addr) = next;
|
let (mut conn, addr) = next;
|
||||||
|
|
||||||
info!(?addr, "Received a new connection");
|
info!(%addr, "Received a new connection");
|
||||||
|
|
||||||
//let rng = vec![
|
//let rng = vec![
|
||||||
// 0x14, 0xa2, 0x04, 0xa5, 0x4b, 0x2f, 0x5f, 0xa7, 0xff, 0x53, 0x13, 0x67, 0x57, 0x67, 0xbc,
|
// 0x14, 0xa2, 0x04, 0xa5, 0x4b, 0x2f, 0x5f, 0xa7, 0xff, 0x53, 0x13, 0x67, 0x57, 0x67, 0xbc,
|
||||||
|
|
@ -168,7 +168,7 @@ async fn handle_connection(
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_eof {
|
if is_eof {
|
||||||
debug!(channel = ?update.number, "Received EOF, closing channel");
|
debug!(channel = %update.number, "Received EOF, closing channel");
|
||||||
|
|
||||||
state.do_operation(update.number.construct_op(ChannelOperationKind::Close));
|
state.do_operation(update.number.construct_op(ChannelOperationKind::Close));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,12 @@ use ssh_transport::Result;
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct ChannelNumber(pub u32);
|
pub struct ChannelNumber(pub u32);
|
||||||
|
|
||||||
|
impl std::fmt::Display for ChannelNumber {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
std::fmt::Display::fmt(&self.0, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ServerChannelsState {
|
pub struct ServerChannelsState {
|
||||||
packets_to_send: VecDeque<Packet>,
|
packets_to_send: VecDeque<Packet>,
|
||||||
channel_updates: VecDeque<ChannelUpdate>,
|
channel_updates: VecDeque<ChannelUpdate>,
|
||||||
|
|
@ -115,7 +121,7 @@ impl ServerChannelsState {
|
||||||
Packet::SSH_MSG_GLOBAL_REQUEST => {
|
Packet::SSH_MSG_GLOBAL_REQUEST => {
|
||||||
let request_name = packet.utf8_string()?;
|
let request_name = packet.utf8_string()?;
|
||||||
let want_reply = packet.bool()?;
|
let want_reply = packet.bool()?;
|
||||||
debug!(?request_name, ?want_reply, "Received global request");
|
debug!(%request_name, %want_reply, "Received global request");
|
||||||
|
|
||||||
self.packets_to_send
|
self.packets_to_send
|
||||||
.push_back(Packet::new_msg_request_failure());
|
.push_back(Packet::new_msg_request_failure());
|
||||||
|
|
@ -127,7 +133,7 @@ impl ServerChannelsState {
|
||||||
let initial_window_size = packet.u32()?;
|
let initial_window_size = packet.u32()?;
|
||||||
let max_packet_size = packet.u32()?;
|
let max_packet_size = packet.u32()?;
|
||||||
|
|
||||||
debug!(?channel_type, ?sender_channel, "Opening channel");
|
debug!(%channel_type, %sender_channel, "Opening channel");
|
||||||
|
|
||||||
let update_message = match channel_type {
|
let update_message = match channel_type {
|
||||||
"session" => ChannelOpen::Session,
|
"session" => ChannelOpen::Session,
|
||||||
|
|
@ -170,7 +176,7 @@ impl ServerChannelsState {
|
||||||
kind: ChannelUpdateKind::Open(update_message),
|
kind: ChannelUpdateKind::Open(update_message),
|
||||||
});
|
});
|
||||||
|
|
||||||
debug!(?channel_type, ?our_number, "Successfully opened channel");
|
debug!(%channel_type, %our_number, "Successfully opened channel");
|
||||||
}
|
}
|
||||||
Packet::SSH_MSG_CHANNEL_DATA => {
|
Packet::SSH_MSG_CHANNEL_DATA => {
|
||||||
let our_channel = packet.u32()?;
|
let our_channel = packet.u32()?;
|
||||||
|
|
@ -219,7 +225,7 @@ impl ServerChannelsState {
|
||||||
let request_type = packet.utf8_string()?;
|
let request_type = packet.utf8_string()?;
|
||||||
let want_reply = packet.bool()?;
|
let want_reply = packet.bool()?;
|
||||||
|
|
||||||
debug!(?our_channel, ?request_type, "Got channel request");
|
debug!(%our_channel, %request_type, "Got channel request");
|
||||||
|
|
||||||
let channel = self.channel(our_channel)?;
|
let channel = self.channel(our_channel)?;
|
||||||
let peer_channel = channel.peer_channel;
|
let peer_channel = channel.peer_channel;
|
||||||
|
|
@ -234,10 +240,10 @@ impl ServerChannelsState {
|
||||||
let term_modes = packet.string()?;
|
let term_modes = packet.string()?;
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
?our_channel,
|
%our_channel,
|
||||||
?term,
|
%term,
|
||||||
?width_chars,
|
%width_chars,
|
||||||
?height_rows,
|
%height_rows,
|
||||||
"Trying to open a terminal"
|
"Trying to open a terminal"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -252,12 +258,12 @@ impl ServerChannelsState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"shell" => {
|
"shell" => {
|
||||||
info!(?our_channel, "Opening shell");
|
info!(%our_channel, "Opening shell");
|
||||||
ChannelRequest::Shell { want_reply }
|
ChannelRequest::Shell { want_reply }
|
||||||
}
|
}
|
||||||
"exec" => {
|
"exec" => {
|
||||||
let command = packet.string()?;
|
let command = packet.string()?;
|
||||||
info!(?our_channel, command = ?String::from_utf8_lossy(command), "Executing command");
|
info!(%our_channel, command = %String::from_utf8_lossy(command), "Executing command");
|
||||||
ChannelRequest::Exec {
|
ChannelRequest::Exec {
|
||||||
want_reply,
|
want_reply,
|
||||||
command: command.to_owned(),
|
command: command.to_owned(),
|
||||||
|
|
@ -267,7 +273,7 @@ impl ServerChannelsState {
|
||||||
let name = packet.utf8_string()?;
|
let name = packet.utf8_string()?;
|
||||||
let value = packet.string()?;
|
let value = packet.string()?;
|
||||||
|
|
||||||
info!(?our_channel, ?name, value = ?String::from_utf8_lossy(value), "Setting environment variable");
|
info!(%our_channel, %name, value = %String::from_utf8_lossy(value), "Setting environment variable");
|
||||||
|
|
||||||
ChannelRequest::Env {
|
ChannelRequest::Env {
|
||||||
want_reply,
|
want_reply,
|
||||||
|
|
@ -276,12 +282,12 @@ impl ServerChannelsState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"signal" => {
|
"signal" => {
|
||||||
debug!(?our_channel, "Received signal");
|
debug!(%our_channel, "Received signal");
|
||||||
// Ignore signals, something we can do.
|
// Ignore signals, something we can do.
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
warn!(?request_type, ?our_channel, "Unknown channel request");
|
warn!(%request_type, %our_channel, "Unknown channel request");
|
||||||
self.send_channel_failure(peer_channel);
|
self.send_channel_failure(peer_channel);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,9 +112,9 @@ pub mod auth {
|
||||||
let method_name = auth_req.utf8_string()?;
|
let method_name = auth_req.utf8_string()?;
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
?username,
|
%username,
|
||||||
?service_name,
|
%service_name,
|
||||||
?method_name,
|
%method_name,
|
||||||
"User trying to authenticate"
|
"User trying to authenticate"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -132,7 +132,7 @@ pub mod auth {
|
||||||
}
|
}
|
||||||
let password = auth_req.utf8_string()?;
|
let password = auth_req.utf8_string()?;
|
||||||
|
|
||||||
info!(?password, "Got password");
|
info!(%password, "Got password");
|
||||||
// Don't worry queen, your password is correct!
|
// Don't worry queen, your password is correct!
|
||||||
self.queue_packet(Packet::new_msg_userauth_success());
|
self.queue_packet(Packet::new_msg_userauth_success());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ impl ServerConnection {
|
||||||
self.packet_transport.recv_bytes(bytes)?;
|
self.packet_transport.recv_bytes(bytes)?;
|
||||||
|
|
||||||
while let Some(packet) = self.packet_transport.recv_next_packet() {
|
while let Some(packet) = self.packet_transport.recv_next_packet() {
|
||||||
trace!(packet_type = ?packet.payload.get(0), packet_len = ?packet.payload.len(), "Received packet");
|
trace!(packet_type = %packet.payload.get(0).unwrap_or(&0xFF), packet_len = %packet.payload.len(), "Received packet");
|
||||||
|
|
||||||
// Handle some packets ignoring the state.
|
// Handle some packets ignoring the state.
|
||||||
match packet.payload.get(0).copied() {
|
match packet.payload.get(0).copied() {
|
||||||
|
|
@ -148,7 +148,7 @@ impl ServerConnection {
|
||||||
let description = disconnect.utf8_string()?;
|
let description = disconnect.utf8_string()?;
|
||||||
let _language_tag = disconnect.utf8_string()?;
|
let _language_tag = disconnect.utf8_string()?;
|
||||||
|
|
||||||
info!(?reason, ?description, "Client disconnecting");
|
info!(%reason, %description, "Client disconnecting");
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
@ -169,8 +169,8 @@ impl ServerConnection {
|
||||||
Ok(expected)
|
Ok(expected)
|
||||||
} else {
|
} else {
|
||||||
Err(client_error!(
|
Err(client_error!(
|
||||||
"client does not supported algorithm {expected}. supported: {list:?}",
|
"client does not supported algorithm {expected}. supported: {list:?}",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -341,7 +341,7 @@ impl ServerConnection {
|
||||||
}
|
}
|
||||||
let mut p = Parser::new(&packet.payload[1..]);
|
let mut p = Parser::new(&packet.payload[1..]);
|
||||||
let service = p.utf8_string()?;
|
let service = p.utf8_string()?;
|
||||||
debug!(?service, "Client requesting service");
|
debug!(%service, "Client requesting service");
|
||||||
|
|
||||||
if service != "ssh-userauth" {
|
if service != "ssh-userauth" {
|
||||||
return Err(client_error!("only supports ssh-userauth"));
|
return Err(client_error!("only supports ssh-userauth"));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue