Compare commits
No commits in common. "main" and "9d93e52" have entirely different histories.
6 changed files with 44 additions and 29 deletions
|
@ -1,5 +1 @@
|
||||||
# Remote Code Execution Program
|
# rust-remote
|
||||||
|
|
||||||
I implemented this for my remote server.
|
|
||||||
|
|
||||||
Sometimes ssh can't be possible because of NAT. That's why I add a public remote server as a relay.
|
|
|
@ -90,7 +90,7 @@ async fn execute(payload: Payload, debug: bool) -> Option<Output> {
|
||||||
if debug {
|
if debug {
|
||||||
eprintln!("Error: Command Execution | {}", err_val);
|
eprintln!("Error: Command Execution | {}", err_val);
|
||||||
}
|
}
|
||||||
None
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,10 +145,6 @@ async fn send(
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if debug {
|
|
||||||
report.print();
|
|
||||||
}
|
|
||||||
|
|
||||||
let report = serde_json::json!(report);
|
let report = serde_json::json!(report);
|
||||||
let result = ws_sender.lock().await.send(report.to_string().into()).await;
|
let result = ws_sender.lock().await.send(report.to_string().into()).await;
|
||||||
match result {
|
match result {
|
||||||
|
|
|
@ -14,7 +14,6 @@ pub enum Runner {
|
||||||
|
|
||||||
impl Runner {
|
impl Runner {
|
||||||
fn print(&self) {
|
fn print(&self) {
|
||||||
println!("-------");
|
|
||||||
match self {
|
match self {
|
||||||
Runner::Server => println!("Runner = Server"),
|
Runner::Server => println!("Runner = Server"),
|
||||||
Runner::Client => println!("Runner = Client"),
|
Runner::Client => println!("Runner = Client"),
|
||||||
|
@ -45,7 +44,6 @@ pub struct Config {
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn print(&self) {
|
pub fn print(&self) {
|
||||||
println!("-------");
|
|
||||||
println!("IP = {}", self.ip);
|
println!("IP = {}", self.ip);
|
||||||
println!("Port = {}", self.port);
|
println!("Port = {}", self.port);
|
||||||
}
|
}
|
||||||
|
@ -53,12 +51,15 @@ impl Config {
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct Payload {
|
pub struct Payload {
|
||||||
|
pub sudo: bool,
|
||||||
|
pub user: String,
|
||||||
pub args: String,
|
pub args: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Payload {
|
impl Payload {
|
||||||
fn print(&self) {
|
fn print(&self) {
|
||||||
println!("-------");
|
println!("sudo = {}", self.sudo);
|
||||||
|
println!("user = {}", self.user);
|
||||||
println!("args = {}", self.args);
|
println!("args = {}", self.args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,6 +88,7 @@ impl Report {
|
||||||
}
|
}
|
||||||
if !self.stderr.is_empty() {
|
if !self.stderr.is_empty() {
|
||||||
println!("Stderr ↓ \n{}", self.stderr);
|
println!("Stderr ↓ \n{}", self.stderr);
|
||||||
|
println!("-------");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,14 @@ async fn main() {
|
||||||
|
|
||||||
match args {
|
match args {
|
||||||
Some((runner_mode, config)) => {
|
Some((runner_mode, config)) => {
|
||||||
|
println!("-------");
|
||||||
|
println!("Runner Mode ↓");
|
||||||
runner_mode.print();
|
runner_mode.print();
|
||||||
|
println!("-------");
|
||||||
|
println!("Config ↓");
|
||||||
config.print();
|
config.print();
|
||||||
|
println!("-------");
|
||||||
|
|
||||||
match runner_mode {
|
match runner_mode {
|
||||||
RunnerMode::State(Runner::Server, false) => {
|
RunnerMode::State(Runner::Server, false) => {
|
||||||
rust_remote::server::start(config, false).await
|
rust_remote::server::start(config, false).await
|
||||||
|
|
|
@ -31,21 +31,15 @@ pub async fn start(config: Config, debug: bool) {
|
||||||
match payload_from_input(debug).await {
|
match payload_from_input(debug).await {
|
||||||
Some(payload) => {
|
Some(payload) => {
|
||||||
if !send(payload, ws_sender, debug).await {
|
if !send(payload, ws_sender, debug).await {
|
||||||
if debug {
|
|
||||||
eprintln!("Error: Send");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
if let Some(report) = receive(ws_receiver, debug).await {
|
match receive(ws_receiver, debug).await {
|
||||||
match serde_json::from_str::<Report>(&report) {
|
Some(report) => match serde_json::from_str::<Report>(&report) {
|
||||||
Ok(report) => report.print(),
|
Ok(report) => report.print(),
|
||||||
Err(err_val) => {
|
Err(_) => {}
|
||||||
if debug {
|
},
|
||||||
eprintln!("Error: Deserialize | {}", err_val);
|
None => todo!(),
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -93,9 +87,31 @@ async fn establish_connection(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn payload_from_input(debug: bool) -> Option<Payload> {
|
async fn payload_from_input(debug: bool) -> Option<Payload> {
|
||||||
println!("-------");
|
println!("User");
|
||||||
|
// let user = match get_input(debug) {
|
||||||
|
// Some(input) => input,
|
||||||
|
// None => return None,
|
||||||
|
// };
|
||||||
|
let user = "tahinli".to_string();
|
||||||
println!("Command");
|
println!("Command");
|
||||||
get_input(debug).map(|args| Payload { args })
|
match get_input(debug) {
|
||||||
|
Some(input) => {
|
||||||
|
let mut sudo = false;
|
||||||
|
let args = match input.split_once(" ") {
|
||||||
|
Some(input_splitted) => {
|
||||||
|
if input_splitted.0 == "sudo" {
|
||||||
|
sudo = true;
|
||||||
|
input_splitted.1.to_string()
|
||||||
|
} else {
|
||||||
|
input
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => input,
|
||||||
|
};
|
||||||
|
Some(Payload { sudo, user, args })
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_input(debug: bool) -> Option<String> {
|
fn get_input(debug: bool) -> Option<String> {
|
||||||
|
|
|
@ -13,8 +13,8 @@ pub fn take_args() -> Option<(RunnerMode, Config)> {
|
||||||
"--server" | "-sv" => runner = Runner::Server,
|
"--server" | "-sv" => runner = Runner::Server,
|
||||||
"--client" | "-cl" => runner = Runner::Client,
|
"--client" | "-cl" => runner = Runner::Client,
|
||||||
"--debug" | "-d" => debug = true,
|
"--debug" | "-d" => debug = true,
|
||||||
"--ip" | "-i" => ip.clone_from(&args[i + 1]),
|
"--ip" | "-i" => ip = args[i + 1].clone(),
|
||||||
"--port" | "-p" => port.clone_from(&args[i + 1]),
|
"--port" | "-p" => port = args[i + 1].clone(),
|
||||||
"--help" | "-h" => {
|
"--help" | "-h" => {
|
||||||
show_help();
|
show_help();
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue