6 Commits
7 changed files with 159 additions and 23 deletions

No files matched your search

Whitespace-only changes.
View File
Whitespace-only changes.
+35 -16
View File
@@ -163,6 +163,7 @@ impl AppState {
new_project.load_config(display)?; new_project.load_config(display)?;
let template_box = self.config.get("template_box").unwrap(); let template_box = self.config.get("template_box").unwrap();
let tools = self.config.get("tools").unwrap(); let tools = self.config.get("tools").unwrap();
if template_box != "NONE" || new_project.distrobox {
let db = DistroBox { let db = DistroBox {
name: format!( name: format!(
"{}-{}-{}", "{}-{}-{}",
@@ -179,6 +180,9 @@ impl AppState {
template: template_box.clone(), template: template_box.clone(),
}; };
new_project.db = Some(db); new_project.db = Some(db);
} else {
new_project.db = None;
}
self.projects.push(new_project); self.projects.push(new_project);
} }
} }
@@ -581,24 +585,24 @@ impl AppState {
let project = self.projects[self.selected_project].clone(); let project = self.projects[self.selected_project].clone();
if let Some(cmd) = self.config.get("term_cmd") { if let Some(cmd) = self.config.get("term_cmd") {
if let Some(db) = project.db { if let Some(db) = project.db {
db.launch_terminal(cmd.to_string()); let _ = self
.main_tx
.send(ToolMessage::Output((rid, format!("launcing distrobox..."))));
db.launch_terminal(
cmd.to_string(),
self.projects[self.selected_project].files.clone(),
);
} else { } else {
if let Some((prog, _)) = cmd.split_once(" ") { if let Some((prog, _)) = cmd.split_once(" ") {
let mut launch_cmd = Command::new(prog); let mut launch_cmd = Command::new(prog);
match prog { launch_cmd.current_dir(&project.files);
"konsole" => { if let Some(dir) = launch_cmd.get_current_dir() {
launch_cmd let _ = self.main_tx.send(ToolMessage::Output((
.arg(format!("--workdir {}", project.files.display())); rid,
format!("launcing terminal in {}", dir.display()),
)));
} }
"xfce4-terminal" => { match launch_cmd.current_dir(&project.files).spawn() {
launch_cmd.arg(format!(
"--working-directory={}",
project.files.display()
));
}
_ => {}
}
match launch_cmd.spawn() {
Ok(_) => {} Ok(_) => {}
Err(e) => { Err(e) => {
let _ = self.main_tx.send(ToolMessage::Output(( let _ = self.main_tx.send(ToolMessage::Output((
@@ -2038,6 +2042,7 @@ impl AppState {
} }
} }
let mut db = None; let mut db = None;
let mut distrobx = false;
if template_box != &"NONE".to_string() { if template_box != &"NONE".to_string() {
db = Some(DistroBox { db = Some(DistroBox {
name: format!("{}-{}-{}", template_box, org, name), name: format!("{}-{}-{}", template_box, org, name),
@@ -2049,6 +2054,7 @@ impl AppState {
created: false, created: false,
template: template_box.to_string(), template: template_box.to_string(),
}); });
distrobx = true;
}; };
let mut new_project = Project { let mut new_project = Project {
org_name: org, org_name: org,
@@ -2059,6 +2065,7 @@ impl AppState {
config_folder: project_config_file, config_folder: project_config_file,
current: false, current: false,
db: db, db: db,
distrobox: distrobx,
scope: Vec::new(), scope: Vec::new(),
exclusions: Vec::new(), exclusions: Vec::new(),
}; };
@@ -2101,8 +2108,20 @@ impl AppState {
let mut old_notes = new_project.notes.clone(); let mut old_notes = new_project.notes.clone();
old_files.pop(); old_files.pop();
old_notes.pop(); old_notes.pop();
remove_dir_all(&old_files)?; remove_dir_all(&new_project.files)?;
remove_dir_all(&old_notes)?; remove_dir_all(&new_project.notes)?;
if let Err(_) = remove_dir(old_files) {
self.main_tx.send(ToolMessage::Output((
rid,
String::from("organization files folder is not empty and will not be deleted."),
)))?;
}
if let Err(_) = remove_dir(old_notes) {
self.main_tx.send(ToolMessage::Output((
rid,
String::from("organization notes folder is not empty and will not be deleted."),
)))?;
}
new_files_path.push(&new_project.name); new_files_path.push(&new_project.name);
new_notes_path.push(&new_project.name); new_notes_path.push(&new_project.name);
new_project.files(new_files_path.clone()); new_project.files(new_files_path.clone());
+55 -2
View File
@@ -1,11 +1,12 @@
use fs_extra::dir::{CopyOptions, copy}; use fs_extra::dir::{CopyOptions, copy};
use std::env;
use std::error::Error; use std::error::Error;
use std::fs::{File, create_dir_all, remove_dir_all}; use std::fs::{File, OpenOptions, create_dir_all, remove_dir_all};
use std::io::Write; use std::io::Write;
use std::os::unix::fs::PermissionsExt;
use std::path::PathBuf; use std::path::PathBuf;
use std::process::Command; use std::process::Command;
use std::process::exit; use std::process::exit;
use std::{env, fs};
use tetanus::funcs::get_user_input; use tetanus::funcs::get_user_input;
pub fn install() -> Result<(), Box<dyn Error>> { pub fn install() -> Result<(), Box<dyn Error>> {
@@ -98,6 +99,7 @@ pub fn client_install() -> Result<(), Box<dyn Error>> {
client_config_file.write(format!("term_cmd: {}\n", term_cmd).as_bytes())?; client_config_file.write(format!("term_cmd: {}\n", term_cmd).as_bytes())?;
client_config_file.write(format!("tools: {}\n", tools_folder).as_bytes())?; client_config_file.write(format!("tools: {}\n", tools_folder).as_bytes())?;
client_config_file.write("alternate_configs: \n".as_bytes())?; client_config_file.write("alternate_configs: \n".as_bytes())?;
let mut version_file = File::create(root_config_folder_path.join("version"))?;
println!("\ndefault config files written!"); println!("\ndefault config files written!");
println!("downloading note templates, victim templates, and modules..."); println!("downloading note templates, victim templates, and modules...");
create_dir_all("./temp")?; create_dir_all("./temp")?;
@@ -143,15 +145,66 @@ pub fn client_install() -> Result<(), Box<dyn Error>> {
.status() .status()
{ {
if res.success() { if res.success() {
let base_update_string = fs::read_to_string("./tetanus_update.sh")?;
let update_string = base_update_string.replace(
"|||config|||",
&root_config_folder_path.display().to_string(),
);
let update_path = PathBuf::from("./tetanus_update");
let mut update_script = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(&update_path)?;
update_script.write(update_string.as_bytes())?;
let mut perms = fs::metadata(&update_path)?.permissions();
perms.set_mode(0o755);
fs::set_permissions(update_path, perms)?;
let _ = Command::new("sudo")
.arg("cp")
.arg("./tetanus_update")
.arg("/usr/bin/tetanus_update")
.status();
version_file
.write("version: 0.0.7\npath: /usr/bin/tetanus".as_bytes())?;
println!("copied to path!"); println!("copied to path!");
println!("install completed!"); println!("install completed!");
} else { } else {
eprintln!( eprintln!(
"error copying to path. please copy this executable to your path manually." "error copying to path. please copy this executable to your path manually."
); );
eprintln!("please download the update_script to your path manually");
eprintln!(
"sudo curl https://git.pyro.monster/pyro/tetanus/raw/branch/main/tetanus_update.sh -o /usr/bin/tetanus_update"
);
eprintln!("sudo chmod +x /usr/bin/tetanus_update");
} }
} }
} }
} else {
println!(
"Ok, we will keep the tetanus binary where it is. The tetanus_update bash script will be in the same directory."
);
let base_update_string = fs::read_to_string("./tetanus_update.sh")?;
let update_string = base_update_string.replace(
"|||config|||",
&root_config_folder_path.display().to_string(),
);
let mut update_path = env::current_exe()?;
update_path.pop();
update_path.push("tetanus_update");
let mut update_script = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(&update_path)?;
update_script.write(update_string.as_bytes())?;
let mut perms = fs::metadata(&update_path)?.permissions();
perms.set_mode(0o755);
fs::set_permissions(update_path, perms)?;
version_file.write(
format!("version: 0.0.7\npath: {}", env::current_exe()?.display()).as_bytes(),
)?;
} }
env::set_current_dir("../")?; env::set_current_dir("../")?;
remove_dir_all("./temp")?; remove_dir_all("./temp")?;
+27
View File
@@ -2,6 +2,8 @@ use clap::Parser;
use keyring::Entry; use keyring::Entry;
use rand::RngExt; use rand::RngExt;
use rand::distr::Alphanumeric; use rand::distr::Alphanumeric;
use std::fs::OpenOptions;
use std::io::{Write, read_to_string};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::thread::{sleep, spawn}; use std::thread::{sleep, spawn};
use std::time::Duration; use std::time::Duration;
@@ -115,6 +117,30 @@ async fn main() {
} }
} }
} }
if let Ok(version_string) = std::fs::read_to_string(config_path.join("version")) {
version_string
.lines()
.into_iter()
.filter(|line| line.contains("path:"))
.for_each(|line| {
if let Some((_, path)) = line.split_once(" ") {
if let Ok(current_exe) = env::current_exe() {
if PathBuf::from(path) != current_exe {
let new_version_string =
version_string.replace(path, &current_exe.display().to_string());
if let Ok(mut version_file) = OpenOptions::new()
.truncate(true)
.write(true)
.open(config_path.join("version"))
{
let _ = version_file.write(new_version_string.as_bytes());
}
}
}
}
});
}
if args.client { if args.client {
let banner = " let banner = "
XXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXX
@@ -158,6 +184,7 @@ async fn main() {
banner.lines().for_each(|line| { banner.lines().for_each(|line| {
appstate.output.push(line.to_string()); appstate.output.push(line.to_string());
}); });
let handles = Arc::new(Mutex::new(Vec::new())); let handles = Arc::new(Mutex::new(Vec::new()));
let handles_clone = handles.clone(); let handles_clone = handles.clone();
let primary_handle = spawn(move || { let primary_handle = spawn(move || {
+21 -5
View File
@@ -22,6 +22,7 @@ pub struct Project {
pub hosts: Vec<Host>, pub hosts: Vec<Host>,
pub current: bool, pub current: bool,
pub db: Option<DistroBox>, pub db: Option<DistroBox>,
pub distrobox: bool,
pub scope: Vec<String>, pub scope: Vec<String>,
pub exclusions: Vec<String>, pub exclusions: Vec<String>,
} }
@@ -37,6 +38,7 @@ impl Project {
hosts: Vec::new(), hosts: Vec::new(),
current: false, current: false,
db: None, db: None,
distrobox: false,
scope: Vec::new(), scope: Vec::new(),
exclusions: Vec::new(), exclusions: Vec::new(),
} }
@@ -117,6 +119,13 @@ impl Project {
self.exclusions.push(ip.to_string()); self.exclusions.push(ip.to_string());
}); });
} }
"db" => {
if parts[1].contains("false") {
self.distrobox = false;
} else {
self.distrobox = true;
}
}
_ => {} _ => {}
} }
} }
@@ -236,13 +245,14 @@ impl Project {
} }
let mut file = File::create(&self.config_folder)?; let mut file = File::create(&self.config_folder)?;
let mut out_string = format!( let mut out_string = format!(
"org_name: {}\nname: {}\nnotes: {}\nfiles: {}\nscope: {}\nexclusions: {}\n", "org_name: {}\nname: {}\nnotes: {}\nfiles: {}\nscope: {}\nexclusions: {}\ndb: {}\n",
self.org_name, self.org_name,
self.name, self.name,
self.notes.display(), self.notes.display(),
self.files.display(), self.files.display(),
self.scope.join(","), self.scope.join(","),
self.exclusions.join(","), self.exclusions.join(","),
self.distrobox
); );
if self.current { if self.current {
out_string.push_str("stage: current"); out_string.push_str("stage: current");
@@ -314,11 +324,17 @@ impl DistroBox {
.arg(self.name.clone()); .arg(self.name.clone());
let mut added_volumes = Vec::new(); let mut added_volumes = Vec::new();
for volume in &self.volumes { for volume in &self.volumes {
let folder_name = volume.split("/").last().unwrap(); let mut folder_name = volume.split("/").last().unwrap();
if folder_name.contains("pentest")
|| folder_name.contains("project")
|| folder_name.contains("ctf")
{
folder_name = "project";
}
if !added_volumes.contains(&String::from(folder_name)) { if !added_volumes.contains(&String::from(folder_name)) {
create_command create_command
.arg("--volume") .arg("--volume")
.arg(format!("{}:/project:rw", volume)); .arg(format!("{}:/{}:rw", volume, folder_name));
added_volumes.push(folder_name.to_string()); added_volumes.push(folder_name.to_string());
} }
} }
@@ -458,7 +474,7 @@ impl DistroBox {
return Ok(()); return Ok(());
} }
pub fn launch_terminal(&self, cmd: String) { pub fn launch_terminal(&self, cmd: String, dir: PathBuf) {
if let Some((terminal_cmd, args)) = cmd.split_once(" ") { if let Some((terminal_cmd, args)) = cmd.split_once(" ") {
let mut term_cmd = Command::new(terminal_cmd); let mut term_cmd = Command::new(terminal_cmd);
args.split(" ").into_iter().for_each(|arg| { args.split(" ").into_iter().for_each(|arg| {
@@ -474,7 +490,7 @@ impl DistroBox {
term_cmd.arg(arg); term_cmd.arg(arg);
} }
}); });
let _ = term_cmd.spawn(); let _ = term_cmd.current_dir(dir).spawn();
} }
} }
+21
View File
@@ -0,0 +1,21 @@
#!/bin/bash
config_path="|||CONFIG|||"
current_version=$(cat $config_path/version | grep version | cut -d " " -f 2)
path=$(cat $config_path/version | grep path | cut -d " " -f 2)
version=$(curl https://git.pyro.monster/pyro/tetanus/releases/tag/latest | grep "<title>" | cut -d ">" -f 2 | cut -d " " -f 1)
if [[ "$version" == "$current_version" ]]; then
echo "up to date"
else
echo "update needed"
curl https://git.pyro.monster/pyro/tetanus/releases/download/latest/tetanus -o $config_path/new_tetanus
chmod +x $config_path/new_tetanus
if [ "$(stat -c '%u' $path)" -eq 0 ]; then
sudo cp $config_path/new_tetanus $path
else
cp $config_path/new_tetanus $path
fi
echo "version: $version" > $config_path/version
echo "path: $path" >> $config_path/version
echo update complete!
fi