๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿด‍โ˜ ๏ธ CTF ๐Ÿด‍โ˜ ๏ธ/๐Ÿงฎ ์•”ํ˜ธํ•™ ๐Ÿงฎ

[Dream Hack - Crypto] Robot Only

๋ฐ˜์‘ํ˜•

ํ’€์ด ๋ฐฉ๋ฒ•

  1. ๋กœ๋ด‡์ž„์„ ์ธ์ฆ
  2. ์ถœ๋ ฅ๋˜๋Š” ํ† ํฐ์„ ์žฌ์ž…๋ ฅ
  3. ๋ฐฐํŒ…์„ ํ†ตํ•ด ๋ˆ์„ ๋ฒ”๋ฐฐํŒ…ํ•˜๋Š” ๋ˆ์ด ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋ˆ๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์œผ๋ฉด ๋˜๋Š” ๊ฒƒ์„ ํ™•์ธ. ์Œ์ˆ˜์˜ ๋ˆ์„ ๋ฐฐํŒ…ํ•˜์—ฌ ๋ฐฐํŒ…์—์„œ ์ง€๋Š” ๊ฒฝ์šฐ, money - bet ์‹์„ ํ†ตํ•ด ์˜คํžˆ๋ ค ๋ˆ์„ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธ
  4. bet = int(input('how much money do you want to bet (your money: ${0})? '.format(money))) if money < bet: print('you don\\'t have enough money (your money: ${0}).'.format(money)) return
  5. ๋ˆ์ฃผ๊ณ  flag๋ฅผ ์‚ฐ๋‹ค.

 

์ฝ”๋“œ

from pwn import *
import time

p = remote("host3.dreamhack.games", 23111)
# p = process("./robot_only.py")

data = p.recvline().decode('utf-8')     
data += p.recvline().decode('utf-8')
data += p.recvline().decode('utf-8')
data += p.recvline().decode('utf-8')
data += p.recvline().decode('utf-8')
print(data)
## ๋กœ๋ด‡ ์ธ์ฆ ์„ ํƒ
p.sendafter(b"> ", b"2\\n") 

## ํ† ํฐ์ด ์ถœ๋ ฅ๋จ
data = p.recvline().decode('utf-8')
print(data)

## ํ† ํฐ๋งŒ ๋ถˆํ• ํ•ด์„œ ์ถœ๋ ฅ
token = data.split("please type this same: \\"")[1]
token = token.split("\\"")[0] + "\\n"
print("token : " + token)
p.sendafter(b"> ", bytes(token, 'utf-8'))

## ๋กœ๋ด‡์ž„์„ ํ™•์ธํ–ˆ๋‹ค๋Š” ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ
data = p.recvline().decode('utf-8')
data += p.recvline().decode('utf-8')     
data += p.recvline().decode('utf-8')
data += p.recvline().decode('utf-8')
data += p.recvline().decode('utf-8')
data += p.recvline().decode('utf-8')
print(data)

## ๋ฐฐํŒ… ์‹œ์ž‘
p.sendafter(b"> ", b"1\\n")

data = p.recvline().decode('utf-8')
print(data)
## ๋ฐฐํŒ…ํ•  ๊ธˆ์•ก ์„ ํƒ 
## ์ฝ”๋“œ์—์„œ money < bet ๋กœ ํ™•์ธํ•˜๋Š” ๊ฑธ ํ†ตํ•ด ์Œ์ˆ˜ ์ž…๋ ฅ๊ฐ€๋Šฅํ•œ ๊ฒƒ์„ ํ™•์ธ
p.sendafter(b")?", b"-1000000000000000\\n")

data = p.recvline().decode('utf-8')
print(data)

## 1 ์„ ํƒ. 1์ด ๋‹ต์ธ ๊ฒฝ์šฐ๋Š” ์—๋Ÿฌ ๋ฐœ์ƒ -> ํ•œ๋ฒˆ ๋” ์‹œ๋„
p.sendafter(b"> ", b"1\\n")
data = p.recvline().decode('utf-8')
data += p.recvline().decode('utf-8')
data += p.recvline().decode('utf-8')     
data += p.recvline().decode('utf-8')
data += p.recvline().decode('utf-8')
data += p.recvline().decode('utf-8')
data += p.recvline().decode('utf-8')
print(data)

## flag ์‚ฌ๊ธฐ!!
p.sendafter(b"> ", b"3\\n")

data = p.recvline().decode('utf-8')
data += p.recvline().decode('utf-8')
print(data)

 
p.close()

 

๊ฒฐ๊ณผ

๋ฐ˜์‘ํ˜•