Siber Yıldız - 2019 | CTF (Capture The Flag) Solutions

Hello friends, this year we took part as team WWarriors in Türkiye's Cyber Stars (Siber Yıldız) competition, which was held for the second time, and we finished in 7th place. (The final results have not been announced yet)
I would like to thank my teammates for their effort and hard work.
I wanted to share our solutions with you as well, hoping they will be useful...
You can download the files related to the solutions at the very bottom.
- --- Warm-up Questions
These questions were asked before the competition started, so that the possible flag formats could be understood.
- --Warm-up Question - 1 | Would you like to work at our IT company?
When we open the question, we are greeted by a website

After wandering around it a bit, we view the page source and a comment line greets us
So we immediately run one of the directory scanning tools and try to reach the panel address; dirb or gobuster can be used for this.
In the end, when we find the directory address and go to it, the flag appears right in front of us

FLAG:
RUp2cWFJNHNmekYvQVUyemZXQXRYbFV6Tll4cEQ0UFJGYTVLb25MN3EwdW8ra3VxNncrVFNtRFRNenJ1VlVEVFJBQlRySklHWkU5eGw4Z3o0dWlKSEE9PQ==
- --Warm-up Question - 2 | If you look carefully, you can find the answer.
When we open the question, we are greeted by a piece of text.

The first thing we do is take a look at the source code.

We examine the file given as a hint.
When we examine the algorithm we come across, it tells us that the part after the 4th key will give us the flag.
So we split it right away, counted, and ended up with "87habythi15ng151.php". If you like, you can write a split function or use an online splitter; I didn't bother, it is obvious enough just by looking anyway :)
We take the MD5 hash of the answer 87habythi15ng151.php and we have found the result.
FLAG: 28833db32bb4def17138de776fe2156a
- --- Competition Questions
Now let's look at the actual competition questions.
- --Question - 1 | This one is really easy
When we opened the downloaded file named dikkatli.bak.dms with any text editor, the answer was right in front of us.

FLAG:
RDcxVWV3SUFLM29RazBGV1Rnb0dsbURpWDJnckg1MUgvZ09WWFZmbkFBWXpsNCt5K2ZBMjI2TnRKKzJvZ29xV0lEZ0NSK1lIMklWRkRyOC9XbWpOcEE9PQ==
- --Question - 2 | You are still warming up
On the page that opened, we went straight to viewing the source and saw that there was script code.

To save time, before trying to decode it, let's copy it and pass it to console.log().

We were greeted by an error; we didn't give up right away, decided to take a look at the error, and bingo.

FLAG:
NjJJdTJZRzZkS2FTa1p4Wi91dFpsdWpMRmNyOExQTXdIYUFiMkY1ZEtsS3gveUhGQkVyUFN5QWsxbUNIb2RZOTRyeGZiSHpUeGEyQ0puQ3NFSllENkE9PQ==
- --Question - 3 | Everything is virtual, the network is real
In my opinion this is one of the most annoying questions; we only managed to solve it in the final hours. If we knew Cisco, maybe we would have solved it more easily :D
A pcap file comes out of the file we downloaded, so we set about examining it with WireShark.

When we examined the capture, we saw URL browsing, nmap logs and meaningless packets. When we exported the files inside it, we again found meaningless files, a whole lot of things that would be of no use to us...

However, one single file inside it that could be useful caught our attention: there was an sslkeylog.log. If you ask what that is: if we have the secret log file, we can decrypt the traffic going over SSL even without having the server key.

Now that we have this file, we can add it to Wireshark. We click Edit>Preferences and select Protocols>SSL from the left menu. In the (Pre)-Master-Secret log filename field we choose the file we downloaded and save. Now we can also read the traffic going over SSL.

We go back to Wireshark and continue examining. During the examination, a file named 99037582138585721057129547823.pkt had been requested.

To see the request in more detail, if you right-click it and choose Follow>Http Stream you can see the outgoing GET request.

The response was OK (200), but no file came back. So we downloaded this file from the remote server. We did some quick research on how we could open the file and found that it was a file created for Cisco Packet Tracer (a network simulator that Cisco developed for its own devices), and we downloaded the program.
We opened the program and loaded our file into it.

We searched this way and that, there was no corner of the program we didn't go into, but we couldn't find anything useful.
In the end, saving the config settings of the Router device took us to the next stage.

When we opened the saved file, there was a username and a password in it.

