Space pirate: Entrypoint

A standard FSB challenge

Initial Impressions

We are given a 64-bit binary file that upon running gives us two options.

โ”Œโ”€โ”€(kaliใ‰ฟkali)-[~/Desktop/CTF/PWN/htb_spacepirate_entrypoint]
โ””โ”€$ ./sp_entrypoint 


			 Authentication System

โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“          โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“          โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“          โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“          โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“          โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“          โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“โ–’โ–’โ–“โ–“โ–“โ–’โ–’โ–’โ–’โ–’โ–“โ–“โ–’โ–‘โ–’โ–“โ–“โ–“โ–‘โ–‘โ–“โ–“โ–“โ–“โ–“  โ–‘  โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“     โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“โ–’โ–’โ–“โ–“โ–“โ–’โ–’โ–’โ–’โ–’โ–“โ–“โ–‘โ–‘โ–‘โ–“โ–“โ–“โ–’โ–‘โ–“โ–“โ–“โ–“โ–“ โ–‘   โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“     โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–’โ–’โ–“โ–“โ–“โ–’โ–’โ–’โ–’โ–’โ–“โ–“โ–‘โ–‘โ–‘โ–“โ–“โ–“โ–‘โ–‘โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–’โ–’โ–“โ–“โ–“โ–’โ–’โ–’โ–’โ–‘โ–“โ–“โ–‘โ–‘โ–‘โ–“โ–“โ–“โ–‘โ–‘โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–’โ–’โ–“โ–“โ–“โ–’โ–’โ–’โ–’โ–’โ–“โ–“โ–’โ–‘โ–‘โ–“โ–“โ–“โ–‘โ–‘โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–’โ–’โ–“โ–“โ–“โ–’โ–’โ–’โ–’โ–‘โ–“โ–“โ–‘โ–‘โ–‘โ–“โ–“โ–“โ–‘ โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–’โ–’โ–“โ–“โ–“โ–’โ–’โ–’โ–’โ–’โ–“โ–“โ–‘โ–‘โ–‘โ–“โ–“โ–’โ–‘โ–‘โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“                                                        โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–’โ–’โ–“โ–“โ–“โ–’โ–’โ–‘โ–‘โ–‘โ–“โ–“โ–‘โ–‘โ–‘โ–“โ–“โ–’โ–‘ โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–’โ–’โ–“โ–“โ–“โ–’โ–‘โ–‘โ–‘โ–’โ–“โ–“โ–‘โ–‘โ–‘โ–“โ–“โ–’ โ–‘โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–’โ–’โ–“โ–“โ–“โ–‘โ–‘โ–‘โ–‘โ–‘โ–“โ–“โ–‘โ–‘โ–‘โ–“โ–“โ–“  โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–’โ–‘โ–“โ–“โ–“โ–’โ–‘โ–‘โ–‘โ–‘โ–“โ–“โ–’  โ–“โ–“โ–’  โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–’โ–’โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“  โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–’โ–’โ–“โ–“โ–“โ–‘โ–’โ–‘โ–‘โ–‘โ–“โ–“โ–‘  โ–“โ–“โ–’  โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“โ–‘โ–’โ–“โ–“โ–“โ–‘โ–‘โ–‘โ–‘โ–‘โ–“โ–“โ–‘  โ–“โ–“โ–’  โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“     โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“โ–’โ–‘โ–“โ–“โ–“โ–‘โ–‘โ–‘โ–‘ โ–“โ–“   โ–“โ–“โ–’  โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“  โ–“โ–“โ–“     โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“     โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“          โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“          โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“          โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“          โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“          โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“          โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“


1. Scan card ๐Ÿ’ณ
2. Insert password โ†ช๏ธ
> 

Looking at the decompiled main function in Ghidra, it gives us two functions of interest, open_door and check_pass.

The open_door() function prints out the flag to us while the check_pass() authenticates us if our input is 0nlyTh30r1g1n4lCr3wM3mb3r5C4nP455.

However, that is impossible as the input is only accepting 15 bytes of input (Oxf).

Looking back at the main function, we see a possible FSB vulnerability on line 27 and 29 where our input is being displayed directly with printf.

This can be easily tested with %p which leaks a value of the stack.

We can also see that the variable declared earlier local_48 is on the stack 0xdeadbeef.

Exploit

To successfully get the flag, we need to

  1. Leak the location of the pointer tolocal_48 on the stack

  2. Overwrite the contents of local_48 to be equivalent 0xdead1337 to pass the check

Using %p.%p.%p.%p.%p.%p.%p, we can see that local_48 is on the 6th position on the stack.

With the use of pwndbg, we can see that the pointer to local_48 is on the 7th position on the stack 0x7fffffffdc68 pointing to 0x7fffffffdc60.

We can then $hn to overwrite the last word (4 bytes) of 0xdeadbeef with %4914c which translates to 1337 in decimal., making local_48 = 0xdead1337.

The %n specifier takes in a pointer (memory address) and writes there the number of characters written so far. If we can control the input, we can control how many characters are written and also where we write to.

This makes our final payload %4919c%7$hn, with %7 referring to the pointer to local_48 and $hn referring to the beef portion of 0xdeadbeef which we are trying to overwrite.

Last updated