Windowsofopportunity
WindowsOfOpportunity
Date: 26th October 2023 Challenge Author: simonedimaria Difficulty: Easy Category: Reversing
TL;DR
The challenge consisted of reversing a window-sliding algorithm knowing a known byte and/or bruteforcing it.
Description
Challenge scenario
We're given a windows
executable, decompiling it with Ghidra will result in the following:
The code is quite simple and short, it appears to be a simple window-sliding algorithm to check the password (aka flag):
For each index of our input, take the corresponding byte and the following one, add together, and if their sum corresponds to the corresponding index value saved in the global variable arr
the execution continues. Until eventually "The window opens to allow you passage..." (i.e we've discovered the flag).
The code it's already clear enough to be able to reproduce a reversing algorithm, but for readability sake here's a refactored version:
This is instead the global variable arr
:
Solution
We have therefore understood that to solve the challenge we must find the correct bytes which, added together, will give a certain value. But how do we know which is the exact pair of bytes that will give us the flag piece by piece? Thinking about it, the combination of interest is very easy to bruteforce, but it is even easier if we knew even just one byte of the "secret" to discover, given that to obtain the subsequent ones it will be enough to do a simple subtraction! Why? Let's visualize the algorithm:
At the first iteration, the first two bytes (b1
and b2
) are taken into consideration, their sum (sum0
) should be equal to arr[0]
which is 0x9c
(156).
At the second iteration, the second byte (again) and the third byte (b1
and b2
) are taken in consideration, their sum (sum1
) should be equal to arr[1]
which is 0x96
(150).
Therefore, knowing sum0
from arr[0]
, and assuming that we also know b0
then b1
is simply the value of sum0-b0
. Thus obtaining b1
, the value of b2
is simply sum1-b1
and so on.
Aaand, we know b0
! Since the flag starts with HTB{
, therefore b0 == H == 0x48 == 72
. Let's write a simple reversing script in python:
HTB{4_d00r_cl0s35_bu7_4_w1nd0w_0p3n5!}
Last updated