添加题目
This commit is contained in:
parent
ffbfe199d8
commit
426cfbaeaa
1
misc/easy_maze/crack.py
Normal file
1
misc/easy_maze/crack.py
Normal file
@ -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
|
123
misc/easy_maze/easy_maze.py
Normal file
123
misc/easy_maze/easy_maze.py
Normal file
@ -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()
|
Loading…
x
Reference in New Issue
Block a user