2

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.

1
  • What does the shellcode do? How does it print its output? Commented Feb 26, 2015 at 14:36

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.