sssshhhh
Prologue¶
Difficulty: beginner
Category: reverse engineering
Solved: 81
Description
Great news! We found the Kookaburras!... Bad news.. They're locked up. We've managed to get access to the central terminal and ripped a binary off of it for you to analyse. Maybe you can find a way to free our friends?
Input files:
NB:
-
Following indices bases system is used to avoid ambiguity. Whenever element of a collection is referenced by number, 0-based index implied.
Ie, element
0
of list[1, 2, 4, 8, 16]
is1
, Element3
is8
.When element is reference in explanation with word (first, third...), 1-based system is implied.
Ie, first character of string
Hello World!
isH
, fifth iso
.
- Solution code was redacted for readability purposes. Due to time pressure during the competition I was using a lot of one-letter variables and questionable code structure.
- I am using gdb with pwndbg plugin
My struggle¶
What do we do the first when we have an unknown binary? Lets run it:
1 2 |
|
When we try to ssh to it we see that it requires a password. So lets open in Ghidra and see if we can find it.
main
function has calls startLogger()
and RunSSH()
. Second call is interesting - it should initialise user accounts somehow. In code there are a lot of
references to https://github.com/charmbracelet/ssh which is a go package for embeded ssh server. In the documentation and examples of the
library we can see how usually password authentication is configured https://pkg.go.dev/github.com/gliderlabs/ssh#PasswordAuth, so we know what
to look for.
Two interesting lines in RunSSH()
that caught my eye:
1 2 |
|
func2
is taken right before PasswordAuth setup. Its worth
to check the code of the func2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
memequal
. Strangely, memequel
doesn't take any params. Eventually I checked disassembly for this line:
1 2 3 4 |
|
We can see password in plain text at address DAT_0067ec99, now lets try to connect:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
We can see line -> No valid command
. This looks like a hint of the next obstacle. Our work with Ghidra is not finished yet. There should be handler somewhere with
commands list. We are looking for something that calculates elapsed time or prints kookaburras count. Eventually I restarted
server with gdb and set a breakpoint to printf function found through stack trace that handler for the server is func_8_1.
There we can see following check:
1 2 3 4 5 6 7 8 9 10 11 |
|
0x68546b636f6c6e55 0x6c654365 0x736c
to ascii
and reversing order of each number (little endian) gives us the command. Lets try it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
And it did nothing - I still see no valid command
. Well actually now there is one more line Welcome Warden, running command
, but then it says command is still invalid.
In code inside the if
block there is os.GetEnv()
, so likely this is where flag comes from. Restarting server with following command:
1 |
|
Connecting to server now gave the flag.
Epilogue¶
- Official website: https://downunderctf.com/
- Official writeups: https://github.com/DownUnderCTF/Challenges_2024_Public