在Rust中通过TLS重定向stdio

问题描述

我正在尝试在ncat中复制“ -e”选项,以将Rust中的stdio重定向到远程ncat侦听器。

我可以通过使用dup2在TcpStream上执行此操作,然后在Rust中执行“ / bin / sh”命令。但是,我不知道如何通过TLS进行操作,因为重定向似乎需要文件描述符,而TlsStream似乎没有提供文件描述符。

有人可以建议吗?

编辑2020年11月2日

Rust论坛中的某个人已经与我(https://users.rust-lang.org/t/redirect-stdio-pipes-and-file-descriptors/50751/8)分享了一个解决方案,现在我正在尝试研究如何通过TLS连接重定向stdio。

let mut command_output = std::process::Command::new("/bin/sh")
    .stdin(Stdio::piped())
    .stdout(Stdio::piped())
    .stderr(Stdio::piped())
    .spawn()
    .expect("cannot execute command");

let mut command_stdin = command_output.stdin.unwrap();
println!("command_stdin {}",command_stdin.as_raw_fd());

let copy_stdin_thread = std::thread::spawn(move || {
    io::copy(&mut io::stdin(),&mut command_stdin)
});
        
let mut command_stdout = command_output.stdout.unwrap();
println!("command_stdout {}",command_stdout.as_raw_fd());

let copy_stdout_thread = std::thread::spawn(move || {
   io::copy(&mut command_stdout,&mut io::stdout())
});

let command_stderr = command_output.stderr.unwrap();
println!("command_stderr {}",command_stderr.as_raw_fd());

let copy_stderr_thread = std::thread::spawn(move || {
    io::copy(&mut command_stderr,&mut io::stderr())
});

copy_stdin_thread.join().unwrap()?;
copy_stdout_thread.join().unwrap()?;
copy_stderr_thread.join().unwrap()?;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)