i have this little program that executes a 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)();
}
i compile it with: gcc -o file file.c -fno-stack-protector -z execstack
.
Then i try to redirect the output to a file: ./file > tmp.txt
But it doesn't work. Neither this: ./file 2> tmp.txt
or ./file &> tmp.txt
The output is always printed to the screen, never to the file. Can anyone help me? I really need the output of that shellcode.
If redirecting stdout and stderr doesn't work then the program is likely accessing the terminal directly. To capture direct terminal output you need to launch the program with a pseduo-tty connected. The easiest way to do that (that I'm aware of) is to use ssh. Try:
ssh -qt localhost "./file" > tmp.txt 2>&1
You'll want to install ssh keys to avoid having to enter login credentials.
Edit: Oops, my redirections were in the wrong order. Rookie mistake.