{"config":{"indexing":"full","lang":["en"],"min_search_length":3,"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"gCTF 2023 | LATIZA This document contains some notes about how we solved some of the problems. The idea is to write the process to get to the solution rather than describing them. The hardest part for beginners is going from 0 to 1. The main goal is that everyone from the team can be on the same page about the resources and tools used. The source code of this document is in this repository . tools Main tools used during the competition. nc netcat command is available in Unix. Used to connect to remote services. In this case, several challenges are hosted in a server, and you should interact with the server to get the flag. nc wfw1.2023.ctfcompetition.com 1337 pwntools pwntools is a python library with several useful primitives for CTFs. In particular, we used it as a programmatic replacement for nc . from pwn import * r = remote('wfw1.2023.ctfcompetition.com', 1337) r.sendline('hello') r.recvline() This way, it is easier to automatize the interaction with the server. Decompiler Ghidra Great tool to decompile binaries. You get some pseudo-C code. Pictures of some problems. I've read in the general gctf discord about some alternatives that I haven't tried: - Radare2 - IDA This one seems very good but is not free. - Binary Ninja Debugger dbg - pwndbg is a GDB plug-in that makes debugging with GDB suck less This one works great. Solver Z3 is a powerful theorem prover. You can think about it like an SAT solver on steroids. What was the other alternative mentioned by @alex for C++ symbolic execution? Other UNIX tools readelf strings ??? Hex editor Edit binary files with hex editors. I have used Hex Editor extension from VSCode. misc Everything that doesn't fit in the other categories. MIND THE GAP NPC PAPAPAPA SYMATRIX TOTALLY NOT BRUTE FORCE crypto Usually, it is easy to understand the goal by inspecting the given code. The problem is generally about cracking some insecure crypto primitive involving \"heavy\" math. CURSVED LEAST COMMON GENOMINATOR MHK2 MYTLS PRIMES ZIP pwn You are given an application (usually in a stand-alone binary or a binary running in a server) with some \"clear\" functionality containing a not-so-clear vulnerability. In this case, the goal is to exploit the vulnerability to make the app do something unintended. Some common vulnerabilities are gaining shell access or reading a file you are not supposed to read. GRADEBOOK KCONCAT STORYGEN UBF WATTHEWASM WRITE-FLAG-WHERE reversing You are given an application (usually in a stand-alone binary or a binary running in a server) with an obscure functionality. The first part of the goal is trying to figure out what the application is doing by inspecting the code. AUXIN FLANGTON JXL OLDSCHOOL PNG2 TURTLE ZERMATT web You are given a web application with some functionality. The goal is to exploit some vulnerability in the web application to get the flag. This is where you will find the most common vulnerabilities, like SQL injection, XSS, etc. BIOHAZARD NOTENINJA POSTVIEWER V2 UNDER-CONSTRUCTION VEGGIE SODA sandbox You are given a sandboxed environment where you can run some code. The goal is to exploit some vulnerability in the sandbox to get the flag. FASTBOX GVISOR LIGHTBOX V8BOX","title":"Home"},{"location":"#gctf-2023-latiza","text":"This document contains some notes about how we solved some of the problems. The idea is to write the process to get to the solution rather than describing them. The hardest part for beginners is going from 0 to 1. The main goal is that everyone from the team can be on the same page about the resources and tools used. The source code of this document is in this repository .","title":"gCTF 2023 | LATIZA"},{"location":"#tools","text":"Main tools used during the competition. nc netcat command is available in Unix. Used to connect to remote services. In this case, several challenges are hosted in a server, and you should interact with the server to get the flag. nc wfw1.2023.ctfcompetition.com 1337 pwntools pwntools is a python library with several useful primitives for CTFs. In particular, we used it as a programmatic replacement for nc . from pwn import * r = remote('wfw1.2023.ctfcompetition.com', 1337) r.sendline('hello') r.recvline() This way, it is easier to automatize the interaction with the server. Decompiler Ghidra Great tool to decompile binaries. You get some pseudo-C code. Pictures of some problems. I've read in the general gctf discord about some alternatives that I haven't tried: - Radare2 - IDA This one seems very good but is not free. - Binary Ninja Debugger dbg - pwndbg is a GDB plug-in that makes debugging with GDB suck less This one works great. Solver Z3 is a powerful theorem prover. You can think about it like an SAT solver on steroids. What was the other alternative mentioned by @alex for C++ symbolic execution? Other UNIX tools readelf strings ??? Hex editor Edit binary files with hex editors. I have used Hex Editor extension from VSCode.","title":"tools"},{"location":"#misc","text":"Everything that doesn't fit in the other categories. MIND THE GAP NPC PAPAPAPA SYMATRIX TOTALLY NOT BRUTE FORCE","title":"misc"},{"location":"#crypto","text":"Usually, it is easy to understand the goal by inspecting the given code. The problem is generally about cracking some insecure crypto primitive involving \"heavy\" math. CURSVED LEAST COMMON GENOMINATOR MHK2 MYTLS PRIMES ZIP","title":"crypto"},{"location":"#pwn","text":"You are given an application (usually in a stand-alone binary or a binary running in a server) with some \"clear\" functionality containing a not-so-clear vulnerability. In this case, the goal is to exploit the vulnerability to make the app do something unintended. Some common vulnerabilities are gaining shell access or reading a file you are not supposed to read. GRADEBOOK KCONCAT STORYGEN UBF WATTHEWASM WRITE-FLAG-WHERE","title":"pwn"},{"location":"#reversing","text":"You are given an application (usually in a stand-alone binary or a binary running in a server) with an obscure functionality. The first part of the goal is trying to figure out what the application is doing by inspecting the code. AUXIN FLANGTON JXL OLDSCHOOL PNG2 TURTLE ZERMATT","title":"reversing"},{"location":"#web","text":"You are given a web application with some functionality. The goal is to exploit some vulnerability in the web application to get the flag. This is where you will find the most common vulnerabilities, like SQL injection, XSS, etc. BIOHAZARD NOTENINJA POSTVIEWER V2 UNDER-CONSTRUCTION VEGGIE SODA","title":"web"},{"location":"#sandbox","text":"You are given a sandboxed environment where you can run some code. The goal is to exploit some vulnerability in the sandbox to get the flag. FASTBOX GVISOR LIGHTBOX V8BOX","title":"sandbox"},{"location":"mind-the-gap/","text":"Mind the gap You are given a script minesweeper.py and text file gameboard.txt . Invoking the python script requires pygame to be installed. pip install pygame It takes several seconds to load. After loading we get a minesweeper game Inspect the script and search for CTF / FLAG etc. We see this part of the code if len(violations) == 0: bits = [] for x in range(GRID_WIDTH): bit = 1 if validate_grid[23][x].state in [10, 11] else 0 bits.append(bit) flag = hashlib.sha256(bytes(bits)).hexdigest() print(f'Flag: CTF{{{flag}}}') else: print(violations) Basically we need to solve it, and the we will be able to reconstruct the flag from the solution. Inspect gameboard.txt -- it looks like the board in a simple text format. The board seems very structured. It looks like putting one mine will collapse a lot of other cells, but not all. \u276f wc gameboard.txt 1631 198991 5876831 gameboard.txt The board is 1600 x 3600 cels. It is huge. It is not possible to solve it by hand. We need to solve the board with code. Idea 1 use backtracking, and pray to be fast enough. Idea 2 skip backtracking and use SAT solver (Z3). This is what we did. With Z3 we can create variables and create constraints on the values they can get, then ask for a solution. If there is a solution, Z3 will give us the values for the variables. Z3 will find a solution in a reasonable\u2122\ufe0f time. Check the code to generate the solution. With the solution we can easily generate the flag by using the code from the game. import z3 with open('gameboard.txt') as f: data = f.read().split('\\n') rows = len(data) cols = len(data[0]) print(rows, cols, flush=True) solver = z3.Solver() vars = {} def get_var(i, j): assert data[i][j] == '9' if (i, j) not in vars: vars[i, j] = z3.Int(f'var_{i}_{j}') solver.add(0 <= vars[i, j]) solver.add(vars[i, j] <= 1) return vars[i, j] for i in range(rows): for j in range(cols): if data[i][j] in '12345678': flags_on = 0 pending = [] for dx in [-1, 0, 1]: for dy in [-1, 0, 1]: if dx == 0 and dy == 0: continue nx = i + dx ny = j + dy if 0 <= nx < rows and 0 <= ny < cols: if data[nx][ny] == 'B': flags_on += 1 elif data[nx][ny] == '9': pending.append(get_var(nx, ny)) if not pending: continue solver.add(z3.Sum(pending) + flags_on == int(data[i][j])) print(len(vars)) for i in range(rows): for j in range(cols): if data[i][j] == '9': assert (i, j) in vars print(\"Solving...\") print(solver.check()) for (i, j), v in vars.items(): if solver.model()[v] == 1: print(i, j)","title":"Mind the gap"},{"location":"mind-the-gap/#mind-the-gap","text":"You are given a script minesweeper.py and text file gameboard.txt . Invoking the python script requires pygame to be installed. pip install pygame It takes several seconds to load. After loading we get a minesweeper game Inspect the script and search for CTF / FLAG etc. We see this part of the code if len(violations) == 0: bits = [] for x in range(GRID_WIDTH): bit = 1 if validate_grid[23][x].state in [10, 11] else 0 bits.append(bit) flag = hashlib.sha256(bytes(bits)).hexdigest() print(f'Flag: CTF{{{flag}}}') else: print(violations) Basically we need to solve it, and the we will be able to reconstruct the flag from the solution. Inspect gameboard.txt -- it looks like the board in a simple text format. The board seems very structured. It looks like putting one mine will collapse a lot of other cells, but not all. \u276f wc gameboard.txt 1631 198991 5876831 gameboard.txt The board is 1600 x 3600 cels. It is huge. It is not possible to solve it by hand. We need to solve the board with code. Idea 1 use backtracking, and pray to be fast enough. Idea 2 skip backtracking and use SAT solver (Z3). This is what we did. With Z3 we can create variables and create constraints on the values they can get, then ask for a solution. If there is a solution, Z3 will give us the values for the variables. Z3 will find a solution in a reasonable\u2122\ufe0f time. Check the code to generate the solution. With the solution we can easily generate the flag by using the code from the game. import z3 with open('gameboard.txt') as f: data = f.read().split('\\n') rows = len(data) cols = len(data[0]) print(rows, cols, flush=True) solver = z3.Solver() vars = {} def get_var(i, j): assert data[i][j] == '9' if (i, j) not in vars: vars[i, j] = z3.Int(f'var_{i}_{j}') solver.add(0 <= vars[i, j]) solver.add(vars[i, j] <= 1) return vars[i, j] for i in range(rows): for j in range(cols): if data[i][j] in '12345678': flags_on = 0 pending = [] for dx in [-1, 0, 1]: for dy in [-1, 0, 1]: if dx == 0 and dy == 0: continue nx = i + dx ny = j + dy if 0 <= nx < rows and 0 <= ny < cols: if data[nx][ny] == 'B': flags_on += 1 elif data[nx][ny] == '9': pending.append(get_var(nx, ny)) if not pending: continue solver.add(z3.Sum(pending) + flags_on == int(data[i][j])) print(len(vars)) for i in range(rows): for j in range(cols): if data[i][j] == '9': assert (i, j) in vars print(\"Solving...\") print(solver.check()) for (i, j), v in vars.items(): if solver.model()[v] == 1: print(i, j)","title":"Mind the gap"},{"location":"write-flag-where/","text":"WRITE FLAG WHERE This challenges had three parts with increasing difficulty. During competition we solved up to part 2. The solution to part 2 uses a very nice trick that was not the intended solution. Part 1 In this problem you are given a binary chal with a library libc.so.6 . \u276f file chal chal: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=325b22ba12d76ae327d8eb123e929cece1743e1e, for GNU/Linux 3.2.0, not stripped \u276f file libc.so.6 libc.so.6: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=69389d485a9793dbe873f0ea2c93e02efaa9aa3d, for GNU/Linux 3.2.0, stripped Ok, this is an ELF binary, dynamically linked, we can run it on Linux. We are also given a server we can connect to: nc wfw1.2023.ctfcompetition.com 1337 This challenge is not a classical pwn In order to solve it will take skills of your own An excellent primitive you get for free Choose an address and I will write what I see But the author is cursed or perhaps it's just out of spite For the flag that you seek is the thing you will write ASLR isn't the challenge so I'll tell you what I'll give you my mappings so that you'll have a shot. 5626cbcd7000-5626cbcd8000 r--p 00000000 00:11e 810424 /home/user/chal 5626cbcd8000-5626cbcd9000 r-xp 00001000 00:11e 810424 /home/user/chal 5626cbcd9000-5626cbcda000 r--p 00002000 00:11e 810424 /home/user/chal 5626cbcda000-5626cbcdb000 r--p 00002000 00:11e 810424 /home/user/chal 5626cbcdb000-5626cbcdc000 rw-p 00003000 00:11e 810424 /home/user/chal 5626cbcdc000-5626cbcdd000 rw-p 00000000 00:00 0 7f4d9e838000-7f4d9e83b000 rw-p 00000000 00:00 0 7f4d9e83b000-7f4d9e863000 r--p 00000000 00:11e 811203 /usr/lib/x86_64-linux-gnu/libc.so.6 7f4d9e863000-7f4d9e9f8000 r-xp 00028000 00:11e 811203 /usr/lib/x86_64-linux-gnu/libc.so.6 7f4d9e9f8000-7f4d9ea50000 r--p 001bd000 00:11e 811203 /usr/lib/x86_64-linux-gnu/libc.so.6 7f4d9ea50000-7f4d9ea54000 r--p 00214000 00:11e 811203 /usr/lib/x86_64-linux-gnu/libc.so.6 7f4d9ea54000-7f4d9ea56000 rw-p 00218000 00:11e 811203 /usr/lib/x86_64-linux-gnu/libc.so.6 7f4d9ea56000-7f4d9ea63000 rw-p 00000000 00:00 0 7f4d9ea65000-7f4d9ea67000 rw-p 00000000 00:00 0 7f4d9ea67000-7f4d9ea69000 r--p 00000000 00:11e 811185 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 7f4d9ea69000-7f4d9ea93000 r-xp 00002000 00:11e 811185 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 7f4d9ea93000-7f4d9ea9e000 r--p 0002c000 00:11e 811185 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 7f4d9ea9f000-7f4d9eaa1000 r--p 00037000 00:11e 811185 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 7f4d9eaa1000-7f4d9eaa3000 rw-p 00039000 00:11e 811185 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 7ffe76706000-7ffe76727000 rw-p 00000000 00:00 0 [stack] 7ffe767e9000-7ffe767ed000 r--p 00000000 00:00 0 [vvar] 7ffe767ed000-7ffe767ef000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall] Give me an address and a length just so: