Skip to content

Commit

Permalink
added rustfmt to github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
bee-san committed Jul 26, 2020
1 parent 4d4ef5a commit fb3c7c4
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 28 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,35 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
60 changes: 33 additions & 27 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ mod scanner;
use scanner::Scanner;

use colored::*;
use std::time::Duration;
use std::process::{exit, Command};
use futures::executor::block_on;
use rlimit::Resource;
use rlimit::{setrlimit, getrlimit};
use rlimit::{getrlimit, setrlimit};
use std::process::{exit, Command};
use std::time::Duration;
use structopt::StructOpt;

#[derive(StructOpt, Debug)]
Expand All @@ -28,11 +28,11 @@ struct Opts {
/// 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.
#[structopt(short, long, default_value = "4500")]
#[structopt(short, long, default_value = "4500")]
batch_size: u64,

/// The timeout in milliseconds before a port is assumed to be closed.
#[structopt(short, long, default_value = "1500")]
#[structopt(short, long, default_value = "1500")]
timeout: u64,

/// Automatically ups the ULIMIT with the value you provided.
Expand All @@ -54,25 +54,25 @@ fn main() {
let user_nmap_options = if opts.command.is_empty() {
"-A -vvv".to_string()
} else {
opts.command.join(" ")
opts.command.join(" ")
};

if !opts.quiet {
print_opening();
print_opening();
}

// Updates ulimit when the argument is set
if opts.ulimit.is_some() {
let limit = opts.ulimit.unwrap();
let limit = opts.ulimit.unwrap();

if !opts.quiet {
println!("Automatically upping ulimit to {}", limit);
}
if !opts.quiet {
println!("Automatically upping ulimit to {}", limit);
}

match setrlimit(Resource::NOFILE, limit, limit) {
Ok(_) => {},
Err(_) => println!("ERROR. Failed to set Ulimit.")
}
match setrlimit(Resource::NOFILE, limit, limit) {
Ok(_) => {}
Err(_) => println!("ERROR. Failed to set Ulimit."),
}
}

let (x, _) = getrlimit(Resource::NOFILE).unwrap();
Expand All @@ -92,17 +92,16 @@ fn main() {
// basically, ubuntu is 8000
// but i can only get it to work on < 5k in testing
// 5k is default, so 3000 seems safe
if x > 8000{
if x > 8000 {
opts.batch_size = 3000
}
else {
} else {
opts.batch_size = x - 100u64;
}
}
// else if the ulimit is higher than batch size
// tell the user they can increase batch size
// if the user set ulimit arg they probably know what they are doing so don't print this
else if x + 2 > opts.batch_size && (opts.ulimit.is_none()){
else if x + 2 > opts.batch_size && (opts.ulimit.is_none()) {
if !opts.quiet {
println!(
"Your file description limit is higher than the batch size. You can potentially increase the speed by increasing the batch size, but this may cause harm to sensitive servers. Your limit is {}, try batch size {}.",
Expand All @@ -114,7 +113,14 @@ fn main() {
// the user has asked to automatically up the ulimit

// 65535 + 1 because of 0 indexing
let scanner = Scanner::new(&opts.ip, 1, 65536, opts.batch_size, Duration::from_millis(opts.timeout), opts.quiet);
let scanner = Scanner::new(
&opts.ip,
1,
65536,
opts.batch_size,
Duration::from_millis(opts.timeout),
opts.quiet,
);
let scan_result = block_on(scanner.run());

// prints ports and places them into nmap string
Expand All @@ -135,10 +141,7 @@ fn main() {

// Tells the user we are now switching to Nmap
if !opts.quiet {
println!(
"{}",
"Starting nmap.".blue(),
);
println!("{}", "Starting nmap.".blue(),);
}

// nmap port style is 80,443. Comma seperated with no spaces.
Expand All @@ -150,7 +153,10 @@ fn main() {
exit(1);
}

let nmap_args = format!("{} {} {} {} {} {}", &user_nmap_options, "-vvv", "-Pn", "-p", &ports_str, opts.ip);
let nmap_args = format!(
"{} {} {} {} {} {}",
&user_nmap_options, "-vvv", "-Pn", "-p", &ports_str, opts.ip
);
if !opts.quiet {
println!("The Nmap command to be run is {}", &nmap_args);
}
Expand Down Expand Up @@ -180,8 +186,8 @@ fn print_opening() {
#[cfg(test)]
mod tests {
use super::Scanner;
use std::time::Duration;
use async_std::task::block_on;
use std::time::Duration;

#[test]
fn does_it_run() {
Expand All @@ -191,4 +197,4 @@ mod tests {
// if the scan fails, it wouldn't be able to assert_eq! as it panicked!
assert_eq!(1, 1);
}
}
}
2 changes: 1 addition & 1 deletion src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ mod tests {
// TODO run functions here
assert_eq!(1, 1);
}
}
}

0 comments on commit fb3c7c4

Please sign in to comment.