Skip to content

Commit

Permalink
feat: make only header requests + time logging
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-eof committed Oct 9, 2022
1 parent 4f4161f commit 1471352
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ rayon = "1.5.3"
num_cpus = "1.13.1"
crossbeam-channel = "0.5.6"
async-std = { version = "1", features = ["attributes", "tokio1"] }
dotenv = "0.15.0"
dotenv = "0.15.0"
chrono = "0.4.22"
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,25 @@ Tested on `MacOS`, `Ubuntu` and `Windows 11` and (today) it works.

## Comparison

I used the same dictionary file on three different notebooks not connected to the mains.
I used the same dictionary file on three different notebooks connected to the mains (energy saving off).

```
1. MacOS - M1 Pro - 8 threads -> ~42s
1. MacOS - M1 Pro - 1 thread -> ~240s
1. MacOS - M1 Pro - 8 threads -> 43.34s
1. MacOS - M1 Pro - 8 threads -> 42.08s
1. MacOS - M1 Pro - 8 threads -> 43.63s
-----------------------------------------------------------------
2. Windows 11 - Intel i7-10750H - 12 threads -> ~70s
2. Ubuntu - Intel i7-10750H - 12 threads -> ~72s
2. Windows 11 - Intel i7-10750H - 12 threads -> 31.80s
2. Windows 11 - Intel i7-10750H - 12 threads -> 60.15s
2. Windows 11 - Intel i7-10750H - 12 threads -> 30.98s
2. Ubuntu - Intel i7-10750H - 12 threads -> 48.61s
2. Ubuntu - Intel i7-10750H - 12 threads -> 61.04s
2. Ubuntu - Intel i7-10750H - 12 threads -> 65.48s
-----------------------------------------------------------------
3. Ubuntu - AMD Ryzen 7 (4800H) - 16 threads -> ~133s
3. Ubuntu - AMD Ryzen 7 (4800H) - 16 threads -> 139.42s
3. Ubuntu - AMD Ryzen 7 (4800H) - 16 threads -> 140.37s
3. Ubuntu - AMD Ryzen 7 (4800H) - 16 threads -> 136.08s
```

## Linux users
Expand Down
6 changes: 4 additions & 2 deletions src/utils/connection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use async_std::task;
use chrono::{Utc, Timelike};
use reqwest::Response;

pub async fn http_req(
Expand All @@ -15,7 +16,8 @@ pub async fn http_req(


while res.is_err(){
println!("[KO] -> Error. Retrying username:[{}], password[{}]...", username, password);
let dt = Utc::now();
println!("[{}:{} {}] [KO] -> Error. Retrying username:[{}], password[{}]...", dt.hour(), dt.minute(), dt.second(), username, password);
*failed_and_restored_requests = (*failed_and_restored_requests) + 1;
res = task::block_on(async move {
request(uri, auth).await
Expand All @@ -41,7 +43,7 @@ async fn request(uri: &str, auth: &str) -> Result<Response, reqwest::Error> {
.danger_accept_invalid_hostnames(true)
.build()
.unwrap()
.get(uri)
.head(uri)
.header(USER_AGENT, "Basic Brutus")
.header("Authorization", format!("Base {}", auth))
.send()
Expand Down
25 changes: 18 additions & 7 deletions src/utils/core.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chrono::{Utc, Timelike};
use crossbeam_channel::Receiver;

const MAX_NMUM_THREADS: &str = "MAX_NUM_THREADS";
Expand Down Expand Up @@ -31,7 +32,8 @@ pub fn execute_command(parsed_command: HashMap<String, String>, original_command
fn run_attack(parsed_command: HashMap<String, String>, original_command: &str) {
let num_threads = load_env_variable_as_usize(MAX_NMUM_THREADS, num_cpus::get(), true);
let channel_buffer = load_env_variable_as_usize(CHANNEL_BUFFER, CHANNEL_BUFFER_DEF_VALUE, true);
println!("The channel buffer is {}", channel_buffer);
let dt = Utc::now();
println!("[{}:{} {}] The channel buffer is {}", dt.hour(), dt.minute(), dt.second(), channel_buffer);
let start = Instant::now();
let uri = parsed_command.get("uri").unwrap();

Expand All @@ -40,8 +42,9 @@ fn run_attack(parsed_command: HashMap<String, String>, original_command: &str) {

rayon::scope(|s| {
let mut failed_and_restored_requests = 0;
let mut dt = Utc::now();
let (work_queue_sender, work_queue_receiver) = crossbeam_channel::bounded(channel_buffer);
println!("I will use [ {} ] threads", num_threads);
println!("[{}:{} {}] I will use [ {} ] threads", dt.hour(), dt.minute(), dt.second(), num_threads);
for task_counter in 0..num_threads {
let work_receiver: Receiver<String> = work_queue_receiver.clone();

Expand All @@ -59,7 +62,8 @@ fn run_attack(parsed_command: HashMap<String, String>, original_command: &str) {
}

let filename_passwords = parsed_command.get("dictionary").unwrap();
println!("Reading filename {}...", &filename_passwords);
dt = Utc::now();
println!("[{}:{} {}] Reading filename {}...",dt.hour(), dt.minute(), dt.second(), &filename_passwords);

match parsed_command.get("usernames") {
Some(path) => {
Expand Down Expand Up @@ -137,7 +141,8 @@ fn load_env_variable_as_usize(
original_command: &str,
failed_and_restored_requests: &mut i32
) {
println!("thread {} initialized", &task_counter);
let dt = Utc::now();
println!("[{}:{} {}] thread {} initialized", dt.hour(), dt.minute(), dt.second(), &task_counter);

loop {
let tx_res = work_receiver.recv();
Expand All @@ -149,7 +154,9 @@ fn load_env_variable_as_usize(
let password = &tx[separator_pos + 1..];
match task::block_on(attack_request(task_counter, &uri, username, password, failed_and_restored_requests)) {
Ok(_) => {
let dt = Utc::now();
let duration = start.elapsed();
println!("{}:{} {}", dt.hour(), dt.minute(), dt.second(), );
println!("original command: {:?}", original_command);
println!("duration: {:?}", duration);
println!("total n. of threads: {:?}", num_threads);
Expand All @@ -161,7 +168,8 @@ fn load_env_variable_as_usize(
}
}
Err(err) => {
println!("thread {} finished job: {}", &task_counter, err);
let dt = Utc::now();
println!("[{}:{} {}] thread {} finished job: {}", dt.hour(), dt.minute(), dt.second(), &task_counter, err);
break;
}
}
Expand Down Expand Up @@ -190,8 +198,10 @@ async fn attack_request(
);
return Ok(result);
} else {
let dt = Utc::now();
println!(
"[KO] -> thread: [{}], username: [{}], password: [{}]",
"[{}:{} {}] [KO] -> thread: [{}], username: [{}], password: [{}]",
dt.hour(), dt.minute(), dt.second(),
idx + 1,
&username,
&password
Expand All @@ -204,7 +214,8 @@ fn read_lines(filename: &str) -> io::Result<io::Lines<io::BufReader<File>>> {
let file = match File::open(filename) {
Ok(file) => file,
Err(err) => {
println!("{} for filename {}", err, filename);
let dt = Utc::now();
println!("[{}:{} {}] {} for filename {}", dt.hour(), dt.minute(), dt.second(), err, filename);
panic!();
}
};
Expand Down

0 comments on commit 1471352

Please sign in to comment.