From 1c1a9bc368555ccd29943f5991ae4572cca23245 Mon Sep 17 00:00:00 2001 From: Pyro57000 <147988717+Pyro57000@users.noreply.github.com> Date: Mon, 20 Nov 2023 10:56:07 -0600 Subject: [PATCH] eventually going to be my custom implant kit --- tetanous/Cargo.lock | 7 ++++ tetanous/Cargo.toml | 8 +++++ tetanous/src/main.rs | 76 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 tetanous/Cargo.lock create mode 100644 tetanous/Cargo.toml create mode 100644 tetanous/src/main.rs diff --git a/tetanous/Cargo.lock b/tetanous/Cargo.lock new file mode 100644 index 0000000..66c2635 --- /dev/null +++ b/tetanous/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "tetanous" +version = "0.1.0" diff --git a/tetanous/Cargo.toml b/tetanous/Cargo.toml new file mode 100644 index 0000000..dd56f5a --- /dev/null +++ b/tetanous/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "tetanous" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tetanous/src/main.rs b/tetanous/src/main.rs new file mode 100644 index 0000000..93266e6 --- /dev/null +++ b/tetanous/src/main.rs @@ -0,0 +1,76 @@ +use std::net::{TcpListener, TcpStream}; +use std::io::{BufRead, BufReader, Write}; +use std::thread; + + +fn handle_client(mut stream: TcpStream) { + // Read and print client input + let mut reader = BufReader::new(&stream); + loop { + let mut buffer = String::new(); + reader.read_line(&mut buffer).expect("Read error"); + if buffer.is_empty() { + break; + } + println!("Received: {}", buffer.trim()); + } +} + +fn main() { + // Listen for incoming connections on port 8080 + let listener = TcpListener::bind("127.0.0.1:8080").expect("Listen error"); + + // Store client connections in a vector + let mut clients: Vec = Vec::new(); + + // Accept incoming connections and spawn a new thread for each client + for stream in listener.incoming() { + match stream { + Ok(stream) => { + println!("New client connected: {:?}", stream.peer_addr().unwrap()); + clients.push(stream.try_clone().expect("Clone error")); + let mut client_idx = clients.len() - 1; + thread::spawn(move || { + handle_client(stream); + println!("Client disconnected: {:?}", clients[client_idx].peer_addr().unwrap()); + clients.remove(client_idx); + }); + } + Err(e) => { + println!("Connection error: {:?}", e); + } + } + } + + // Allow the user to switch between connections + loop { + let mut input = String::new(); + std::io::stdin().read_line(&mut input).expect("Read error"); + match input.trim() { + "list" => { + println!("Connected clients:"); + for (idx, client) in clients.iter().enumerate() { + println!("{}: {:?}", idx, client.peer_addr().unwrap()); + } + } + "switch" => { + println!("Enter client index:"); + let mut input = String::new(); + std::io::stdin().read_line(&mut input).expect("Read error"); + let client_idx = input.trim().parse::().expect("Parse error"); + if client_idx < clients.len() { + // TODO: Switch to selected client + println!("Switching to client: {:?}", clients[client_idx].peer_addr().unwrap()); + } else { + println!("Invalid client index"); + } + } + "exit" => { + break; + } + _ => { + println!("Invalid command"); + } + } + } +}