From 57dfb158521ce4c4a99dd5b83788389b2113633d Mon Sep 17 00:00:00 2001 From: "Ben (CMNatic)" Date: Wed, 23 Sep 2020 12:40:51 +0100 Subject: [PATCH 1/2] Update Dockerfile to encourage layer caching (#241) At the moment the Dockerfile brings the entire current directory in as a context for the building container. We can encourage some caching here by only bringing forward the essentials: `cargo.tml`, `cargo.lock` and the `src` + Added a maintainer label --- Dockerfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9b7c5ff..fd86ff4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,11 @@ FROM rust:alpine as builder +LABEL maintainer="CMNatic RUN apk add --no-cache build-base +# Encourage some layer caching here rather then copying entire directory that includes docs to builder container ~CMN WORKDIR /usr/src/rustscan -COPY . . +COPY Cargo.toml Cargo.lock ./ +COPY src src RUN cargo install --path . FROM alpine:3.12 @@ -13,4 +16,4 @@ RUN addgroup -S rustscan && \ apk add --no-cache nmap nmap-scripts wget COPY --from=builder /usr/local/cargo/bin/rustscan /usr/local/bin/rustscan USER rustscan -ENTRYPOINT [ "/usr/local/bin/rustscan" ] +ENTRYPOINT [ "/usr/local/bin/rustscan" ] \ No newline at end of file From 6bf70f0f9a6581ee8812e76c82bbd1631d6e390a Mon Sep 17 00:00:00 2001 From: Bee <10378052+bee-san@users.noreply.github.com> Date: Wed, 23 Sep 2020 12:42:13 +0100 Subject: [PATCH 2/2] Fixed output error, Warning! ran when file opened (#237) Take file of addresses as input --- .gitignore | 4 ++++ src/main.rs | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index c9d612c..f53f6f1 100644 --- a/.gitignore +++ b/.gitignore @@ -116,3 +116,7 @@ fabric.properties # Android studio 3.1+ serialized cache file .idea/caches/build_file_checksums.ser + +.idea/* +.idea +.idea* diff --git a/src/main.rs b/src/main.rs index e855b4c..24e436d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,8 +21,12 @@ use futures::executor::block_on; use rlimit::Resource; use rlimit::{getrlimit, setrlimit}; use std::collections::HashMap; +use std::fs::File; +use std::io::prelude::*; +use std::io::BufReader; use std::net::ToSocketAddrs; use std::process::Command; +use std::str::FromStr; use std::{net::IpAddr, time::Duration}; extern crate colorful; @@ -204,6 +208,24 @@ fn build_nmap_arguments<'a>( arguments } +#[cfg(not(tarpaulin_include))] +/// Parses an input file of IPs and uses those +fn read_ips_from_file(ips: String) -> Result, std::io::Error> { + // if we cannot open it as a file, it is not a file so move on + let file = File::open(ips)?; + let reader = BufReader::new(file); + + let mut ips: Vec = Vec::new(); + + for str_ip in reader.lines() { + match IpAddr::from_str(&str_ip.unwrap()) { + Ok(x) => ips.push(x), + Err(y) => panic!("File does not contain valid IP address. Error at {}", y), + } + } + Ok(ips) +} + fn parse_addresses(opts: &Opts) -> Vec { let mut ips: Vec = Vec::new(); @@ -212,13 +234,16 @@ fn parse_addresses(opts: &Opts) -> Vec { Ok(cidr) => cidr.iter().for_each(|ip| ips.push(ip)), _ => match format!("{}:{}", &ip_or_host, 80).to_socket_addrs() { Ok(mut iter) => ips.push(iter.nth(0).unwrap().ip()), - _ => { - warning!( - format!("Host {:?} could not be resolved.", ip_or_host), - opts.greppable, - opts.accessible - ); - } + _ => match read_ips_from_file(ip_or_host.to_owned()) { + Ok(x) => ips.extend(x), + _ => { + warning!( + format!("Host {:?} could not be resolved.", ip_or_host), + opts.greppable, + opts.accessible + ); + } + }, }, } }