summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeuin <[email protected]>2023-07-28 01:22:46 +0800
committerKeuin <[email protected]>2023-07-28 01:25:06 +0800
commite353ec1ee62274d3d21ef250c0f33e876e0880d9 (patch)
tree7c4979e886f85919e136e75db001aec339129c69 /src
init version
Diffstat (limited to 'src')
-rw-r--r--src/main.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..96b6873
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,45 @@
+
+
+use clap::Parser;
+use tokio::net::UdpSocket;
+
+/// Simple program to greet a person
+#[derive(Parser, Debug)]
+#[command(author, version, about, long_about = None)]
+struct Args {
+ /// The address and port to listen and accept cleartext UDP datagrams from
+ #[arg(short, long)]
+ bind: String,
+
+ /// The destination to send obfuscated UDP datagrams to
+ #[arg(short, long)]
+ sendto: String,
+
+ /// The hex representation of XOR key to use
+ #[arg(short, long)]
+ key: String,
+}
+
+#[tokio::main]
+async fn main() {
+ let args = Args::parse();
+ let key = hex::decode(args.key)
+ .expect("failed to decode key hex string");
+ let sock = UdpSocket::bind(&args.bind).await
+ .expect("failed to bind UDP endpoint");
+ let mut buf = [0; 65536];
+ loop {
+ if let Ok((len, _)) = sock.recv_from(&mut buf).await {
+ let mut i = 0;
+ let n = key.len();
+ for j in 0..len {
+ buf[j] ^= key[i];
+ i += 1;
+ if i == n {
+ i = 0;
+ }
+ }
+ let _ = sock.send_to(&buf[..len], &args.sendto).await;
+ }
+ }
+}