This commit is contained in:
2023-09-13 13:37:54 +08:00
parent 426cfbaeaa
commit 1a11df1d52
2 changed files with 120 additions and 19 deletions

View File

@@ -1 +1,65 @@
# https://zh.wikipedia.org/zh-hans/%E8%A7%A3%E8%BF%B7%E5%AE%AE%E6%BC%94%E7%AE%97%E6%B3%95
# https://zh.wikipedia.org/zh-hans/%E8%A7%A3%E8%BF%B7%E5%AE%AE%E6%BC%94%E7%AE%97%E6%B3%95
from pwn import *
import random
import time
context.log_level = 'debug'
map = [[0 for _ in range(19)] for _ in range(19)]
start = [9,9]
position = start
for i in range(19):
map[0][i] = 9
map[18][i] = 9
map[i][0] = 9
map[i][18] = 9
r = remote('localhost',10001)
r.recvline()
r.recvline()
# 11*11的迷宫
def gen_moves(map:list, position:list)->str:
moves = ''
if map[position[0]-1][position[1]] == 0:
moves += "w"
if map[position[0]+1][position[1]] == 0:
moves += "s"
if map[position[0]][position[1]-1] == 0:
moves += "a"
if map[position[0]][position[1]+1] == 0:
moves += "d"
return moves
while(1):
moves = gen_moves(map, position)
move = random.choice(moves).encode()
r.sendline(move)
status = r.recvline().decode()
# 撞墙
if 'wall' in status:
if move == b'w':
map[position[0]-1][position[1]] = 9
if move == b's':
map[position[0]+1][position[1]] = 9
if move == b'a':
map[position[0]][position[1]-1] = 9
if move == b'd':
map[position[0]][position[1]+1] = 9
else:
if move == b'w':
position[0] -= 1
if move == b's':
position[0] += 1
if move == b'a':
position[1] -= 1
if move == b'd':
position[1] += 1

View File

@@ -31,7 +31,7 @@ class Task(socketserver.BaseRequestHandler):
# 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, 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],
@@ -39,10 +39,11 @@ class Task(socketserver.BaseRequestHandler):
[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, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
start = [1, 0]
end = [9, 10]
start = [1, 1]
end = [9, 9]
# ddddssssssddddss
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],
@@ -54,46 +55,81 @@ class Task(socketserver.BaseRequestHandler):
[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]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
start = [9, 3]
end = [9, 5]
# waawwwwwwwddssddsssdssas
else:
maze = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1],
maze = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 1, 0, 1, 0, 1],
[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]
start = [1, 9]
end = [7, 9]
# aassaaaaaassddddsssddsddww
return maze, start, end
def check_position(self,maze:list,position:list)->bool:
if maze[position[0]][position[1]] == 1:
return False
else:
return True
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 not move:
print("Connection closed by the client.")
return False
if len(move) != 1:
self.send(b'Invalid lenth')
return False
continue
if move not in 'wasd':
self.send(b'Invalid instruction')
return False
continue
if move == "w":
pass
position[0] -= 1
if self.check_position(maze,position):
self.send(b"You moved one step up")
else:
self.send(b"You bumped into the wall")
position[0] += 1
elif move == "s":
pass
position[0] += 1
if self.check_position(maze,position):
self.send(b"You moved one step down")
else:
self.send(b"You bumped into the wall")
position[0] -= 1
elif move == "a":
pass
position[1] -= 1
if self.check_position(maze,position):
self.send(b"You moved one step left")
else:
self.send(b"You bumped into the wall")
position[1] += 1
else:
pass
position[1] += 1
if self.check_position(maze,position):
self.send(b"You moved one step right")
else:
self.send(b"You bumped into the wall")
position[1] -= 1
return True
def handle(self):
@@ -115,7 +151,8 @@ class ForkedServer(socketserver.ForkingMixIn, socketserver.TCPServer):
if __name__ == "__main__":
flag = bytes(os.getenv("FLAG"),"utf-8")
# flag = bytes(os.getenv("FLAG"),"utf-8")
flag = b'11111111111111'
HOST, PORT = '0.0.0.0', 10001
server = ForkedServer((HOST, PORT), Task)
server.allow_reuse_address = True