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

C 重定向执行外壳代码的程序的输出,c,bash,shell,io-redirection,shellcode,C,Bash,Shell,Io Redirection,Shellcode,我有一个执行外壳代码的小程序: #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)(); }

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

#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)();
}
#包括
#包括
#包括
char外壳代码[]=“这是字节码”;
int main(int main,char*argv[]{
无效(*ret)();
ret=(void(*)()外壳代码;
(无效)(*ret)();
}
我用:
gcc-o file.c-fno-stack-protector-z execstack
编译它。 然后我尝试将输出重定向到一个文件:
/file>tmp.txt
但它不起作用。这两者都不是:
/file 2>tmp.txt
/file&>tmp.txt


输出总是打印到屏幕上,而不是打印到文件上。有人能帮我吗?我真的需要外壳代码的输出。

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

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

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


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

外壳代码做什么?它是如何打印输出的?它在@ccarton!!非常感谢;)