Compare commits

..
Author SHA1 Message Date
Brandon 9717fc661f Merge pull request #174 from caass/patch-1
Allow compilation on windows (#171)
2020-08-27 20:36:29 +01:00
Cassandra Fridkin a0119cbece Skip tests that deal with ulimit on windows 2020-08-27 14:45:08 -04:00
Cassandra Fridkin 7a3d900eed Revert "Try to DRY out code"
This reverts commit 87b802d7ae.
2020-08-27 14:32:43 -04:00
Cassandra Fridkin 87b802d7ae Try to DRY out code 2020-08-27 14:23:13 -04:00
Cass 69bdff2ce2 semicolon
that's what i get for using github to edit the file smh
2020-08-27 14:13:37 -04:00
Cass 0a8d108c3a Add a windows-specific warning
We should probably let folks know it's gonna be slow that the Docker alternative exists.
2020-08-27 13:19:08 -04:00
Cass 24c713a634 Allow compilation on windows (#171) 2020-08-27 13:14:25 -04:00
Brandon 1745be38ce conditional use statement in main 2020-08-27 12:11:23 +01:00
Brandon 07c0236a75 cargo fmt 2020-08-27 11:48:54 +01:00
Brandon b91d632657 made windows conditional import 2020-08-27 11:37:44 +01:00
Brandon 7df1b72e0c changed rlimit typehint to u32 2020-08-27 00:59:32 +01:00
Brandon 4bbd3943bd changes
that enable windows support
2020-08-26 17:04:23 +01:00
10 changed files with 56 additions and 176 deletions

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@ language: rust
os:
- linux
- osx
# - windows
- windows
arch:
- amd64
Generated
-16
View File
@@ -774,7 +774,6 @@ dependencies = [
"rlimit",
"shell-words",
"structopt",
"toml",
]
[[package]]
@@ -783,12 +782,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
[[package]]
name = "serde"
version = "1.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3"
[[package]]
name = "shell-words"
version = "1.0.0"
@@ -881,15 +874,6 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "toml"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a"
dependencies = [
"serde",
]
[[package]]
name = "unicode-segmentation"
version = "1.6.0"
+3 -5
View File
@@ -21,19 +21,17 @@ colored = "2.0.0"
structopt = "0.3.16"
async-std = "1.6.3"
futures = "0.3"
rlimit = "0.4.0"
shell-words = "1.0.0"
log = "0.4.0"
env_logger = "0.7.1"
dirs = "3.0.1"
toml = "0.5.6"
gcd = "2.0.1"
rand = "0.7.3"
colorful = "0.2.1"
ansi_term = "0.12.1"
ureq = "1.3.0"
serde = "1.0.115"
serde_derive = "1.0.115"
[target."cfg(not(windows))".dependencies]
rlimit = "0.4.0"
[package.metadata.deb]
depends = "$auto, nmap"
+10 -28
View File
@@ -213,25 +213,23 @@ rustscan -h
```
```
rustscan 1.7.1
Fast Port Scanner built in Rust. WARNING Do not use this program against sensitive infrastructure since the specified
server may not be able to handle this many socket connections at once. - Discord https://discord.gg/GFrQsGy - GitHub
https://github.com/RustScan/RustScan
USAGE:
rustscan [FLAGS] [OPTIONS] <ips-or-hosts>... [-- <command>...]
rustscan [FLAGS] [OPTIONS] <ips>... [-- <command>...]
FLAGS:
-a, --accessible
-h, --help Prints help information
-q, --quiet Quiet mode. Only output the ports. No Nmap. Useful for grep or outputting to a file
-V, --version Prints version information
-h, --help Prints help information
-q, --quiet Quiet mode. Only output the ports. No Nmap. Useful for grep or outputting to a file
-V, --version Prints version information
OPTIONS:
-b, --batch-size <batch-size> The batch size for port scanning, it increases or slows the speed of scanning.
Depends on the open file limit of your OS. If you do 65535 it will do every port
at the same time. Although, your OS may not support this [default: 4500]
-p, --ports <ports>... A list of comma separed ports to be scanned. Example: 80,443,8080.
-r, --range <range> A range of ports with format start-end. Example: 1-1000
--scan-order <scan-order> The order of scanning to be performed. The "serial" option will scan ports in
ascending order while the "random" option will scan ports randomly [default:
serial] [possible values: Serial, Random]
@@ -239,11 +237,11 @@ OPTIONS:
-u, --ulimit <ulimit> Automatically ups the ULIMIT with the value you provided
ARGS:
<ips-or-hosts>... A list of comma separated IP addresses or hosts to be scanned
<command>... The Nmap arguments to run. To use the argument -A, end RustScan's args with '-- -A'.
Example: 'rustscan -T 1500 127.0.0.1 -- -A -sC'. This command adds -Pn -vvv -p $PORTS
automatically to nmap. For things like --script '(safe and vuln)' enclose it in quotations
marks \"'(safe and vuln)'\"")
<ips>... A list of comma separated IP addresses to be scanned
<command>... The Nmap arguments to run. To use the argument -A, end RustScan's args with '-- -A'. Example:
'rustscan -T 1500 127.0.0.1 -- -A -sC'. This command adds -Pn -vvv -p $PORTS automatically to
nmap. For things like --script '(safe and vuln)' enclose it in quotations marks \"'(safe and
vuln)'\"")
```
The format is `rustscan -b 500 -T 1500 192.168.0.1` to scan 192.168.0.1 with 500 batch size with a timeout of 1500ms. The timeout is how long RustScan waits for a response until it assumes the port is closed.
@@ -340,22 +338,6 @@ To increase accuracy, the easiest way is to increase the timeout. The default is
Decreasing accuracy gives some speed bonus, but my testing found that batch size dramatically changed the speed whereas timeout did, but not so much.
## 🤖 Config File
RustScan uses a Config file to make things easier for you. And to also improve itself.
The config file is used as the basis of the _adaptive learning_ mechanisms. This means that RustScan _learns_ from your scans and improves itself over time. (Don't worry, no bloated AI framework here 😉)
The config file should be placed in APPDIRS. To find this folder, run RustScan and look out for RustScan saying "couldn't find config at <location>". That location is where your config file should be.
Once you have this location, copy and paste this:
```toml
# The top ports
[top_ports]
80, 60, 443
```
# 🎪 Community
Howdy Space Cow-Person 🤠🌌
-28
View File
@@ -1,28 +0,0 @@
FROM archlinux:latest
RUN yes | pacman -Syu
RUN yes | pacman -S fakeroot binutils sudo make gcc gettext awk git
WORKDIR /opt
RUN git clone https://aur.archlinux.org/yay-git.git
RUN useradd -m tecmint
RUN passwd -d tecmint
RUN printf 'tecmint ALL=(ALL) ALL\n' | tee -a /etc/sudoers
WORKDIR /opt/yay-git
RUN chown -R tecmint /opt/yay-git
USER tecmint
RUN makepkg -si --noconfirm
# AUR
RUN yay -S rustscan --noconfirm
RUN rustscan 127.0.0.1 -q -b 250 -t 1
RUN yay -R rustscan --noconfirm
# homebrew
RUN yes | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
ENV PATH="/home/linuxbrew/.linuxbrew/bin:${PATH}"
RUN yes | brew tap brandonskerritt/rustscan
RUN yes | brew install rustscan
RUN rustscan 127.0.0.1 -q -b 250 -t 1
File renamed without changes.
@@ -5,7 +5,6 @@ git pull --force
#amd64
cargo deb
yes | dpkg -i *.deb
#arm64
rustup target add arm-unknown-linux-gnueabihf
File renamed without changes.
+42 -97
View File
@@ -11,22 +11,17 @@ use port_strategy::PortStrategy;
use colorful::Color;
use colorful::Colorful;
use futures::executor::block_on;
use rlimit::Resource;
use rlimit::{getrlimit, setrlimit};
use serde_derive::Deserialize;
#[cfg(not(target_os = "windows"))]
use rlimit::{getrlimit, setrlimit, Resource};
use std::collections::HashMap;
use std::net::ToSocketAddrs;
#[cfg(not(target_os = "windows"))]
use std::convert::TryInto;
use std::process::Command;
use std::str::FromStr;
use std::{
fs::File,
io::{Read, Write},
net::IpAddr,
path::PathBuf,
time::Duration,
};
use std::{net::IpAddr, net::ToSocketAddrs, time::Duration};
use structopt::{clap::arg_enum, StructOpt};
use ureq;
extern crate colorful;
extern crate dirs;
@@ -34,9 +29,9 @@ extern crate dirs;
const LOWEST_PORT_NUMBER: u16 = 1;
const TOP_PORT_NUMBER: u16 = 65535;
// Average value for Ubuntu
const DEFAULT_FILE_DESCRIPTORS_LIMIT: rlimit::rlim = 8000;
const DEFAULT_FILE_DESCRIPTORS_LIMIT: u32 = 8000;
// Safest batch size based on experimentation
const AVERAGE_BATCH_SIZE: rlimit::rlim = 3000;
const AVERAGE_BATCH_SIZE: u32 = 3000;
#[macro_use]
extern crate log;
@@ -106,10 +101,6 @@ struct Opts {
#[structopt(short, long)]
accessible: bool,
///Config file usage
#[structopt(short, long)]
config: bool,
/// The batch size for port scanning, it increases or slows the speed of
/// scanning. Depends on the open file limit of your OS. If you do 65535
/// it will do every port at the same time. Although, your OS may not
@@ -123,7 +114,7 @@ struct Opts {
/// Automatically ups the ULIMIT with the value you provided.
#[structopt(short, long)]
ulimit: Option<rlimit::rlim>,
ulimit: Option<u32>,
/// The order of scanning to be performed. The "serial" option will
/// scan ports in ascending order while the "random" option will scan
@@ -140,11 +131,6 @@ struct Opts {
command: Vec<String>,
}
#[derive(Deserialize)]
struct ConfigFile {
ip: IpAddr,
}
#[cfg(not(tarpaulin_include))]
/// Faster Nmap scanning with Rust
/// If you're looking for the actual scanning, check out the module Scanner
@@ -167,12 +153,6 @@ fn main() {
print_opening();
}
/*
TODO when releasing the new config file feature
turn this on.
if opts.config {
let config = get_config_file();
}*/
let ips: Vec<IpAddr> = parse_ips(&opts);
if ips.is_empty() {
@@ -180,7 +160,8 @@ fn main() {
std::process::exit(1);
}
let ulimit: rlimit::rlim = adjust_ulimit_size(&opts);
let ulimit: u32 = adjust_ulimit_size(&opts);
let batch_size: u16 = infer_batch_size(&opts, ulimit);
let scanner = Scanner::new(
@@ -269,65 +250,21 @@ Faster Nmap scanning with Rust."#;
--------------------------------------"#;
println!("{}", info.gradient(Color::Yellow).bold());
funny_opening!();
// println!("{}", loaded_config_file);
}
fn get_config_file() {
let result_get_location = get_location_config();
let location = match result_get_location {
Ok(path) => path,
Err(_) => panic!("Your system does not have appdirs."),
};
info!("The location of config is {:?}", location);
detail!(format!("The config file is at {:?}", location));
load_and_parse_config_file(location);
}
fn get_location_config() -> Result<std::path::PathBuf, &'static str> {
info!("Getting location of config file");
let config_path = match dirs::config_dir() {
Some(mut path) => {
path.push("rustscan");
path.push("config.toml");
Ok(path)
path
}
None => Err("Your system does not have APPDIRS"),
None => panic!("Couldn't find config dir."),
};
config_path
detail!(format!(
"{} {:?}",
"The config file is expected to be at", config_path
));
}
fn load_and_parse_config_file(config_path: PathBuf) -> ConfigFile {
// Gets the file and returns the string of TOML
// TODO quiet mode
let mut file = File::open(&config_path);
let mut file: File = match file {
Ok(result) => result,
Err(_) => download_place_config_file(config_path),
};
let mut contents = String::new();
file.read_to_string(&mut contents).unwrap();
let config: ConfigFile = toml::from_str(&contents).unwrap();
config
}
// Downloads config file
// Places into Appdirs
fn download_place_config_file(config_location: PathBuf) -> std::fs::File {
info!("Placing config file");
let body = ureq::get("https://raw.githubusercontent.com/RustScan/RustScan/master/config.toml")
.call()
.into_string()
.unwrap();
let mut file = File::create(config_location).unwrap();
file.write(body.as_bytes()).unwrap();
file
}
#[cfg(not(tarpaulin_include))]
fn build_nmap_arguments<'a>(
addr: &'a str,
@@ -368,9 +305,10 @@ fn parse_ips(opts: &Opts) -> Vec<IpAddr> {
ips
}
fn adjust_ulimit_size(opts: &Opts) -> rlimit::rlim {
#[cfg(not(target_os = "windows"))]
fn adjust_ulimit_size(opts: &Opts) -> u32 {
if opts.ulimit.is_some() {
let limit: rlimit::rlim = opts.ulimit.unwrap();
let limit: rlimit::rlim = opts.ulimit.unwrap().into();
match setrlimit(Resource::NOFILE, limit, limit) {
Ok(_) => {
@@ -385,14 +323,21 @@ fn adjust_ulimit_size(opts: &Opts) -> rlimit::rlim {
let (rlim, _) = getrlimit(Resource::NOFILE).unwrap();
rlim
rlim.try_into().unwrap()
}
fn infer_batch_size(opts: &Opts, ulimit: rlimit::rlim) -> u16 {
let mut batch_size: rlimit::rlim = opts.batch_size.into();
// Rlimit does not support Windows
// set to 1000 if Windows is used
#[cfg(target_os = "windows")]
fn adjust_ulimit_size(_opts: &Opts) -> u32 {
1000
}
fn infer_batch_size(opts: &Opts, ulimit: u32) -> u16 {
let mut batch_size: u32 = opts.batch_size.into();
// Adjust the batch size when the ulimit value is lower than the desired batch size
if ulimit < batch_size {
if ulimit < batch_size && !(cfg!(windows)) {
warning!("File limit is lower than default batch size. Consider upping with --ulimt. May cause harm to sensitive servers",
opts.quiet
);
@@ -404,7 +349,11 @@ fn infer_batch_size(opts: &Opts, ulimit: rlimit::rlim) -> u16 {
// ulimit is smaller than aveage batch size
// user must have very small ulimit
// decrease batch size to half of ulimit
warning!("Your file limit is very small, which negatively impacts RustScan's speed. Use the Docker image, or up the Ulimit with '--ulimit 5000'. ");
if !(cfg!(windows)) {
warning!("Your file limit is very small, which negatively impacts RustScan's speed. Use the Docker image, or up the Ulimit with '--ulimit 5000'. ");
} else {
warning!("Windows is known to be much slower than scanning on Unix systems. Use the Docker image if you need faster speeds.");
}
info!("Halving batch_size because ulimit is smaller than average batch size");
batch_size = ulimit / 2
} else if ulimit > DEFAULT_FILE_DESCRIPTORS_LIMIT {
@@ -430,6 +379,7 @@ fn infer_batch_size(opts: &Opts, ulimit: rlimit::rlim) -> u16 {
mod tests {
use crate::{adjust_ulimit_size, infer_batch_size, parse_ips, print_opening, Opts, ScanOrder};
#[cfg(not(target_os = "windows"))]
#[test]
fn batch_size_lowered() {
let opts = Opts {
@@ -441,7 +391,6 @@ mod tests {
timeout: 1_000,
ulimit: Some(2_000),
command: Vec::new(),
config: false,
accessible: false,
scan_order: ScanOrder::Serial,
};
@@ -450,6 +399,7 @@ mod tests {
assert!(batch_size < 50_000);
}
#[cfg(not(target_os = "windows"))]
#[test]
fn batch_size_lowered_average_size() {
let opts = Opts {
@@ -461,7 +411,6 @@ mod tests {
timeout: 1_000,
ulimit: Some(2_000),
command: Vec::new(),
config: false,
accessible: false,
scan_order: ScanOrder::Serial,
};
@@ -469,6 +418,7 @@ mod tests {
assert!(batch_size == 3_000);
}
#[cfg(not(target_os = "windows"))]
#[test]
fn batch_size_equals_ulimit_lowered() {
// because ulimit and batch size are same size, batch size is lowered
@@ -482,7 +432,6 @@ mod tests {
timeout: 1_000,
ulimit: Some(2_000),
command: Vec::new(),
config: false,
accessible: false,
scan_order: ScanOrder::Serial,
};
@@ -490,6 +439,7 @@ mod tests {
assert!(batch_size == 4_900);
}
#[cfg(not(target_os = "windows"))]
#[test]
fn batch_size_adjusted_2000() {
// ulimit == batch_size
@@ -502,7 +452,6 @@ mod tests {
timeout: 1_000,
ulimit: Some(2_000),
command: Vec::new(),
config: false,
accessible: false,
scan_order: ScanOrder::Serial,
};
@@ -527,7 +476,6 @@ mod tests {
timeout: 1_000,
ulimit: None,
command: Vec::new(),
config: false,
accessible: true,
scan_order: ScanOrder::Serial,
};
@@ -550,7 +498,6 @@ mod tests {
command: Vec::new(),
accessible: false,
scan_order: ScanOrder::Serial,
config: false,
};
let ips = parse_ips(&opts);
@@ -570,7 +517,6 @@ mod tests {
command: Vec::new(),
accessible: false,
scan_order: ScanOrder::Serial,
config: false,
};
let ips = parse_ips(&opts);
@@ -590,7 +536,6 @@ mod tests {
command: Vec::new(),
accessible: false,
scan_order: ScanOrder::Serial,
config: false,
};
let ips = parse_ips(&opts);
View File
Whitespace-only changes.