From b6dfad22fb8b405e816e63430ac1cf0bb7ee5a63 Mon Sep 17 00:00:00 2001 From: Astro Date: Wed, 28 Sep 2022 17:09:51 +0200 Subject: [PATCH] randomize UNAME_RESPONSES --- Cargo.lock | 1 + Cargo.toml | 1 + src/handler.rs | 13 ++++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index f130c89..7af8c30 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1058,6 +1058,7 @@ dependencies = [ "env_logger", "futures", "log", + "rand 0.8.5", "russh", "russh-keys", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 076fbc4..2854f88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ log = "*" env_logger = "*" anyhow = "*" chrono = "0.4" +rand = "0.8" diff --git a/src/handler.rs b/src/handler.rs index 83c852a..d64f1f4 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -5,6 +5,7 @@ use std::pin::Pin; use futures::FutureExt; use log::info; +use rand::{Rng, thread_rng}; use russh::server::{Auth, Session}; use russh::*; @@ -23,6 +24,12 @@ enum CommandStatus { Scp, } +const UNAME_RESPONSES: &[&str] = &[ + "Linux fnordister 5.10.0-10-amd64 #1 SMP Debian 5.10.84-1 (2021-12-08) x86_64 GNU/Linux", + "Linux raspberrypi 5.19.9 #1-NixOS SMP Thu Sep 15 08:47:20 UTC 2022 aarch64 GNU/Linux", + "Linux OpenWrt 5.10.138 #0 Sat Sep 3 02:55:34 2022 mips GNU/Linux", +]; + pub struct Handler { filename: String, lazy_file: Option, @@ -66,7 +73,11 @@ impl Handler { match program { "whoami" => respond(&self.user), "id" => respond(&format!("uid=0({}) gid=0(root)", self.user)), - "uname" => respond("Linux fnordister 5.10.0-10-amd64 #1 SMP Debian 5.10.84-1 (2021-12-08) x86_64 GNU/Linux"), + "uname" => { + let mut rnd = thread_rng(); + let i = rnd.gen_range(0..UNAME_RESPONSES.len()); + respond(&UNAME_RESPONSES[i]); + } "pwd" => respond("/"), "ls" => { respond("drwxr-xr-x 18 root root 18 Jan 4 1969 .");