From 8ab99810878c6a11d20498904882ef526f6b67ae Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Fri, 28 Oct 2016 15:00:59 -0500 Subject: [PATCH] Added a problem (wao) --- dijkstra/grader.py | 4 +- my-usb/grader.py | 4 +- security-through-obscurity/description.md | 2 +- security-through-obscurity/grader.py | 6 +- survey/grader.py | 2 +- wayward-space-junk/description.md | 5 ++ wayward-space-junk/grader.py | 13 +++++ wayward-space-junk/problem.yml | 6 ++ wayward-space-junk/server.py | 71 +++++++++++++++++++++++ 9 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 wayward-space-junk/description.md create mode 100644 wayward-space-junk/grader.py create mode 100644 wayward-space-junk/problem.yml create mode 100644 wayward-space-junk/server.py diff --git a/dijkstra/grader.py b/dijkstra/grader.py index abf65e1..edf74d0 100644 --- a/dijkstra/grader.py +++ b/dijkstra/grader.py @@ -1,4 +1,4 @@ def grade(autogen, answer): if answer.find("edsger_wybe_dijkstra_was_a_happy_accident") != -1: - return { "correct": True, "message": "Great Job! That's a tough one." } - return { "correct": False, "message": "Nope, try again." } \ No newline at end of file + return True, "Great Job! That's a tough one." + return False, "Nope, try again." \ No newline at end of file diff --git a/my-usb/grader.py b/my-usb/grader.py index ac8dbb9..2839a7e 100644 --- a/my-usb/grader.py +++ b/my-usb/grader.py @@ -1,4 +1,4 @@ def grade(autogen, answer): if answer.find("d3let3d_f1l3z_r_k00l") != -1: - return { "correct": True, "message": "Correct!" } - return { "correct": False, "message": "Nope, try again." } \ No newline at end of file + return True, "Correct!" + return False, "Nope, try again." \ No newline at end of file diff --git a/security-through-obscurity/description.md b/security-through-obscurity/description.md index 2fa753a..2b09f78 100644 --- a/security-through-obscurity/description.md +++ b/security-through-obscurity/description.md @@ -1,4 +1,4 @@ I've never seen such a cryptosystem before! It looks like a public key cryptosystem, though... Could you help me crack it? -[encrypt.sage](${encrypt_sage}) +[encrypt.sage](${encrypt_sage}) [publickey_and_ciphertext.txt](${publickey_and_ciphertext_txt}) \ No newline at end of file diff --git a/security-through-obscurity/grader.py b/security-through-obscurity/grader.py index 7e098b4..125031d 100644 --- a/security-through-obscurity/grader.py +++ b/security-through-obscurity/grader.py @@ -1,4 +1,4 @@ def grade(autogen, answer): - if answer.find("i_actu4lly_d0nt_know_th3_name_of_th15_crypt0sy5tem") != -1: - return { "correct": True, "message": "Correct!" } - return { "correct": False, "message": "Nope, try again." } \ No newline at end of file + if answer.find("i_actu4lly_d0nt_know_th3_name_of_th15_crypt0sy5tem") != -1: + return True, "Correct!" + return False, "Nope, try again." \ No newline at end of file diff --git a/survey/grader.py b/survey/grader.py index 8594c54..f2685eb 100644 --- a/survey/grader.py +++ b/survey/grader.py @@ -1,2 +1,2 @@ def grade(autogen, answer): - return False, "This problem hasn't been released yet." \ No newline at end of file + return False, "This problem hasn't been released yet." \ No newline at end of file diff --git a/wayward-space-junk/description.md b/wayward-space-junk/description.md new file mode 100644 index 0000000..bfbcb08 --- /dev/null +++ b/wayward-space-junk/description.md @@ -0,0 +1,5 @@ +I'm trying to destroy some space junk, but it won't stop moving! + +`nc some_ip 8580` + +Pilot Key: `${key}` \ No newline at end of file diff --git a/wayward-space-junk/grader.py b/wayward-space-junk/grader.py new file mode 100644 index 0000000..f16aa16 --- /dev/null +++ b/wayward-space-junk/grader.py @@ -0,0 +1,13 @@ +def generate(random): + key = "".join([random.choice("0123456789abcdef") for i in range(32)]) + return dict(variables={ + "key": key + }) + +def grade(autogen, answer): + key = "".join([autogen.choice("0123456789abcdef") for i in range(32)]) + autogen.seed("super%secretkeylalalala" % key) + flag = "".join([random.choice("012456789abcdef") for i in range(32)]) + if answer.find(flag) != -1: + return True, "Correct!" + return False, "Nope, try again." \ No newline at end of file diff --git a/wayward-space-junk/problem.yml b/wayward-space-junk/problem.yml new file mode 100644 index 0000000..ff0fb70 --- /dev/null +++ b/wayward-space-junk/problem.yml @@ -0,0 +1,6 @@ +title: Wayward Space Junk +hint: Try figuring out the trajectory of the junk. +category: Programming +autogen: true +programming: false +value: 300 \ No newline at end of file diff --git a/wayward-space-junk/server.py b/wayward-space-junk/server.py new file mode 100644 index 0000000..e79a522 --- /dev/null +++ b/wayward-space-junk/server.py @@ -0,0 +1,71 @@ +import SocketServer +import os +import re +import time +from math import sin, cos, pi, sqrt, atan + +equations = [ + lambda constant, offset, amp, theta: amp * sin(constant * theta) + offset, + lambda constant, offset, amp, theta: amp * cos(constant * theta) + offset, + lambda constant, offset, amp, theta: amp * atan(constant * theta) + offset +] + +pattern = re.compile("\((\d+(?:.\d+)?),(?:\s+)?(\d+(?:.\d+)?)\)") + +def dist(x1, y1, x2, y2): + dx = x2 - x1 + dy = y2 - y1 + return sqrt(dx * dx + dy * dy) + +def p2r(r, theta): + return (r * cos(theta), r * sin(theta)) + +class RequestHandler(SocketServer.BaseRequestHandler): + def handle(self): + self.request.sendall("Please enter your pilot key: ") + key = self.request.recv(1024).strip() + + import random + random.seed(key) + + amplitude = random.uniform(5000, 10000) + offset = random.uniform(5000, 10000) + constant = random.uniform(0, 2 * pi) + equation = random.choice(equations) + period = random.uniform(400, 800) + + current_time = time.time() + self.request.sendall("The current time is: %s\n" % current_time) + self.request.sendall("Please enter the coordinates (x, y) you would like to hit:\n") + + theta = current_time + while theta > period: + theta -= period + theta *= 2 * pi / period + + coordinates = self.request.recv(1024).strip() + match = pattern.match(coordinates) + if not match: + self.request.sendall("Sorry, you didn't enter valid coordinates.\n") + return + + x1, y1 = float(match.group(1)), float(match.group(2)) + x2, y2 = p2r(equation(constant, offset, amplitude, theta), theta) + distance = dist(x1, y1, x2, y2) + + if distance < 10: + random.seed("super%secretkeylalalala" % key) + flag = "".join([random.choice("012456789abcdef") for i in range(32)]) + self.request.sendall("Perfect!\n") + self.request.sendall("Your flag is: easyctf{%s}\n" % flag) + else: + self.request.sendall("You missed. You were (%.3f, %.3f) off.\n" % (x2 - x1, y2 - y1)) + # self.request.sendall("[DEBUG] Actual coordinates: (%.3f, %.3f)\n" % (x2, y2)) + + +if __name__ == "__main__": + HOST = os.getenv("HOST", "0.0.0.0") + PORT = int(os.getenv("PORT", "8580")) + server = SocketServer.TCPServer((HOST, PORT), RequestHandler) + print "Listening on %s:%s" % (HOST, PORT) + server.serve_forever() \ No newline at end of file