While researching how we could crack this password, we found an online tool. (//ifm.net.nz/cookbooks/passwordcracker.html)
When we entered the password, the answer came back as "flag md5(r0uterP@ss)", so we took the MD5 and solved the question.

FLAG: be4a5b6e929ad88d4f88ad7435ed2eb9
- --Question - 4 | OBURIX's password
Once again we are faced with a pcap file; we open it and start examining.

There was a hint in the name of the question, and during the examination the OBEX protocol caught our attention. Since this protocol is used for file exchange, we assumed that a png file had been sent over Bluetooth and thought of finding the packet carrying the png data by using the png.chunk.data filter; in the results, the info column said usom.png, so we had found the right packet.
On the relevant frame, we right-click OBEX Protocol>Portable Network Graphics and press Show Packet Bytes. The flag appears in front of us.

FLAG:
KOJwaTdxRUoydk9Ea3VpTW8rRVM1UT09
- --Question - 5 | Respect for hard work
This was one of the questions that kept us busy the most. The effort of the person who prepared it really is the kind that deserves respect :)
When we opened the page, we were greeted by the text “Cok calistik,cok. Emege saygi gosterin, kaynak belirtin.” (We worked hard, very hard. Respect the effort, cite your source.)

The "cite your source" part was giving us a hint, so that is what I did from the start: I put it as a source under one of my own posts :) Then, when we clicked it, another page both opened slowly and kept changing.

The text that appeared on the screen had excited us. The fact that it said "we have sent the answer to those who cite the source" was telling me there was an incoming request to my server. In that case I needed to capture the requests coming to the server. Any sniffer tool would do the job, so I opened the sniffer and started waiting. When I went to the place where I had cited the source and clicked the link, it redirected and sent a referer request back.

Honestly, I never thought the question would be solved this way :)
FLAG:
aFZPL0hkSjhvaThneGdIdkFMcUd1UFZLOGNhMGxGSG1lak1VbXlROFVGOFdxVWI3bjFYTW10bVVFMk5ZdTVQV3daRSsxWFZsbmZWZ3dLOFMveHZxQnc9PQ==
- --Question - 6 | The commercial break is over, the film is starting
The question gave us a file named "dump.scm". After a bit of research, it turned out that a file with the .scm extension was a channel list editing format from old TV boxes; we found and downloaded a suitable editor to open it and opened the file.

We quickly go to the link and find Interstellar, one of my favourite films, in front of us. While watching the scene from the film, a nasty crackling sound comes from the background. We immediately convert the video to mp3 and analyze it.

FLAG: c6a107c3072414436a6acf122bf4f349
- --Question - 7 | There are those who look and those who search
When we entered the question, the hash below appeared in front of us.
0827206450376af3dce61d788ddeba21f58dba35257fdb43c1872c096a36287f
When we searched for the hash on Virustotal, it gave us a link in the comments section.
https://www.virustotal.com/tr/file /0827206450376af3dce61d788ddeba21f58dba35257fdb43c1872c096a36287f/analysis/ http://85.111.95.19/a5d8bccb8e1255fc72340eddab8be601-mobile01/cyb3rStar.zip (Pass: Cyberstar_2018!. )

We downloaded the file, took a copy of the application that came out of it, changed its extension to zip, extracted it to a folder and started examining the contents. The images in the resdrawable directory caught our attention, and we started examining them one by one.

When we analyzed the photos, there were about 200 of them, each with a file named thankyoucyberstar.gif inside.

However, only one of them had a different file inside, ortakoy.jpg but that one was password-protected too.

In the exif data of another image, a string made up of jumbled characters caught our attention, and we used this string for the password-protected file; the password was correct and took us to the next step.

