I am having trouble solving a challenge that requires using a buffer overflow to overwrite the return address and call another function that gives a shell. The program prompts the user for input, which can be used to overflow the buffer.
I can manually overwrite the address in gdb and get the shell, however, when I attempt to input data to the program through a file, using "run < input.txt" (still in gdb) it doesn't work - I just get a segfault. Even when the memory layout after inputting the data looks exactly the same and stepping through the program does correctly return to and execute the "give_shell()" function.
Even if I only input a single character using the input file and then manually overwrite the return address it does not work. The only way I can get the shell is to enter input manually, break, overwrite the return address, and then continue.
Does anyone have any idea why the execution would be different when I manually enter the input to the program vs. sending input through a file within gdb?