Mafia

点击此处获得更好的阅读体验


WriteUp来源

https://dunsp4rce.github.io/csictf-2020/miscellaneous/2020/07/21/Mafia.html

by anishbadhri

题目描述

The CTF Mafia wants to remove the competition (i.e.you) to again have monopoly over flags. Bribe the Mafia to get away unscathed and with the flag.

题目考点

解题思路

This problem is an application of binary search. The value of amount is binary searched with a lower bound as 1 and upper bound as 1000000.

In each iteration, the current amount is queried against the current set of friends. All friends with amount greater than the current amount is taken as the set of friends for the next iteration. If no friend has amount greater than current but some friend has equal to current amount, that value is displayed. Otherwise, the same set of friends are taken for a lower amount.

Solution Script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from pwn import *
conn = remote('chall.csivit.com',30721)
friends = [i for i in range(1,301)]
beg = 1
end = 1000000
while len(friends) > 0:
cur_value = (beg + end) // 2
G = []
E = []
for x in friends:
conn.send(f'1 {x} {cur_value}\n')
v = conn.recvline(1).decode()[0]
if v == 'G':
G.append(x)
elif v == 'E':
E.append(x)
print()
if len(G) > 0:
friends = G[:]
beg = cur_value + 1
elif len(E) > 0:
conn.send('2 '+ str(cur_value) +"\n")
while True:
print(conn.recvline())
else:
end = cur_value - 1

Flag

1
csictf{y0u_ar5_t8e_k!ng_0f_rAnd0mne55}