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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| import socket import thread import os
flag="flag{xxxxxxxxxxxxxxxxx}"
def remote_sub(conn, address): print address, (ip,port)=address conn.settimeout(20) secret=int(os.urandom(16).encode("hex"),16) ground=0 sky=pow(2,128) for i in range(200): conn.send("g\n") newground=int(conn.recv(1024).strip(),16) conn.send("s\n") newsky=int(conn.recv(1024).strip(),16) if newground<ground or newsky>sky or newground>newsky: conn.close() return ground=newground sky=newsky if secret <ground or secret >sky: conn.close() return
conn.send("g1\n") g1 = int(conn.recv(1024).strip(), 16) conn.send("g2\n") g2 = int(conn.recv(1024).strip(), 16)
if abs(g2-g1) > abs(sky-ground)/3+1: conn.close() return
if g1==secret and g2==secret: conn.send(flag+"\n") else: if pow(abs(secret-g1)-abs(secret-g2),2)<pow(abs(g2-g1),2): conn.send("1\n") else: conn.send("2\n") conn.close() return def remote(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(("0.0.0.0", 9999)) sock.listen(0) while True: thread.start_new_thread(remote_sub, sock.accept()) if __name__ == '__main__': remote()
|