JohnHammond / katana

Katana - Automatic CTF Challenge Solver in Python3
Other
1.27k stars 182 forks source link

Fix the quipqiup module #29

Open 313ctric opened 3 years ago

313ctric commented 3 years ago

Fix issue #27 by using the actual quipqiup site as the existing api always returns a 500 (Internal Server Error) response code.

It works, but I don't like having to set the verify=False with requests as this stops certificate validation which makes it less secure. I also dislike using sleep(), but I can't think of a better way to wait for the server.

calebstewart commented 3 years ago

The only comment I would have is we could utilize the interval returned by the API call in the same way the web interface does instead of waiting the maximum amount of time. It would mean more web requests, but a possibly shorter wait time. @JohnHammond do you have an opinion either way here?

313ctric commented 3 years ago

This code waits for it to solve by requesting every poll_interval until it returns last (finished flag) as 1 or we take too long. It is about 0.5-1 second(s) faster, and in testing sent 3 rather than 2 requests so is probably worth the change.

from time import time as curr_time

...

data = {"ciphertext":cipher,"clues":clues,"mode":"auto","was_auto":True,"was_clue":False}
solve_response = json.loads( requests.post(url, data=json.dumps(data), headers=headers, verify=False).text )

url = "https://quipqiup.com/status"
data = {"id":solve_response["id"]}
status_response = json.loads( requests.post(url, data=json.dumps(data), headers=headers, verify=False).text )

start_time = curr_time()

while (curr_time() - start_time) <= min(solve_response["max_time"], time) and status_response["last"] != 1:
    sleep( min(solve_response["poll_interval"], time) )
    status_response = json.loads( requests.post(url, data=json.dumps(data), headers=headers, verify=False).text )

return json.dumps(status_response)
eljeffeg commented 3 years ago

@calebstewart is this PR good to merge? The current version is broken, so would be good to have some fix applied.