Sitemap

Secure Password Database

5 min readOct 12, 2026

--

Hello folks!, today we are going to solve Secure Password Database CTF from Cylab Security Academy formerly PicoCTF.
This is going to be my first writeup so apologies in advance :).

First of all we will download the binary system.out from the challenge page, and start the instance and download the binary.

Press enter or click to view image in full size

Now lets try to run the file,
first we will have to give it permission to execute with
chmod +x system.out

now we get,

Press enter or click to view image in full size

So we have to give it hash to get our flag.

Now, lets start reversing the binary and find the logic we need to reach our destiny(flag)
I’m using Ghidra which is open source tool by NSA.
Let’s see what functions we have here

Press enter or click to view image in full size

as always most of it is useless for us, we will focus on hash, make secret and main functions.

This is the function flow graph we will be focusing on.

Make Secret Function

Look here carefully, we can see that this is XOR obfuscation of obf_bytes with 0xaa and bytes are hardcoded, which are as follow

obf_bytes

Press enter or click to view image in full size

Note that this is hardcoded and we can say that make_secret is not making any secret so it always returns a fixed value. Also Ghidra shows make_secret as void, the actual return is the so called secret value which is iUbh81!j*hn! .

Get ab5urdher0x’s stories in your inbox

Join Medium for free to get updates from this writer.

There’s also a memory leak in this binary, when we run it and put any number 72 or higher we get the leaked secret value which also proves its hardcoded.

Press enter or click to view image in full size

Also if you are wondering why 72 or 73 to be safe, its due to fact that secret is placed at offset 60 of the buffer by make_secret(buf + 60). It's 12 characters long, so it occupies boxes 60–71, with the terminator at box 72. To print the full secret you need to type a length of at least 72.

Hash Function

Now the make_secret function’s output is hashed with djb2 hash algorithm, a simple non-cryptographic hash. It’s fast and easy to implement, but it’s not suitable for password storage.
It initializes a hash accumulator with a magic seed (0x1505 / 5381), then processes each character of the string by multiplying the current hash by 33 (0x21) and adding the byte.

Main

In main function, we can see this code, if we look closely at line 59 we can see that it is comparing output of our make secret function to generate hash.

Now lets find the hash value we would need to enter

I have written this code for hash calculation

#include <stdio.h>
typedef unsigned char byte;
int main()
{
byte obf_bytes[] = {
0xc3, 0xff, 0xc8, 0xc2, 0x92, 0x9b,
0x8b, 0xc0, 0x80, 0xc2, 0xc4, 0x8b,
0x00
};
byte input[13];
// obfuscate
for (int a = 0; obf_bytes[a] != '\0'; a++) {
input[a] = obf_bytes[a] ^ 0xaa;
}
input[12] = '\0';
// DJB2 hash
long b = 0x1505;
byte *p = input;
while (*p != 0) {
b = *p + b * 0x21;
p++;
}
printf("Hash: %ld\n", b);
return 0;
}

I will name it as hasher.c and run it on my system

We are getting hash as -3209081493549540382.
The hash is a 64-bit value whose top bit is set. As a signed long, it prints as -3209081493549540382. As an unsigned uint64_t, it's 15237662580160011234. Both are the same bits.
The server reads your input with strtoul, which converts the negative decimal back to the unsigned value, and the comparison in main promotes the signed hash to unsigned before matching. Either number works.

Now lets verify if its working by starting instance on Cylab Academy.

Press enter or click to view image in full size

And now the moment of truth,

Press enter or click to view image in full size

Boom, and we have the flag guys.

Few words

The binary had a hash() function, a make_secret() function, a comparison, a rejection message. It reads like a password validator, but guess what it’s a bluff.
This was my first time writing writeup, i made it a little meme heavy, hope you enjoyed it and pls drop your recommendations so i can improve.

Have a great time, folks.

--

--

ab5urdher0x
ab5urdher0x