The hadibul.b64 file that came out of it was a file encoded with base64, so we immediately found an online decoder (http://base64converter.com/) and decoded it. When we examined the file we realized it was an apk file, and when we installed it on a phone and ran it, the answer was in front of us.

FLAG: 05a24ab2b3f6e4d8309575dca5388eeb
- --Question - 8 | QR code reader
There was a login screen and a page listing the users; we tried to log in with simple combinations but could not get anywhere.
Then, when we took a look at the page with the users, it contained the phrase "Enter the QR code generated specifically for the administrator".

Creating a QR code with SQL injection came to mind right away, and on an online site we turned ' or 1=1# into a QR code.

When we sent the code we had created to the server, we got the result we expected: it had listed the users. There was one user (admin) and two hash values.

When we decoded the hash values, the value of one of the hashes was admin0123456789 and when we logged in, the flag was in front of us.

FLAG:
TWtCM1JTRVZydWpqekNVQzBNR09NUHM2SFh2VTNQbFA5WE5PenQxMWtHa3lDL21ydnJEVXFjZUQycHA1Vloxc0dockh1M28xZXBnd3FkUXJrdEd4REE9PQ==
- --Question - 10 | We are not going to serve everything to you on a plate
We were greeted by a web application called "Servis gibi servis" (A service worthy of the name). It had login and registration pages. The registration page said that registrations had been disabled. And on the login page there was a link for logging in with the demo account.
The address of the link was ws/ws.php?islem=girisYap&kullaniciAdi=demo& parola=demo. When we changed the username to admin, we got a message saying the user does not exist. So we changed the islem parameter and made a request like ws/ws.php?islem=kayitOL&kullaniciAdi=admin& parola=admin. However, the result was "invalid method". This time we changed our approach, and when we swapped the GET method for the POST method, we were able to register.
POST /86d37fde1020e969eca3d6436bddb4f5-04/ws/ws.php?islem=kayitOl&kullaniciAdi=admin&parola=admin&email=test HTTP/1.1 Host: 85.111.95.28 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Referer: http://85.111.95.28/86d37fde1020e969eca3d6436bddb4f5-04/giris.html Accept-Language: en-US,en;q=0.9 Cookie: PHPSESSID=ttjj1d2lcpoagr63qp2596fqb4 Connection: close Content-Type: application/x-www-form-urlencoded Content-Length: 45 islem=kayitOl&kullaniciAdi=admin&parola=admin&email=test
In other words, here we registered as admin:admin. When we logged in, a page reserved for the admin greeted us and asked us for a code.
It is really nice in here; I think you should log in and come along too.
====================================
Admin User
You have 10 attempts to enter the correct answer. When you find it, you will get your reward as well. Act accordingly: 
When we viewed the source code of the page, a piece of php code was visible as a comment.
function generateRandomString($length = 6) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i <= $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
function decryptFile($source, $key, $dest)
{
$key = substr(sha1($key, true), 0, 16);
$error = false;
if ($fpOut = fopen($destc, 'w')) {
if ($fpIn = fopen($source, 'rb')) {
// Get the initialzation vector from the beginning of the file
$iv = fread($fpIn, 16);
while (!feof($fpIn)) {
// we have to read one block more for decrypting than for encrypting
$ciphertext = fread($fpIn, 16 * (FILE_ENCRYPTION_BLOCKS + 1));
$plaintext = openssl_decrypt($ciphertext, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv);
// Use the first 16 bytes of the ciphertext as the next initialization vector
$iv = substr($ciphertext, 0, 16);
fwrite($fpOut, $plaintext);
}
fclose($fpIn);
} else {
$error = true;
}
fclose($fpOut);
} else {
$error = true;
}
//key gen with private algorithms
//same private algorithms used for check
if($keys=generateRandomString(6)) {
$k1 = strpos($key,$keys[0]);
if($k1===false) {
$errors=true;
} else {
if(strpos($key,$keys[1]) === false)
$errors=true;
else {
if(strpos($key,$keys[2]) === false)
$errors=true;
else {
if(intval($keys[5]) < 9 and intval($keys[5]) >= strlen('12345678')) {
if($keys[4] == $key[3]) {
if($keys[6] == rand(0,9)) {
return $keys;
}
}
}
}
}
}
}
return false;
}
function doNotGenerateRandomString($lenght = 4 ){
...
}
function keyChecker($keys) {
...
}
$pass = 'WRITE YOUR OWN ADMIN PASSWORD HERE';
$hash = md5($pass);
//the key is being generated
$key = decryptFile(PATH, $pass, DEST_PATH);
$rand = generateRandomString(6);
//checking whether it is a valid key
if(keyChecker($key))
echo 'congratulations';
We set about examining the code. We tried to work out the algorithm that was expected of us. The conclusions we reached were as follows:
- - take the hash of the user's password with sha1,
- - use the first 16 characters of the hash as the generator key,
- - the 1st, 2nd and 3rd characters of the key must be in the generator key,
- - the 6th character of the key must be 8,
- - the 4th character of the temporary key must be the 5th character of the key,
- - the 7th character of the key must be a random number between 0 and 9 (we can find this one by trial and error as well)
We needed to create a key that met these conditions.
We created the valid key for the admin password in the form dddd38<0-9>.
Once it was verified as correct, it gave us the flag.
FLAG:
U1RpeWtYWWN6ZEw3b1VqRnhPcVhFVlZBbmtMdjJhRmRkTnFYUUV0Nkg5MGRacDUwOXlBKyt6NXVwSG9OOXRhNzgzaSsvVWh5Y2c3UTNYb29kTmhpWXc9PQ==
CTF,Capture The Flag,Forensic,Trivia,Intelligence,WireShark,Flag,MD5,PHP,USOM,BTK,Base64,QR,PowerShell,Çözümler,WriteUp,Write-Up