changed the portscanning function to make it faster. It's using a
combination of multithreading and async now, each host or target for the scan runs on its own thread, then each port check is run asynchronously.
This commit is contained in:
+106
-28
@@ -275,7 +275,10 @@ impl AppState {
|
||||
self.help.push(
|
||||
"save_server\nsave the server and password to your system's keyring.\n".to_string(),
|
||||
);
|
||||
self.help.push("parse_nessus\nparse a nessus csv to add hosts and ports to the currently selected project\n".to_string());
|
||||
self.help.push("parse_nessus\nparse a nessus csv to add hosts and ports to the currently selected project\nexport nessus csv report, only checking the host, protocol, and port boxes.\n".to_string());
|
||||
self.help.push(
|
||||
"Shortcuts:\nCTRL+P = new_project\nCTRL+s = save\nCTRL_+h = select_host\n".to_string(),
|
||||
);
|
||||
self.help.push("exit\nquit the tool\n".to_string());
|
||||
self.initialize_modules();
|
||||
return Ok(());
|
||||
@@ -563,9 +566,22 @@ impl AppState {
|
||||
}
|
||||
"new_terminal" | "nt" => {
|
||||
let project = self.projects[self.selected_project].clone();
|
||||
if let Some(db) = project.db {
|
||||
if let Some(cmd) = self.config.get("term_cmd") {
|
||||
if let Some(cmd) = self.config.get("term_cmd") {
|
||||
if let Some(db) = project.db {
|
||||
db.launch_terminal(cmd.to_string());
|
||||
} else {
|
||||
if let Some((prog, _)) = cmd.split_once(" ") {
|
||||
let mut launch_cmd = Command::new(prog);
|
||||
match launch_cmd.spawn() {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
let _ = self.main_tx.send(ToolMessage::Output((
|
||||
rid,
|
||||
format!("[error] launching terminal: {e}"),
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -871,10 +887,9 @@ impl AppState {
|
||||
let mut key = String::new();
|
||||
let mut value = String::new();
|
||||
if let Some(args) = command_args.clone() {
|
||||
let args_vec: Vec<&str> = args.split(" ").collect();
|
||||
if args_vec.len() == 2 {
|
||||
key = args_vec[0].to_string();
|
||||
value = args_vec[1].to_string();
|
||||
if let Some((setting, data)) = args.split_once(" ") {
|
||||
key = setting.to_string();
|
||||
value = data.to_string();
|
||||
if self.config.contains_key(&key) {
|
||||
ready = true;
|
||||
} else {
|
||||
@@ -1111,7 +1126,14 @@ impl AppState {
|
||||
match args_vec.len() {
|
||||
1 => {
|
||||
args_vec[0].split(",").into_iter().for_each(|p| {
|
||||
if let Ok(port) = p.trim().parse::<u16>() {
|
||||
if p.contains("-") {
|
||||
let (first, last) = p.split_once("-").unwrap();
|
||||
if let Ok(start) = first.parse::<u16>() {
|
||||
if let Ok(end) = last.parse::<u16>() {
|
||||
ports.extend(start..=end);
|
||||
}
|
||||
}
|
||||
} else if let Ok(port) = p.trim().parse::<u16>() {
|
||||
ports.push(port);
|
||||
}
|
||||
});
|
||||
@@ -1155,23 +1177,45 @@ impl AppState {
|
||||
rid,
|
||||
format!("scanning {} ports on {} hosts", ports.len(), hosts.len()),
|
||||
)));
|
||||
let progress_bar = Arc::new(RwLock::new(ToolProgress {
|
||||
name: format!("portscan {} - {}", project.org_name, project.name),
|
||||
total: hosts.len() * ports.len(),
|
||||
complete: 0,
|
||||
finished: false,
|
||||
}));
|
||||
self.progress_bars.push(progress_bar.clone());
|
||||
let project_clone = Arc::new(Mutex::new(project.clone()));
|
||||
let id = self.selected_project.clone();
|
||||
let tx_clone = self.main_tx.clone();
|
||||
let pb_clone = progress_bar.clone();
|
||||
self.workers.spawn(move || {
|
||||
hosts.par_iter_mut().for_each(|h| {
|
||||
ports.par_iter().for_each(|p| {
|
||||
let mut host = h.clone();
|
||||
match host.check_port(p.clone(), tx_clone.clone()) {
|
||||
Ok(_) => {
|
||||
if let Ok(mut lock) = project_clone.lock() {
|
||||
lock.add_host(host.clone());
|
||||
}
|
||||
}
|
||||
Err(_) => {}
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
let host = rt.block_on(h.portscan(
|
||||
ports.clone(),
|
||||
tx_clone.clone(),
|
||||
pb_clone.clone(),
|
||||
));
|
||||
if let Ok(mut lock) = project_clone.lock() {
|
||||
if !lock.hosts.iter().any(|ph| ph.ip == host.ip) {
|
||||
lock.hosts.push(host);
|
||||
} else {
|
||||
lock.hosts
|
||||
.iter_mut()
|
||||
.filter(|ph| ph.ip == host.ip)
|
||||
.for_each(|ph| {
|
||||
host.open_ports.iter().for_each(|p| {
|
||||
if !ph.open_ports.contains(p) {
|
||||
ph.open_ports.push(p.clone());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if let Ok(mut lock) = pb_clone.write() {
|
||||
lock.finished = true;
|
||||
}
|
||||
if let Ok(lock) = project_clone.lock() {
|
||||
let _ =
|
||||
tx_clone.send(ToolMessage::UpdateProject(id, lock.clone()));
|
||||
@@ -1604,6 +1648,7 @@ impl AppState {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
"exit" => {
|
||||
self.save_all()?;
|
||||
let _ = self.main_tx.send(ToolMessage::AppStateExit);
|
||||
@@ -1866,15 +1911,18 @@ impl AppState {
|
||||
}
|
||||
}
|
||||
}
|
||||
let db = DistroBox {
|
||||
name: format!("{}-{}-{}", template_box, org, name),
|
||||
volumes: vec![
|
||||
project_files.display().to_string(),
|
||||
project_notes.display().to_string(),
|
||||
tools.to_string(),
|
||||
],
|
||||
created: false,
|
||||
template: template_box.to_string(),
|
||||
let mut db = None;
|
||||
if template_box != &"NONE".to_string() {
|
||||
db = Some(DistroBox {
|
||||
name: format!("{}-{}-{}", template_box, org, name),
|
||||
volumes: vec![
|
||||
project_files.display().to_string(),
|
||||
project_notes.display().to_string(),
|
||||
tools.to_string(),
|
||||
],
|
||||
created: false,
|
||||
template: template_box.to_string(),
|
||||
});
|
||||
};
|
||||
let mut new_project = Project {
|
||||
org_name: org,
|
||||
@@ -1884,7 +1932,7 @@ impl AppState {
|
||||
hosts: Vec::new(),
|
||||
config_folder: project_config_file,
|
||||
current: false,
|
||||
db: Some(db),
|
||||
db: db,
|
||||
scope: Vec::new(),
|
||||
};
|
||||
match new_project.save_config() {
|
||||
@@ -2547,4 +2595,34 @@ impl AppState {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run_cmd(&mut self, cmd: String) {
|
||||
if let Some(db) = self.projects[self.selected_project].db.clone() {
|
||||
db.run_command(&cmd);
|
||||
} else {
|
||||
if let Some(term_cmd) = self.config.get("term_cmd") {
|
||||
if let Some((prog, args)) = term_cmd.split_once(" ") {
|
||||
let mut launch_cmd = Command::new(prog);
|
||||
args.split(" ").into_iter().for_each(|arg| {
|
||||
launch_cmd.arg(arg);
|
||||
});
|
||||
launch_cmd.arg(&cmd);
|
||||
match launch_cmd.spawn() {
|
||||
Ok(_) => {
|
||||
let _ = self.main_tx.send(ToolMessage::Output((
|
||||
0,
|
||||
format!("[success] running {}", cmd),
|
||||
)));
|
||||
}
|
||||
Err(e) => {
|
||||
let _ = self.main_tx.send(ToolMessage::Output((
|
||||
0,
|
||||
format!("[error] running {}, {e}", cmd),
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user