; ─────────────── S U B R O U T I N E ─────────────── ; FUNCTION CHUNK AT .text:00401A2F SIZE 0000123D BYTES ; Author: Cha0s ; Date: ; Tags:
Functions in this chunk
LA-CTF 2024 rev/aplet321
Everytime i’m about to participate on a new ctf, the first thing i do is to search for the past edition challenges, here is my writeup on the LA-CTF 2024 aplet321 reversing challenge
Challenge description
The challenge provides the following description:
Unlike Aplet123, Aplet321 might give you the flag if you beg him enough.After poking with the binary for a bit, it wouldn’t do anything apart from that:
lactf-archive/2024/rev/aplet321$ ./aplet321
hi, i'm aplet321. how can i help?
test
so rudeSo it was time for some static analysis.
Understanding the logic
After opening the binary on ghidra and doing some basic variable renaming, we are going to have the following pseudo-code:
| |
The first thing that catches my attention are the strncmp for “pretty” and “please”, if the comparison is successful, the counter for the respective word is incremented, by that we already know what the program is expecting. There is also a reference to strstr, which basically only checks for the presence of some string.
The following while condition may seem confusing at first
| |
But after poking it for a while, its simply iterates through each word until both the original user_input and the input_ptr points at the same address, meaning the whole input was processed.
For comparison purposes, here is a python snippet with the same function:
| |
Solving
We already know what the program is expecting, but how much of each?
The following condition is the one to decide if we are going to get the flag:
| |
We can solve this simple equation and discover how much of each word we need to satisfy the condition.
x + y = 54
x - y = -24
(x, y) = (15, 39)Being x = pretty and y = please, we just concatenate everything with a space to separate, adding flag to the end to satisty the strstr condition.
Our final payload would be:
pretty pretty pretty pretty pretty pretty pretty pretty pretty pretty pretty pretty pretty pretty pretty please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please flagAnd after running it, we get the flag:
lactf-archive/2024/rev/aplet321$ ./aplet321
hi, i'm aplet321. how can i help?
pretty pretty pretty pretty pretty pretty pretty pretty pretty pretty pretty pretty pretty pretty pretty please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please flag
ok here's your flag
lactf{next_year_i'll_make_aplet456_hqp3c1a7bip5bmnc}