InfoSec Blog
  • 🏠Home
  • 🪪Trainings & Certification
    • APISec University
      • ASCP Review
    • OffSec
      • OSCP Review
  • 🚩CTFs
    • HackTheBox
      • Windows Machines
        • Visual
      • Web Challenges
        • Neonify
    • ROOTCON 18 PRE QUALIFIERS
      • Rock Paper Scissors Sh**t
      • Zippy
      • Super Secure Static Website
Powered by GitBook
On this page
  1. CTFs
  2. ROOTCON 18 PRE QUALIFIERS

Rock Paper Scissors Sh**t

The goal of the challenge is to win 1000 times against the bot in rock, paper, scissors to get the flag.

PreviousROOTCON 18 PRE QUALIFIERSNextZippy

Last updated 9 months ago

Connecting to the given IP address and port, we see it initiates a rock paper scissors game with the goal of the challenge is to win 1000 times. We see it also saves the data to the Total wins so we can keep track of it.

We can create a Python script using pwntools to automate this.

from pwn import *

# Set the IP and port of the remote service
host = 'IP'
port = PORT

# Connect to the remote server
p = remote(host, port)

# This variable keeps track of total wins
total_wins = 0

# We need to win 1000 times
target_wins = 1000

# Play the game until we reach the target
while total_wins < target_wins:
    # Receive the prompt asking for input (with timeout to avoid hanging)
    try:
        data = p.recvuntil(b"Your move: ",timeout=5)  # Timeout in 5 seconds if nothing is received
        print(data.decode())  # Print the data we received
    except EOFError:
        print("Connection closed by the server.")
        break
    except Exception as e:
        print(f"Error receiving data: {e}")
        break

    # The server asks for our move: "Enter your action (rock, paper, or scissors):"
    if b"Your move:" in data:
        # We will always choose "rock" for simplicity
        p.sendline(b"rock")
        print("Sent: rock")

    # Receive the result of the round (win or lose) with a timeout
    try:
        result = p.recvline(timeout=5)
        print(result.decode())  # Print the result
    except EOFError:
        print("Connection closed by the server.")
        break
    except Exception as e:
        print(f"Error receiving result: {e}")
        break

    # Check if we won or lost the round and update total_wins accordingly
    if b"You won!" in result:
        total_wins += 1
        print(f"Total wins: {total_wins}")
    elif b"You lost" in result:
        print("Lost this round. Continuing...")

# After winning 1000 times, the flag should be revealed
p.interactive()  # Interact with the server after reaching the target

Letting the script run after a while, we see that we have already won 1000 times and the flag is also given as a reward.

🚩