From 426cfbaeaa45cbf85b200dc17cf1e4ad24c08e29 Mon Sep 17 00:00:00 2001 From: sangge <2251250136@qq.com> Date: Mon, 11 Sep 2023 17:37:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A2=98=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- misc/easy_maze/crack.py | 1 + misc/easy_maze/easy_maze.py | 123 ++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 misc/easy_maze/crack.py create mode 100644 misc/easy_maze/easy_maze.py diff --git a/misc/easy_maze/crack.py b/misc/easy_maze/crack.py new file mode 100644 index 0000000..9ee0d6b --- /dev/null +++ b/misc/easy_maze/crack.py @@ -0,0 +1 @@ +# https://zh.wikipedia.org/zh-hans/%E8%A7%A3%E8%BF%B7%E5%AE%AE%E6%BC%94%E7%AE%97%E6%B3%95 \ No newline at end of file diff --git a/misc/easy_maze/easy_maze.py b/misc/easy_maze/easy_maze.py new file mode 100644 index 0000000..1df0a39 --- /dev/null +++ b/misc/easy_maze/easy_maze.py @@ -0,0 +1,123 @@ +import socketserver +import signal +import random +import os + + +class Task(socketserver.BaseRequestHandler): + def _recvall(self): + BUFF_SIZE = 2048 + data = b'' + while True: + part = self.request.recv(BUFF_SIZE) + data += part + if len(part) < BUFF_SIZE: + break + return data.strip() + + def send(self, msg, newline=True): + try: + if newline: + msg += b'\n' + self.request.sendall(msg) + except: + pass + + def recv(self, prompt=b'[-] '): + self.send(prompt, newline=False) + return self._recvall() + + def select_maze(self, seed:int): + # 11 * 11 的maze + if seed % 3 == 0: + maze = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], + [1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1], + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], + [1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1], + [1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1], + [1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1], + [1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1], + [1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1], + [1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] + start = [1, 0] + end = [9, 10] + elif seed % 3 == 1: + maze = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1], + [1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1], + [1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1], + [1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1], + [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], + [1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1], + [1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1], + [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1], + [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], + [1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1]] + start = [10, 3] + end = [10, 5] + else: + maze = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1], + [1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1], + [1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1], + [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1], + [1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1], + [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1], + [1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1], + [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0], + [1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1], + [1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] + start = [0, 10] + end = [7, 10] + return maze, start, end + + def game(self): + self.send(b"Try to solve this maze") + self.send(b"Use wasd to move") + maze, start, end = self.select_maze(random.randint(0,99)) + position = start + while position != end: + move = self.recv(b'Try to move: ').decode() + if len(move) != 1: + self.send(b'Invalid lenth') + return False + if move not in 'wasd': + self.send(b'Invalid instruction') + return False + if move == "w": + pass + elif move == "s": + pass + elif move == "a": + pass + else: + pass + + + def handle(self): + signal.alarm(60) # type: ignore + if not self.game(): + self.send(b'[!] Wrong!') + return + + self.send(b'here is your flag') + self.send(flag) + + +class ThreadedServer(socketserver.ThreadingMixIn, socketserver.TCPServer): + pass + + +class ForkedServer(socketserver.ForkingMixIn, socketserver.TCPServer): + pass + + +if __name__ == "__main__": + flag = bytes(os.getenv("FLAG"),"utf-8") + HOST, PORT = '0.0.0.0', 10001 + server = ForkedServer((HOST, PORT), Task) + server.allow_reuse_address = True + print(HOST, PORT) + server.serve_forever() \ No newline at end of file