So, the server is displaying a wanted amount of money and we need to calculate the number of bills and coins given the amount. All we need is writing a simple python script and a coffee break because it will take about 10 minutes for the flag to come up
from pwn import *
r = remote('misc.chal.csaw.io',8000)
# Create an array of dollars and coins values
money = [10000.0, 5000.0, 1000.0, 500.0, 100.0, 50.0, 20.0, 10.0, 5.0, 1.0, 0.5, 0.25, 0.1, 0.05, 0.01]
count = 0
while(True):
count += 1
amount = 0.0
# Recieve the wanted amount of money
amount = float(r.recvline()[1:])
print "Wanted amount is " + str(amount)
# Send the number of dollars and coins for each value
for m in money:
print r.recv()
ans = int(amount/m)
print "Sending %d" %ans
r.sendline(str(ans))
amount = round((amount - (ans*m)), 2)
print "Left with " + str(amount)
print "[+] Finished %d" %count
print r.recvline()
The flag is: flag{started-from-the-bottom-now-my-whole-team-fucking-here}
Is kill can fix? Sign the autopsy file? kill.pcapng
This challenge was the first in the Forensics category and was very very simple. We are given with what seems like a corrupted pcapng file, I wasn’t able to open it in Wireshark nor Tcpdump. I ran strings on it with a hope to find the flag:
[Megabeets] /tmp/CSAW/kill# strings kill.pcapng | grep -i flag
=flag{roses_r_blue_violets_r_r3d_mayb3_harambae_is_not_kill}
And to my great surprise I got it, the flag was written plain-text in the file.
I clicked the tokyo link, which was actually a GET request with a parameter named page in index.php. In response I got a page with PHP error and information from Wikipedia about Tokyo, printed in Hebrew – my mother tongue.
Warning: include(tokyo/en-US.php): failed to open stream: No such file or directory in /var/www/globalpage/index.php on line 41 Warning: include(): Failed opening ‘tokyo/en-US.php’ for inclusion (include_path=’.:/usr/share/php:/usr/share/pear’) in /var/www/globalpage/index.php on line 41
…
First thing to come in mind is a LFI attack, but before making any reckless time-wasting moves, let’s first figure it all out. The page uses include() to, well, include the page “en-US.php” from folder named tokyo. The page wasn’t existed so an error was thrown. I tried pages like “en.php”, “he.php” and “jp.php” and they did exist. The page “ctf” displayed similar behaviors. Seems like all the pages display their information based on the user’s or the browser’s language.
The second thing I tested was the page’s reactions to different values. I tried the value “?page=flag” and it returned the expected error:
Warning: include(flag/en-US.php): failed to open stream: No such file or directory in /var/www/globalpage/index.php on line 41 Warning: include(): Failed opening ‘flag/en-US.php’ for inclusion (include_path=’.:/usr/share/php:/usr/share/pear’) in /var/www/globalpage/index.php on line 41 Warning: include(flag/en.php): failed to open stream: No such file or directory in /var/www/globalpage/index.php on line 41 Warning: include(): Failed opening ‘flag/en.php’ for inclusion (include_path=’.:/usr/share/php:/usr/share/pear’) in /var/www/globalpage/index.php on line 41
I then understood the page was trying to include the language file and every value that I’ll set to “page” will be a folder. I tested the page with the value “../../../etc/passwd” with and without a null-byte terminator but failed due to the sanitize of dots and slashes the page performs.
But how does the page know my language? It took me a while to figure it out. The page took my language settings from the “Accept-Language” field in the request’s header. I tried to change Accept-Language to something else using a Firefox plugin called Tamper Data and it worked! Any value I’ll put there will change the requested page. For example if I request “?page=Mega” and set Accept-Language to “beets” it would return the errors:
Warning: include(Mega/beets.php): failed to open stream: No such file or directory in /var/www/globalpage/index.php on line 41 Warning: include(): Failed opening ‘Mega/beets.php’ for inclusion (include_path=’.:/usr/share/php:/usr/share/pear’) in /var/www/globalpage/index.php on line 41
I combined it all together to perform a well known LFI attack using php://filter. I set the parameter value to “php:” and the Accept-Language field to “/filter/convert.base64-encode/resource=index”. This function encodes the page with Base64 before including it. And indeed I got “index.php” encoded with base64. The decoded page looks like this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As you can see on the top of the code there is an included page named “flag.php”. I changed the Accept-Language accordingly to “/filter/convert.base64-encode/resource=flag” and received the encoded page. Decode it to reveal the flag:
encrypt.py – A Python script uses RSA algorithm to encrypt the flag
encryped – The encrypted message
key 1 – n, and e of one of the keys used in the encryption process
key 2 – n, and e of the other key used in the encryption process
Are you ready for your math lesson? Here we go.
After reading encrypt.py we know that:
n1 = p*q
n2 = (p+2)(q+2)
p and q are twin primes. i.e p is prime and p+2 is also prime; similar for q.
Now let’s turn the equation into an equation with one unknown and then solve it for the unknown.We can Isolate q to be and substitute q in the other equation. Now we have an equation in one unknown:
Solve the equation and you’ll get:
We need to solve this quadratic equation in order to find p and q. After that it will not be a problem to find the d’s and build the keys.
The rest is in the script:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Your task is to make a palindrome string by rearranging and concatenating given words.
Input Format: N <Word_1> <Word_2> ... <Word_N>
Answer Format: Rearranged words separated by space.
Each words contain only lower case alphabet characters.
Example Input: 3 ab cba c
Example Answer: ab c cba
You have to connect to ppc1.chal.ctf.westerns.tokyo:31111(TCP) to answer the problem.
$ nc ppc1.chal.ctf.westerns.tokyo 31111
Time limit is 3 minutes.
The maximum number of words is 10.
There are 30 cases. You can get flag 1 on case 1. You can get flag 2 on case 30.