I participated in DefCamp CTF 2024 Qualifier as part of the SaturnX team. And our team took 7th place. The finals are limited to 15 places, so our team qualified for the finals in Romania!!😆🥳
I focused on the pwnable challenges and solved all the pwnable challenges by myself within the competition time.
Pwn
ftp-console(90 solves)
Challenge Description
We got a very strange ftp console? Can you retrive the flag?
Analysis
When opening the binary through IDA, there was a clear stack buffer overflow vulnerability. There was also a leak vulnerability because the address of the system function was printed. Since it was a 32-bit binary, 32-bit ROP was performed. Since the server’s libc and the local libc versions were the same, there was no need to match the libc versions separately!
It’s early morning, and the caffeine hasn’t quite kicked in yet. As you sip your cup of coffee, you notice something odd – a mysterious program named cooffee is running on your system.
Analysis
The binary for this challenge had a clear format string bug and stack overflow vulnerability. There was also a leak vulnerability because the address of the printf function was printed.
Someone backdoored us with a strange PAM module, and now anyone can log in with aptssh:aptssh. I think they were able to get our flag.
Analysis
There was no binary for the challenge. After starting the challenge instance and connecting via ssh with the provided username and password, two base64 encoded binaries were provided.
One binary was the linked binary and one was the object file before linking.
Since the two operate in the same way, I will explain them as a single binary.
In the challenge description, it said that someone installed a backdoor via a suspicious PAM module. So I started analyzing it after thinking that this was that PAM module.
I was able to find the core logic in the pam_sm_authenticate function, and through it I was able to see that it performs user authentication when connecting to ssh.
Solve
If you look closely at the logic of the above pseudo code, you can see that authentication can be done with another user (sshuser). There is also one more suspicious logic.
This is the logic right above. When the length of the password is 0x64 or more, you can see that the authentication is performed by comparing the 8 bytes (excluding null bytes) that follow if they are the same. Through this backdoor logic, you can log in as sshuser.
Here’s my note taking app! If you manage to crash the application make sure to wait 2-3minutes for it to restart. You don’t have to restart the task.
Analysis
This challenge was a Web + Pwnable challenge and took the longest to solve.
The binary was stripped and statically compiled, so it took a long time to analyze.
However, because the vulnerability was simple, it didn’t take long to find it.
There was a part that added notes written in binary to an HTML file, and as I continued to add notes, the contents of the notes continued to be added to the HTML file, causing an overflow.
However, the size of the content that could be added to a note was limited to 0x20, and it was difficult to perform ROP with only the content of the note.
Solve
There was also one more obstacle: when sending an HTTP request, bytes like null bytes or \x2b were all url-encoded, making it difficult to write the payload. I struggled a lot here. However, if you look closely at the binary again, there was logic to replace these bytes.
With the help of the above logic, I was able to write the payload.
There were username and password variables on the global variable side, and I could input 0xff here.
Therefore, I wrote a ROP chain on the username and was able to overwrite rbp through the overflow vulnerability, and through this, I performed a stack pivot and executed the ROP chain on the username side.
However, for these Web + Pwn challenges, you can’t just run the shell, you have to get the flag through reverse shell. This is where I wasted a lot of time. I tried to open the reverse shell through execve syscall, but something didn’t work properly in the process of passing the arguments.
Also, here’s a funny thing, to open a reverse shell, the domain name must not contain 0, and the port number must not contain 0 either. This is because the input is weird due to url encoding! lol
At that time, I had not set up a domain name on the my Vultr server, so I borrowed another team member’s server and wrote an exploit!
Having successfully completed this DefCamp 2024 CTF qual, I am participating in the overseas CTF finals offline for the first time! The finals will be held in the Attack & Defense format, so I am really looking forward to it! See you in Romania!