Car Brand is a nice person. He wants to declare his love to his girl. Unfortunately, another trash girl also likes him. In order to announce to the trash girl about his feelings, he decides to put his confession into irrefutable words, and send it to everyone. The trash girl intercepts the message, but is unable to open it. Can you help the trash girl realise the feeling of Car Brand?
Brownie points to those who know what anime I am making this reference from and who both the girls are.
-
Requirements : http request, devious mind, patience, brute force partially required.
-
Flag Format : /{ flag : .+ }/
Solution
The source code for the problem is as shown.
#!/usr/bin/env python3
from http.server import BaseHTTPRequestHandler, HTTPServer
from numpy.random import RandomState
PORT = 7777
FLAG = """IlxxxUHHxxxxxxRPmxx0pv5TClTkDHLwLjzbUwNk1Jh5hUKefZ1QhYWRzxxxxxxzVRlyhc2xxh7v63fTK4q4c131sBGJktlAwNrfMbVAvefWYkXlxxxxxxxxOpgoSvjuKFWVIfR8xxssxxBhxxZVVUGGwCGsK4xxxEm4U
pxxbc5SxxRUjoxx8LxxMvHCjcZtkPz9ZQoaDDBwY8bhPlOSqvlAPsJYslBnxxnK2kIIQu6SxxbzWCMuZQkYYNBOmUpMiFLaknwPKUuOUb0E8FCJ4xxguAX6QvbTHCqi90Ljsk8CZrD5NxxvENd4esV7z2R9qHRN2xx7Fg
lxxMJHNxxXBbGoN80xxkI5xxxxxxBCTqxxxxxxTt5Co0ZJUxxu4JFaCutDgxxPprXAI8l4ixxOllxxxxxx0oTxxOi4QUxx7vmxxxxxxuYdVahXNOxx76eFg5bYxxxxxxpxxxxNsSxxB8xx3axx2swxxxxxxRqay7xxgdS
xxxhhgwxxxxDPX8iUxxwv3C5qFYxxiKxxDzsXxxHWFupcGrdStzR7iUl9a9xxB1ZcTHrMNixxKkxxqqMyxxMErxxoTZxxbvWxxzh5VxxuDfaYDjjxxxxxGsXGuxxkimxxfCrxxcmxxMBxxD9xx8k8cHE9FxxF66yxxxmY
Axx4Y8fxxnv2q5H9qxxmoaxxxxxxxLGxxlL4Zxx6U8gXteNJHtSPHaWzT4axxt0WU9lut0exxk6xx7ZNbxxmS77xxzxxM4QRxxxxxx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[[ord(x) for x in x] for x in FLAG.split()]
PASSWORD = 84
class myHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/plain; charset=printable-ascii')
self.end_headers()
if self.headers['password'] is None or self.headers['password'] == '':
self.wfile.write(b'Header password missing')
return
try:
password = int(self.headers['password'])
except ValueError:
self.wfile.write(b'uint8 expected')
return
if password > 256 or password < 0:
self.wfile.write(b'uint8 expected')
return
diff = abs(PASSWORD - password) * 10
if diff == 0:
self.wfile.write(b'\n')
self.wfile.write(b'\n'.join(map(bytes, ENCODED_FLAG)))
self.wfile.write(b'\n')
return
random_state = RandomState(seed=1143)
generated_mask = random_state.randint(diff, size=(11, 165))
generated_flag = generated_mask + ENCODED_FLAG
self.wfile.write(b'\n')
self.wfile.write(b'\n'.join(map(bytes, generated_flag)))
self.wfile.write(b'\n')
return
httpd = HTTPServer(('', PORT), myHandler)
httpd.serve_forever()
To solve this question, you are required to send a query at the port and host that the server is setup on. So let us try that out. For this example, server is setup on localhost:7777.
$ curl localhost:7777 -v
* Rebuilt URL to: localhost:7777/
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 7777 (#0)
> GET / HTTP/1.1
> Host: localhost:7777
> User-Agent: curl/7.47.0
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: BaseHTTP/0.6 Python/3.5.2
< Date: Thu, 23 Feb 2017 15:17:14 GMT
< Content-type: text/plain; charset=printable-ascii
<
* Closing connection 0
Header password missing%
So there is something fishy in the headers. It speaks of a charset=printable-ascii
. It also says that a header password
is missing.
$ curl localhost:7777 -v -H password:password
* Rebuilt URL to: localhost:7777/
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 7777 (#0)
> GET / HTTP/1.1
> host: localhost:7777
> User-Agent: curl/7.47.0
> Accept: */*
> password:password
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: BaseHTTP/0.6 Python/3.5.2
< Date: Thu, 23 Feb 2017 15:18:24 GMT
< Content-type: text/plain; charset=printable-ascii
<
* Closing connection 0
uint8 expected%
So we make a guess with the password password
, which is as good as any to start, and we see that it points out that a unit8 is expected.
$ curl localhost:7777 -v -H password:10
* Rebuilt URL to: localhost:7777/
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 7777 (#0)
> GET / HTTP/1.1
> Host: localhost:7777
> User-Agent: curl/7.47.0
> Accept: */*
> password:10
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: BaseHTTP/0.6 Python/3.5.2
< Date: Thu, 23 Feb 2017 15:25:54 GMT
< Content-type: text/plain; charset=printable-ascii
<
<BINARY CONTENT REDACTED>
...
...
...
<BINARY CONTENT REDACTED>
* Closing connection 0
So we get a garbage, binary output, for a password of 10. On doing a little bruteforce, we get the following.
$ curl localhost:7777 -v -H password:84
* Rebuilt URL to: localhost:7777/
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 7777 (#0)
> GET / HTTP/1.1
> Host: localhost:7777
> User-Agent: curl/7.47.0
> Accept: */*
> password:84
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: BaseHTTP/0.6 Python/3.5.2
< Date: Thu, 23 Feb 2017 15:28:23 GMT
< Content-type: text/plain; charset=printable-ascii
<
IlxxxUHHxxxxxxRPmxx0pv5TClTkDHLwLjzbUwNk1Jh5hUKefZ1QhYWRzxxxxxxzVRlyhc2xxh7v63fTK4q4c131sBGJktlAwNrfMbVAvefWYkXlxxxxxxxxOpgoSvjuKFWVIfR8xxssxxBhxxZVVUGGwCGsK4xxxEm4U
pxxbc5SxxRUjoxx8LxxMvHCjcZtkPz9ZQoaDDBwY8bhPlOSqvlAPsJYslBnxxnK2kIIQu6SxxbzWCMuZQkYYNBOmUpMiFLaknwPKUuOUb0E8FCJ4xxguAX6QvbTHCqi90Ljsk8CZrD5NxxvENd4esV7z2R9qHRN2xx7Fg
lxxMJHNxxXBbGoN80xxkI5xxxxxxBCTqxxxxxxTt5Co0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rVvqbXa4pz9yRSnIhsD9kZTOVUEEwionIP7IYB6m8tLyLNGMDe
AmvJYyiNalA9YSM5h58O2WEJYOKhU3EsxxxxxxJOP979kT7yWZ6YdlDOiPUl6mE0Suprt1vSlUH7SSiuJfBq7oClpM0e6rqB8ptUWMbcQSqqQgI8HOIiSX4JwM27PTSF9Zw5RyAJmOVYapd8hXtwokuEy4cgbfeCfuqzI
9lIJEm8DMsnL2TJMRrUo57pipc6yI7cTQLLRnMXyibP6jtTOw1P19UgylNoR54RyK12itLkj8ZyTJtsHZV8hUcX47Inp1TcZJyrmMTnFBAAcLIiUCKuBWMNOErnc0GIf5c5JG4mTlccfklIza1rXGDs7rcmZ8XkVQKR5q
* Closing connection 0
Which is the only printable-ascii output that we get from the password. But it is still not done. But I see that there are a lot of 'x' characters in this file. Let's highlight that.
Flag
I love Emilia
Recommended Reading
RSA. But it failed
#crypto #ctf #rsac = 7404228387482887479261869746749991746176804495927055118318206683570516448983801743960459361546161134428690426222368709863453442050071171756423599377401597984440754435058668926603178633761668515076496069751847161724033187368679875259918093224187811267691876198273870870578467510184510086298582204521702946045220312770122458237518246424165432296119053607094777200284200814236416350304918483690156578148133652864328594441673632360773823893061942585188618198600179924877899949396771723157015085683434661302154230334257765610040158570863416499816053904560634890245995407176180498179848769133967582005361790108725945277949845769358752674332269800138008126120486961174643630274131401283073800170609863393091462716402062974615038997250596862336175333249971111165958082179351116528188875511999901288868170989351009565637749016012554778609401305705599425503266370571838403199592830285591168821852287944019050110517938219347052153238370382065390639346971764343981632465382255796047103032366703706122266986406432114737513202337430860123189821063638894815952679576109060674029276361130756827095433943772560556432939992933276440340090287373085788774415087792787958810051460428461265815708830858361853853472340042568141996425244740239642623958541083311687869085046368156034023773742764525490982352637357523475031768768619981883253061696021829604666466769997506990572364386730754183019245389791086458671560767393577689687174730155049027616849606316072012661663516661756810877578172095321431600121667891545760511844723167476314345937930753837239733394626157660380103339672690094231220365695508657679602754981411231543816566131037225152153015287164171129157814773590352342570677841639550177097704155982858059402540582839885549452130954935219771327861980762934458786390322073771612324195542640000816993296528925039288704714097937261854536340516727095307316259517387188619927408613685678242056200319636422554100280245820480283675364454021450870487344889261
...Recommended Reading
Double Hash
#crypto #ctf #hash-chaining #introductoryone fish twofish red fish blowfish
0xcaae8ee4f458ff776860e57141313e1e145423932e79e799d5133af8610e40d 94299046d28022d0b0efaa7fd3177b87e8e8530667111180e47da98f84846d753 cf9afa7c2635c93cf93ef8035b2217c05e192e3d2547e084c86085c2b83ef2b5
Solution
The...
...