Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The full tokio port, Sadly there is no change in performance detected. #723

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,091 changes: 591 additions & 500 deletions Cargo.lock

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "rustscan"
version = "2.3.0"
authors = ["Autumn <[email protected]>"]
edition = "2018"
edition = "2021"
description = "Faster Nmap Scanning with Rust"
homepage = "https://github.com/rustscan/rustscan"
repository = "https://github.com/rustscan/rustscan"
Expand All @@ -17,38 +17,41 @@ exclude = [
]

[dependencies]
clap = { version = "4.5.13", features = ["derive", "wrap_help"] }
colored = "2.2.0"
async-std = "1.13.0"
tokio = { version = "1.43.0", features = ["full"] }
tokio-par-stream = "0.1.1"
blackrock2 = "0.1.0"
clap = { version = "4.5.26", features = ["derive", "wrap_help"] }
colored = "3.0.0"
futures = "0.3"
rlimit = "0.10.2"
log = "0.4.22"
env_logger = "0.11.6"
anstream = "=0.6.18"
dirs = "5.0.1"
gcd = "2.0.1"
rand = "0.8.5"
colorful = "0.3.2"
ansi_term = "0.12.1"
toml = "0.8.19"
serde = "1.0.124"
serde_derive = "1.0.116"
cidr-utils = "0.6.1"
itertools = "0.13.0"
itertools = "0.14.0"
hickory-resolver = { version = "0.24.2", features = ["dns-over-rustls"] }
anyhow = "1.0.40"
text_placeholder = { version = "0.5", features = ["struct_context"] }
once_cell = "1.20.2"

[dev-dependencies]
parameterized = "2.0.0"
wait-timeout = "0.2"
criterion = { version = "0.5", features = ["html_reports"] }
criterion = { version = "0.5", features = ["html_reports", "async_tokio"] }

[package.metadata.deb]
depends = "$auto, nmap"
section = "rust"

[profile.test]
debug = "full"


[profile.release]
lto = true
panic = 'abort'
Expand Down
45 changes: 18 additions & 27 deletions benches/benchmark_portscan.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
use async_std::task::block_on;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rustscan::input::{PortRange, ScanOrder};
use rustscan::port_strategy::PortStrategy;
use rustscan::scanner::Scanner;
use std::net::IpAddr;
use std::net::{IpAddr, Ipv4Addr};
use std::time::Duration;

fn portscan_tcp(scanner: &Scanner) {
let _scan_result = block_on(scanner.run());
}

fn portscan_udp(scanner: &Scanner) {
let _scan_result = block_on(scanner.run());
}

fn bench_address() {
let _addrs = ["127.0.0.1".parse::<IpAddr>().unwrap()];
}

fn bench_port_strategy() {
let range = PortRange {
start: 1,
end: 1_000,
};
let _strategy = PortStrategy::pick(&Some(range.clone()), None, ScanOrder::Serial);
let _strategy = PortStrategy::range(black_box(range), ScanOrder::Serial);
}

fn criterion_benchmark(c: &mut Criterion) {
let addrs = vec!["127.0.0.1".parse::<IpAddr>().unwrap()];
let addrs = [IpAddr::V4(Ipv4Addr::LOCALHOST)];
let range = PortRange {
start: 1,
end: 1_000,
};
let strategy_tcp = PortStrategy::pick(&Some(range.clone()), None, ScanOrder::Serial);
let strategy_udp = PortStrategy::pick(&Some(range.clone()), None, ScanOrder::Serial);
let strategy_tcp = PortStrategy::range(range, ScanOrder::Serial);
let strategy_udp = PortStrategy::range(range, ScanOrder::Serial);

let scanner_tcp = Scanner::new(
&addrs,
Expand All @@ -43,13 +30,19 @@ fn criterion_benchmark(c: &mut Criterion) {
false,
strategy_tcp,
true,
vec![],
&[],
false,
);

c.bench_function("portscan tcp", |b| {
b.iter(|| portscan_tcp(black_box(&scanner_tcp)))
let runtime = tokio::runtime::Runtime::new().unwrap();

let mut tcp_group = c.benchmark_group("portscan tcp");
tcp_group.measurement_time(Duration::from_secs(20));
tcp_group.sample_size(10);
tcp_group.bench_function("portscan tcp", |b| {
b.to_async(&runtime).iter(|| black_box(&scanner_tcp).run())
});
tcp_group.finish();

let scanner_udp = Scanner::new(
&addrs,
Expand All @@ -59,20 +52,18 @@ fn criterion_benchmark(c: &mut Criterion) {
false,
strategy_udp,
true,
vec![],
&[],
true,
);

let mut udp_group = c.benchmark_group("portscan udp");
udp_group.measurement_time(Duration::from_secs(20));
udp_group.sample_size(25);
udp_group.bench_function("portscan udp", |b| {
b.iter(|| portscan_udp(black_box(&scanner_udp)))
b.to_async(&runtime).iter(|| black_box(&scanner_udp).run())
});
udp_group.finish();

// Benching helper functions
c.bench_function("parse address", |b| b.iter(bench_address));


c.bench_function("port strategy", |b| b.iter(bench_port_strategy));
}

Expand Down
15 changes: 7 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fs::{self, File};

use std::env;
use std::io::{BufReader, Read};
use std::path::PathBuf;
use std::path::Path;
use std::process::Command;

// Reads in a file with payloads based on port
Expand Down Expand Up @@ -59,11 +59,11 @@ pub fn main() {
///
/// * `port_payload_map` - A BTreeMap mapping port numbers to payload data
fn generate_code(port_payload_map: BTreeMap<Vec<u16>, Vec<u8>>) {
let dest_path = PathBuf::from("src/generated.rs");
let dest_path = Path::new("src/generated.rs");

let mut generated_code = String::new();
generated_code.push_str("use std::collections::BTreeMap;\n");
generated_code.push_str("use once_cell::sync::Lazy;\n\n");
generated_code.push_str("use std::sync::LazyLock;\n\n");

generated_code.push_str("fn generated_data() -> BTreeMap<Vec<u16>, Vec<u8>> {\n");
generated_code.push_str(" let mut map = BTreeMap::new();\n");
Expand Down Expand Up @@ -92,7 +92,7 @@ fn generate_code(port_payload_map: BTreeMap<Vec<u16>, Vec<u8>>) {
generated_code.push_str("}\n\n");

generated_code.push_str(
"static PARSED_DATA: Lazy<BTreeMap<Vec<u16>, Vec<u8>>> = Lazy::new(generated_data);\n",
"static PARSED_DATA: LazyLock<BTreeMap<Vec<u16>, Vec<u8>>> = LazyLock::new(generated_data);\n",
);
generated_code.push_str("pub fn get_parsed_data() -> &'static BTreeMap<Vec<u16>, Vec<u8>> {\n");
generated_code.push_str(" &PARSED_DATA\n");
Expand All @@ -101,10 +101,9 @@ fn generate_code(port_payload_map: BTreeMap<Vec<u16>, Vec<u8>>) {
fs::write(dest_path, generated_code).unwrap();

// format the generated code
Command::new("cargo")
.arg("fmt")
.arg("--all")
.output()
Command::new("rustfmt")
.arg(dest_path)
.status()
.expect("Failed to execute cargo fmt");
}

Expand Down
Loading