picoctf/pwn/rps/solve.py

35 lines
875 B
Python
Executable File

#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p python3 python3Packages.pwntools
import ctypes
from pwn import *
player_moves = ["paper", "scissors", "rock"]
# computer_moves = ["rock", "paper", "scissors"]
libc_path = ctypes.util.find_library("c")
if libc_path is None:
print("Error: could not find libc")
exit(1)
libc = ctypes.CDLL(libc_path)
ADDR, PORT, *_ = "saturn.picoctf.net 50666".split()
p = remote(ADDR, PORT)
x = 0
for i in range(5):
p.recvuntil(b'Type \'2\' to exit the program')
p.sendline(b'1')
libc.srand(libc.time(None))
p.recvuntil(b'Please make your selection (rock/paper/scissors)')
choice = libc.rand() % 3
player_move = player_moves[choice]
p.sendline(player_move.encode())
print(f'Round {i + 1}')
p.recvuntil(b'You win!')
p.recvuntil(b'Congrats, here\'s the flag!\r\n')
print(p.recvline().decode().strip())
p.close()