Signatures

This commit is contained in:
perp 2023-08-01 01:16:15 +01:00
parent 49f3223ba7
commit ba76403abc
7 changed files with 9158 additions and 125 deletions

190
Cargo.lock generated
View File

@ -191,15 +191,27 @@ dependencies = [
"libc",
]
[[package]]
name = "getrandom"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "ghostport"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"serde",
"serde_json",
"rand",
"tokio",
"tracing",
"tracing-subscriber",
]
[[package]]
@ -232,10 +244,10 @@ dependencies = [
]
[[package]]
name = "itoa"
version = "1.0.9"
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
@ -259,6 +271,12 @@ dependencies = [
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
[[package]]
name = "memchr"
version = "2.5.0"
@ -285,6 +303,16 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
dependencies = [
"overload",
"winapi",
]
[[package]]
name = "num_cpus"
version = "1.16.0"
@ -310,6 +338,12 @@ version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "parking_lot"
version = "0.12.1"
@ -339,6 +373,12 @@ version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57"
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
version = "1.0.66"
@ -357,6 +397,36 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "redox_syscall"
version = "0.3.5"
@ -385,12 +455,6 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "ryu"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "scopeguard"
version = "1.2.0"
@ -398,34 +462,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "serde"
version = "1.0.176"
name = "sharded-slab"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76dc28c9523c5d70816e393136b86d48909cfb27cecaa902d338c19ed47164dc"
checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.176"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4e7b8c5dc823e3b90651ff1d3808419cd14e5ad76de04feaf37da114e7a306f"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c"
dependencies = [
"itoa",
"ryu",
"serde",
"lazy_static",
]
[[package]]
@ -470,6 +512,16 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "thread_local"
version = "1.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]]
name = "tokio"
version = "1.29.1"
@ -501,6 +553,64 @@ dependencies = [
"syn",
]
[[package]]
name = "tracing"
version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
dependencies = [
"cfg-if",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-log"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922"
dependencies = [
"lazy_static",
"log",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77"
dependencies = [
"nu-ansi-term",
"sharded-slab",
"smallvec",
"thread_local",
"tracing-core",
"tracing-log",
]
[[package]]
name = "unicode-ident"
version = "1.0.11"
@ -513,6 +623,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "valuable"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"

View File

@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0.72"
clap = { version = "4.3.19", features = ["derive"] }
serde = { version = "1.0.176", features = ["derive"] }
serde_json = "1.0.104"
rand = "0.8.5"
tokio = { version = "1", features = ["full"] }
tracing = "0.1.37"
tracing-subscriber = "0.3.17"

View File

@ -1,54 +0,0 @@
{
"payloads": [
"1 550 12345 0000000000000000000000000000000000000000000000000000000",
"2 550 12345 0000000000000000000000000000000000000000000000000000000",
"3 550 12345 0000000000000000000000000000000000000000000000000000000",
"4 550 12345 0000000000000000000000000000000000000000000000000000000",
"5 550 12345 0000000000000000000000000000000000000000000000000000000",
"6 550 12345 0ffffffffffffffffffffffffffffffffffffffffffffffffffff00",
"7 550 12345 0fffffffffffff777778887777777777cffffffffffffffffffff00",
"8 550 12345 0fffffffffff8000000000000000008888887cfcfffffffffffff00",
"9 550 12345 0ffffffffff80000088808000000888800000008887ffffffffff00",
"10 550 12345 0fffffffff70000088800888800088888800008800007ffffffff00",
"11 550 12345 0fffffffff000088808880000000000000088800000008fffffff000",
"12 550 12345 0ffffffff80008808880000000880000008880088800008ffffff000",
"13 550 12345 0ffffffff000000888000000000800000080000008800007fffff000",
"14 550 12345 0fffffff8000000000008888000000000080000000000007fffff000",
"15 550 12345 0ffffff70000000008cffffffc0000000080000000000008fffff000",
"16 550 12345 0ffffff8000000008ffffff007f8000000007cf7c80000007ffff000",
"17 550 12345 0fffff7880000780f7cffff7800f8000008fffffff80808807fff000",
"18 550 12345 0fff78000878000077800887fc8f80007fffc7778800000880cff000",
"19 550 12345 0ff70008fc77f7000000f80008f8000007f0000000000000888ff000",
"20 550 12345 0ff0008f00008ffc787f70000000000008f000000087fff8088cf000",
"21 550 12345 0f7000f800770008777000000000000000f80008f7f70088000cf000",
"22 550 12345 0f8008c008fff8000000000000780000007f800087708000800ff000",
"23 550 12345 0f8008707ff07ff8000008088ff800000000f7000000f800808ff000",
"24 550 12345 0f7000f888f8007ff7800000770877800000cf780000ff00807ff000",
"25 550 12345 0ff0808800cf0000ffff70000f877f70000c70008008ff8088fff000",
"26 550 12345 0ff70800008ff800f007fff70880000087f70000007fcf7007fff000",
"27 550 12345 0fff70000007fffcf700008ffc778000078000087ff87f700ffff000",
"28 550 12345 0ffffc000000f80fff700007787cfffc7787fffff0788f708ffff000",
"29 550 12345 0fffff7000008f00fffff78f800008f887ff880770778f708ffff000",
"30 550 12345 0ffffff8000007f0780cffff700000c000870008f07fff707ffff000",
"31 550 12345 0ffffcf7000000cfc00008fffff777f7777f777fffffff707ffff000",
"32 550 12345 0cccccff0000000ff000008c8cffffffffffffffffffff807ffff000",
"33 550 12345 0fffffff70000000ff8000c700087fffffffffffffffcf808ffff000",
"34 550 12345 0ffffffff800000007f708f000000c0888ff78f78f777c008ffff000",
"35 550 12345 0fffffffff800000008fff7000008f0000f808f0870cf7008ffff000",
"36 550 12345 0ffffffffff7088808008fff80008f0008c00770f78ff0008ffff000",
"37 550 12345 0fffffffffffc8088888008cffffff7887f87ffffff800000ffff000",
"38 550 12345 0fffffffffffff7088888800008777ccf77fc777800000000ffff000",
"39 550 12345 0fffffffffffffff800888880000000000000000000800800cfff000",
"40 550 12345 0fffffffffffffffff70008878800000000000008878008007fff000",
"41 550 12345 0fffffffffffffffffff700008888800000000088000080007fff000",
"42 550 12345 0fffffffffffffffffffffc800000000000000000088800007fff000",
"43 550 12345 0fffffffffffffffffffffff7800000000000008888000008ffff000",
"44 550 12345 0fffffffffffffffffffffffff7878000000000000000000cffff000",
"45 550 12345 0ffffffffffffffffffffffffffffffc880000000000008ffffff000",
"46 550 12345 0ffffffffffffffffffffffffffffffffff7788888887ffffffff000",
"47 550 12345 0ffffffffffffffffffffffffffffffffffffffffffffffffffff000",
"48 550 12345 00000000000000000000000000000000000000000000000000000000",
"49 550 12345 00000000000000000000000000000000000000000000000000000000",
"50 550 12345 00000000000000000000000000000000000000000000000000000000"
]
}

8964
signatures.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -5,11 +5,11 @@ use clap::Parser;
// CLI flags/arguments
pub struct Cli {
#[arg(
short = 'c',
long = "config",
short = 's',
long = "signatures",
value_name = "FILE",
help = "Path to the config",
default_value = "~/.config/ghostport/config.toml"
help = "Path to the signatures",
default_value = "signatures"
)]
pub config: String,
pub signatures: String,
}

View File

@ -1,20 +1,10 @@
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use std::fs;
// Entire config
#[derive(Clone, Serialize, Deserialize)]
pub struct Config {
// Payloads to send
pub payloads: Vec<String>,
}
// Read config file
pub fn read(path: &str) -> Result<Config> {
// Read signatures file
pub fn read_signatures(path: &str) -> Result<Vec<String>> {
// Read path
let content = fs::read_to_string(path)
.with_context(|| format!("Could not parse config file {}", path))?;
// Parse JSON
let config: Config = serde_json::from_str(&content)?;
Ok(config)
.with_context(|| format!("Could not read signatures file {}", path))?;
Ok(content.lines().map(String::from).collect())
}

View File

@ -1,5 +1,7 @@
use clap::Parser;
use rand::seq::SliceRandom;
use tokio::net::TcpListener;
use tracing::{debug, info, Level};
use cli::Cli;
@ -8,29 +10,43 @@ mod config;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Parse cli & read config
// Setup logger
tracing_subscriber::fmt()
.without_time()
.with_max_level(Level::DEBUG)
.init();
// Parse CLI
let cli = Cli::parse();
let config = config::read(&cli.config)?;
debug!("Parsed CLI flags");
// Read signatures file
let signatures = config::read_signatures(&cli.signatures)?;
debug!("Read signatures file");
// Bind listener
let listener = TcpListener::bind("127.0.0.1:8888").await?;
info!("Started listener");
loop {
// Accept connection
let (stream, _) = listener.accept().await?;
let config = config.clone();
let (stream, address) = listener.accept().await?;
debug!("Accepted connection");
// Clone signatures
let sigs = signatures.clone();
// Spawn async thread
tokio::spawn(async move {
// Go through payload line by line
for line in config.payloads {
// Format payload & write it
let payload = format!("{}\r\n", line);
match stream.try_write(payload.as_bytes()) {
Ok(n) => n,
Err(_) => return,
};
}
// Choose random signature
let signature = sigs.choose(&mut rand::thread_rng());
// Write signature
match stream.try_write(signature.expect("could not send signature").as_bytes()) {
Ok(n) => {
debug!("Sent signature {:?} to {}", signature, address);
n
}
Err(_) => return,
};
});
}
}