csictf 2020

CTF Writeup - https://ctftime.org/event/1081

Home csictf 2020 Writeups Home
21 July 2020

Mafia

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.

nc chall.csivit.com 30721

Files:

Solution

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:

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

csictf{y0u_ar5_t8e_k!ng_0f_rAnd0mne55}
tags: Miscellaneous