c-重定向执行外壳代码的程序的输出



我有一个执行外壳代码的小程序:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char shellcode[]="here is the bytecode";

int main(int main, char *argv[]) {
      void (*ret)();
      ret = (void (*)())shellcode;
      (void)(*ret)();
}

我用:gcc -o file file.c -fno-stack-protector -z execstack编译它。然后我尝试将输出重定向到一个文件:./file > tmp.txt但它不起作用。既不是./file 2> tmp.txt也不是./file &> tmp.txt

输出始终打印到屏幕上,而从不打印到文件中。有人能帮我吗?我真的需要那个外壳代码的输出。

如果重定向stdout和stderr不起作用,则程序可能直接访问终端。要捕获直接的终端输出,您需要在连接了pseduo-tty的情况下启动程序。最简单的方法(我知道)是使用ssh。尝试:

ssh -qt localhost "./file" > tmp.txt 2>&1

您需要安装ssh密钥以避免输入登录凭据。

编辑:哎呀,我的重定向顺序不对。新手失误。

最新更新