from pwn import *
import time

r = remote('goose.satellitesabove.me', 5033)
r.clean()
r.send('ticket{kilo720quebec:GP6PhNAXPXwLrMQ7cGlVqENRtYi3wK3dy6QggSJ_utEZ6ghqObtNpc1m5PSpJKEVvw}\n')
time.sleep(0.1)
r.readuntil('running at ')
[ip, port] = r.clean().decode().strip().split(':')
port = int(port)

TEMPL='''
TITLE 'COSMOS Command and Telemetry Server'
#COLLECT_METADATA
#                                                                         wtout rtout  prot   off
INTERFACE LOCAL_CFS_INT tcpip_client_interface.rb {ip} {port} {port} 10    nil    LENGTH 32 16 7 1 BIG_ENDIAN
  TARGET CHALLENGE1
  TARGET SYSTEM
'''

with open('cosmos/config/tools/cmd_tlm_server/cmd_tlm_server.txt', 'w') as f:
    f.write(TEMPL.format(ip=ip, port=port))
