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
Brandon 22cbfc5826 Merge pull request #159 from RustScan/bee-add-nmap-ports
updated config file to feature nmap top 1k ports
2020-08-24 16:49:13 +01:00
Brandon a9d729300c Merge branch 'master' into bee-add-nmap-ports 2020-08-24 13:49:10 +01:00
Brandon 4f5dd20e85 Merge pull request #162 from RustScan/ba-reduce-binary-size
Reduce binary size from 2.4MB to 1.9MB
2020-08-24 12:48:45 +01:00
Bernardo Chaves 499ff66f36 Reduce binary size from 2.4MB to 1.9MB
By default, Cargo instructs compilation units to be compiled and optimized
in isolation. LTO instructs the linker to optimize at the link stage.
This can, for example, remove dead code and often times reduces binary size.

By default, when Rust code encounters a situation when it must call panic!(),
it unwinds the stack and produces a helpful backtrace. The unwinding code,
however, does require extra binary size. rustc can be instructed to abort
immediately rather than unwind, which removes the need for this extra unwinding code.

For more information see: https://github.com/johnthagen/min-sized-rust
2020-08-23 18:10:53 -04:00
Brandon 61b87243d9 Merge pull request #161 from RustScan/ba-refactor-port-strategy
Allow randomized order for manual ports
2020-08-22 22:27:37 +01:00
Bernardo Chaves e069991c8d Allow randomized order for manual ports
Before this change we would always scan manually specified ports in
sequential way, this is not the case anymore. This is an important
change since we are planning to introduce a config file with the top 1K
ports and we would like to scan those in a randomized way.
2020-08-21 13:09:41 -04:00
Brandon 85c1cbf445 Merge pull request #160 from RustScan/bee-remove-A
removed -A from nmap
2020-08-20 22:58:39 +01:00
Brandon e609b3617c updated config file to feature nmap top 1k ports 2020-08-20 00:05:45 +01:00
7 changed files with 1087 additions and 55 deletions

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@ language: rust
os:
- linux
- osx
# - windows
- windows
arch:
- amd64
+7 -3
View File
@@ -16,14 +16,11 @@ exclude = [
"rustscan-debbuilder/*",
]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
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"
@@ -33,6 +30,13 @@ rand = "0.7.3"
colorful = "0.2.1"
ansi_term = "0.12.1"
[target."cfg(not(windows))".dependencies]
rlimit = "0.4.0"
[package.metadata.deb]
depends = "$auto, nmap"
section = "rust"
[profile.release]
lto = true
panic = 'abort'
+10 -13
View File
@@ -213,26 +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. These ports will
be scanned sequentially
-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]
@@ -240,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.
+1004
View File
File diff suppressed because it is too large. Load diff
+34 -14
View File
@@ -11,9 +11,13 @@ use port_strategy::PortStrategy;
use colorful::Color;
use colorful::Colorful;
use futures::executor::block_on;
use rlimit::Resource;
use rlimit::{getrlimit, setrlimit};
#[cfg(not(target_os = "windows"))]
use rlimit::{getrlimit, setrlimit, Resource};
use std::collections::HashMap;
#[cfg(not(target_os = "windows"))]
use std::convert::TryInto;
use std::process::Command;
use std::str::FromStr;
use std::{net::IpAddr, net::ToSocketAddrs, time::Duration};
@@ -25,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;
@@ -82,7 +86,6 @@ struct Opts {
ips_or_hosts: Vec<String>,
/// A list of comma separed ports to be scanned. Example: 80,443,8080.
/// These ports will be scanned sequentially.
#[structopt(short, long, use_delimiter = true)]
ports: Option<Vec<u16>>,
@@ -111,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
@@ -157,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(
@@ -301,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(_) => {
@@ -318,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
);
@@ -337,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 {
@@ -363,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 {
@@ -382,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 {
@@ -400,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
@@ -420,6 +439,7 @@ mod tests {
assert!(batch_size == 4_900);
}
#[cfg(not(target_os = "windows"))]
#[test]
fn batch_size_adjusted_2000() {
// ulimit == batch_size
+31 -24
View File
@@ -1,5 +1,7 @@
mod range_iterator;
use super::{PortRange, ScanOrder};
use rand::seq::SliceRandom;
use rand::thread_rng;
use range_iterator::RangeIterator;
/// Represents options of port scanning.
@@ -15,26 +17,27 @@ pub enum PortStrategy {
impl PortStrategy {
pub fn pick(range: Option<PortRange>, ports: Option<Vec<u16>>, order: ScanOrder) -> Self {
match order {
ScanOrder::Serial => match ports.is_none() {
true => {
let range = range.as_ref().unwrap();
PortStrategy::Serial(SerialRange {
start: range.start,
end: range.end,
})
}
false => PortStrategy::Manual(ports.unwrap()),
},
ScanOrder::Random => match ports.is_none() {
true => {
let range = range.as_ref().unwrap();
PortStrategy::Random(RandomRange {
start: range.start,
end: range.end,
})
}
false => PortStrategy::Manual(ports.unwrap()),
},
ScanOrder::Serial if ports.is_none() => {
let range = range.as_ref().unwrap();
PortStrategy::Serial(SerialRange {
start: range.start,
end: range.end,
})
}
ScanOrder::Random if ports.is_none() => {
let range = range.as_ref().unwrap();
PortStrategy::Random(RandomRange {
start: range.start,
end: range.end,
})
}
ScanOrder::Serial => PortStrategy::Manual(ports.unwrap()),
ScanOrder::Random => {
let mut rng = thread_rng();
let mut ports = ports.unwrap();
ports.shuffle(&mut rng);
PortStrategy::Manual(ports)
}
}
}
@@ -121,9 +124,13 @@ mod tests {
}
#[test]
fn random_strategy_with_ports_does_not_randomize_ports() {
let strategy = PortStrategy::pick(None, Some(vec![80, 443]), ScanOrder::Random);
let result = strategy.order();
assert_eq!(vec![80, 443], result);
fn random_strategy_with_ports() {
let strategy = PortStrategy::pick(None, Some((1..10).collect()), ScanOrder::Random);
let mut result = strategy.order();
let expected_range = (1..10).into_iter().collect::<Vec<u16>>();
assert_ne!(expected_range, result);
result.sort();
assert_eq!(expected_range, result);
}
}
View File
Whitespace-only changes.