Skip to content

Instantly share code, notes, and snippets.

@Jeffallan
Created February 14, 2019 15:36
Show Gist options
  • Save Jeffallan/8600f4be71b591b08ffcf0c66fa845b1 to your computer and use it in GitHub Desktop.
Save Jeffallan/8600f4be71b591b08ffcf0c66fa845b1 to your computer and use it in GitHub Desktop.
Solutions to NULLIFY's 2019 CTF Script Challenges
import socket
import time
import sys
HOST = '18.216.82.207'
PORT = 2003
s = socket.create_connection((HOST,PORT))
def main():
intro = s.recv(1024)
print('Intro\t', repr(intro))
time.sleep(3)
call = s.recv(1024)
print('Call\t\t', repr(call))
'''
print('Replaced\t\t', repr(call.replace(b'\n', b'')))
response = call.lstrip() # replace(b'\n', b'') + b'\n'
s.sendall(response)
print('Response bytes:\t', repr(response))
time.sleep(2)
call = s.recv(1024)
print('Call\t\t', repr(call))
'''
def loop():
HOST = '18.216.82.207'
PORT = 2001
s = socket.create_connection((HOST,PORT))
intro = s.recv(1024)
print('Intro\t', repr(intro))
call = s.recv(1024)
while call:
print('Call\t\t', repr(call))
response = call.lstrip()
s.sendall(response)
print("Sent\t", repr(response))
time.sleep(1)
call = s.recv(1024)
def rps():
import re
HOST = '18.216.82.207'
PORT = 2002
s = socket.create_connection((HOST,PORT))
intro = s.recv(1024)
print('Intro\t', repr(intro))
time.sleep(3)
call = s.recv(1024)
while call:
print('Call\t', repr(call))
if re.search("\nROCK\n" , call.decode()):
s.send(b'p\n')
print('Sent: \t Paper')
elif re.search("\nPAPER\n", call.decode()):
s.send(b's\n')
print('Sent: \t Scissors')
else:
#re.search("\nSCISSORS\n", call.decode()):
s.send(b'r\n')
print('Sent: \t Rock')
time.sleep(1.5)
call = s.recv(1024)
def guessing():
HOST = '18.216.82.207'
PORT = 2003
s = socket.create_connection((HOST,PORT))
number = [4,2,9,4,9,6,7,2,9,5]
guess = [0,0,0,0,0,0,0,0,0,0]
res = s.recv(1024)
print('Intro\t', repr(res))
# to string => string = ''.join(str(n) for n in number)
# to bytes => bytes = bytes(string.encode())
i = 0
while res:
message = (''.join(str(g) for g in guess) + '\n')
s.send(bytes(message.encode()))
print("Sent:\t" + message)
time.sleep(1)
res = s.recv(1024)
print('Result:\t', repr(res))
if 'HIGH\n' not in str(res.decode()):
guess[i] +=1
time.sleep(0.5)
else:
guess[i] -= 1
i += 1
time.sleep(0.5)
def sorting():
import re
HOST = '18.216.82.207'
PORT = 2004
s = socket.create_connection((HOST,PORT))
intro = s.recv(1024)
print("Intro:\t", repr(intro))
res = s.recv(1024)
print("Example:\t", repr(res))
sort_me = res.decode().split('\n')[3].replace(' ', '').split(',')
sort = list()
for e in sort_me:
sort.append(int(e))
to_string = ', '.join(str(s) for s in sorted(sort))
print('Sorted:\n' + to_string + '\n')
s.send(bytes(to_string.encode() + b'\n'))
res = s.recv(1024)
print('Sort me:\t', repr(res))
while res:
sort_me = res.decode().replace(' ', '').split(',') # .split('\n').replace(' ', '').split(',')
print(sort_me)
sort = list()
for e in sort_me:
sort.append(int(e))
to_string = ', '.join(str(s) for s in sorted(sort))
print('Sorted:\n' + to_string + '\n')
s.send(bytes(to_string.encode() + b'\n'))
time.sleep(1)
res = s.recv(1024)
print('Sort me:\t', repr(res))
if __name__ == '__main__':
guessing()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment