She Sells Sea Shells

Writeup for She Sells C Shells (Rev) - HackTheBox Cyber Apocalypse - Intergalactic Chase CTF (2023) πŸ’œ

Description

You've arrived in the Galactic Archive, sure that a critical clue is hidden here. You wait anxiously for a terminal to boot up, hiding in the shadows from the guards hunting for you. Unfortunately, it looks like you'll need a password to get what you need without setting off the alarms...

Solution

We run a shell and have a get_flag option that takes a password.

ltrace ./shell
printf("ctfsh-$ ")                                                      = 8
fgets(ctfsh-$ test
"test\n", 1024, 0x7fe582e2e980)                                   = 0x7ffd880fa6b0
strchr("test\n", '\n')                                                  = "\n"
strdup("test")                                                          = 0x555a30952ac0
strtok("test", " ")                                                     = "test"
strtok(nil, " ")                                                        = nil
strcmp("ls", "test")                                                    = -8
strcmp("whoami", "test")                                                = 3
strcmp("cat", "test")                                                   = -17
strcmp("getflag", "test")                                               = -13
strcmp("help", "test")                                                  = -12
fprintf(0x7fe582e2f5c0, "No such command `%s`\n", "test"No such command `test`
)               = 23
free(0x555a30952ac0)                                                    = <void>
printf("ctfsh-$ ")                                                      = 8
fgets(ctfsh-$

get_flag looks like.

Setup a breakpoint at the memcmp and find out what t equals.

So it's like this:

  • our 77 byte input is XORd with m1

  • the output is compared with t

  • if it matches, our input is XORd with m2

  • the result is our flag

Plan of action:

  • XOR t with m2 to recover out input (plaintext)

Copied and pasted the ghidra assembly and asked ChatGPT to extract the XXh values.

So we XOR them and get the flag!

Flag: HTB{cr4ck1ng_0p3n_sh3ll5_by_th3_s34_sh0r3}

Last updated