Created
October 26, 2014 11:48
-
-
Save yohanes/75e7f06921cd2701379b to your computer and use it in GitHub Desktop.
Daemon 2 HITB2014
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import select | |
import socket | |
import struct | |
import sys | |
ports_list=[] | |
for i in range(5000, 64000/4): | |
if ((i & 0xf)==0): | |
ports_list += [i] | |
def make_socket(number): | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
sock.bind(('0.0.0.0', number)) | |
sock.listen(5) | |
return sock | |
read_list= map(lambda x: make_socket(x), ports_list) | |
print(read_list) | |
print "Listening on port %s" % ports_list | |
notAccepted = read_list[:] | |
while True: | |
readable, writable, errored = select.select(read_list, [], []) | |
for s in readable: | |
if s in notAccepted: | |
client_socket, address = s.accept() | |
read_list.append(client_socket) | |
print "Connection from", address, client_socket | |
print "connected to ", client_socket.getsockname() | |
else: | |
data = s.recv(20) | |
print "XXX", data.encode("hex") | |
if data: | |
f = open("sockdata.txt", "a+"); | |
f.write(str(s.getsockname()) + "\n"); | |
f.write(data.encode("hex")); | |
addr,key = s.getsockname() | |
b = struct.unpack("iiiii", data) | |
flag = "" | |
for i in b: | |
a = struct.unpack("BBBB", struct.pack("i", (i ^ key))) | |
for x in a: | |
flag += chr(x) | |
print s.getpeername(), flag[:-4] | |
f.close(); | |
s.close(); | |
read_list.remove(s) | |
else: | |
print "no data" | |
s.close() | |
read_list.remove(s) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment