2

I'm working on a CTF challenge that is an introduction to smashing the stack. I have the binary working in GDB, and can overwrite the correct part of the stack with printable characters.

The challenge, however, is that the binary expects 0xdeadbeef in the correct stack location - and I'm a bit stumped on how to input that value. I've seen examples online where python is used to supply hex values as the argument to the binary - but this particular binary runs, prints a query message, THEN expects input, instead of just reading an argument.

What is the best way to handle this, initially in GDB to confirm my approach, and then using NC to receive the actual flag? I'm working on Ubuntu.

Apologies for asking a basic question, but this has been tripping me up.

Thank you!

2
  • 0xdeadbeef is not non-printable. It is what is commonly known ashexspeak
    – fpmurphy
    May 17 '18 at 2:42
  • Go read this answer.
    – perror
    Sep 18 '18 at 12:44
4

Well, you have several options to do so. These are the two simplest:

Supplying the input through the pipeline:

$ python -c "print '\xde\xad\xbe\xef'" | ./binary
$ python -c "print 0xdeadbeef" | ./binary

Supplying the input from within GDB:

(gdb) r <<< $(python -c "print '\xde\xad\xbe\xef'")
(gdb) r <<< $(python -c "print 0xdeadbeef")
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.