def listen_for_clients(): #init chroot helpers.initialize_chroot(2014,1015) # setup server listensock = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) listensock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) listensock.bind( ( "0.0.0.0", 9876 ) ) listensock.listen( 5 ) #Quietly ignore zombie children signal.signal(signal.SIGCHLD, signal.SIG_IGN) print( "PROG02: socket, bind and listen complete" ) while True: print( "PROG02: Waiting for client" ) ( client, address ) = listensock.accept() print( "PROG02: Got new client {0}".format( address ) ) #Fork the processes try: pid = os.fork() except: print "PROG02: Error occurred during forking. Ignoring" continue if pid == 0: #Child fork - Close the server socket handle, Reseed random and process the client listensock.close() random.seed() ch = ClientHandler( client ) ch.run() print( "PROG02: Handling client" ) else: #Parent fork - Close the client socket and continue print "PROG02: Forked off child process with id %d" % pid client.close() continue
conn.send('Large pieces of debris fall from the ceiling.\n') if collapse == 100: conn.send('Hurry!\n') if collapse == 0: conn.send('The ceiling collapses and crushes you. You are dead.\n') conn.send('You are dead.\n') return def checknode(Z, x, y, node_type): return Z[y,x] == node_type #Run the chroot code #TODO: Define the chroot user and group here helpers.initialize_chroot(2009,1010) print "Starting up maze server" listensock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) listensock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) listensock.bind(("0.0.0.0",7788)) print "Listening on port 7788" #We dont care for zombies signal.signal(signal.SIGCHLD,signal.SIG_IGN) listensock.listen(1) while True: (conn,address) = listensock.accept() print "Connection accepted from",address try:
iv.encode("hex")[0:iv_size] + ":" + ciphertext.encode("hex") + "\n") cmd = f.readline() #Get next command continue else: conn.send("Invalid command. Bye\n") break #clean up sockets f.close() conn.close() #Run the chroot code #TODO: Define the chroot user and group here helpers.initialize_chroot(2005, 1006) print "Crypto3: Starting up challenge" listensock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) listensock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) listensock.bind(("0.0.0.0", 1337)) print "Crypto3: Listening on port 1337" #We dont care for zombies signal.signal(signal.SIGCHLD, signal.SIG_IGN) listensock.listen(1) while True: (conn, address) = listensock.accept() print "Crypto3: Connection accepted from", address try:
# encrypt the data using AES stream mode data = encrypt(aes, data) # send the hex representation to the client conn.send(data) # try to get some more data from the client, if they want to continue, data = conn.recv(2048).strip() # client has gone conn.close() # Run the chroot code # TODO: Define the chroot user and group here helpers.initialize_chroot(2004, 1005) print "Starting up simple crypto challenge" listensock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) listensock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) listensock.bind(("0.0.0.0", 9999)) print "Listening on port 9999" # We dont care for zombies signal.signal(signal.SIGCHLD, signal.SIG_IGN) listensock.listen(1) while True: (conn, address) = listensock.accept() print "Connection accepted from", address try:
conn.sendall("Key reset\n") coded = shuffle_plain(plain) conn.sendall("#>") else: if data not in plain: continue command += data conn.sendall(data) conn.close() #Run the chroot code #TODO: Define the chroot user and group here helpers.initialize_chroot(2003,1004) print "Starting up simple crypto challenge" listensock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) listensock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) listensock.bind(("0.0.0.0",12433)) print "Listening on port 12433" #We dont care for zombies signal.signal(signal.SIGCHLD,signal.SIG_IGN) listensock.listen(1) while True: (conn,address) = listensock.accept() print "Connection accepted from",address try:
#encrypt the data using AES stream mode data = encrypt(aes, data) #send the hex representation to the client conn.send(data) #try to get some more data from the client, if they want to continue, data = conn.recv(2048).strip() #client has gone conn.close() #Run the chroot code #TODO: Define the chroot user and group here helpers.initialize_chroot(2004,1005) print "Starting up simple crypto challenge" listensock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) listensock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) listensock.bind(("0.0.0.0",9999)) print "Listening on port 9999" #We dont care for zombies signal.signal(signal.SIGCHLD,signal.SIG_IGN) listensock.listen(1) while True: (conn,address) = listensock.accept() print "Connection accepted from",address try:
else: ciphertext = encrypt(iv, segs[1]) conn.send(iv.encode("hex")[0:iv_size]+":"+ciphertext.encode("hex")+"\n") cmd = f.readline() #Get next command continue else: conn.send("Invalid command. Bye\n") break #clean up sockets f.close() conn.close() #Run the chroot code #TODO: Define the chroot user and group here helpers.initialize_chroot(2005,1006) print "Crypto3: Starting up challenge" listensock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) listensock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) listensock.bind(("0.0.0.0",1337)) print "Crypto3: Listening on port 1337" #We dont care for zombies signal.signal(signal.SIGCHLD,signal.SIG_IGN) listensock.listen(1) while True: (conn,address) = listensock.accept() print "Crypto3: Connection accepted from",address try:
conn.send('Hurry!\n') if collapse == 0: conn.send( 'The ceiling collapses and crushes you. You are dead.\n') conn.send('You are dead.\n') return def checknode(Z, x, y, node_type): return Z[y, x] == node_type #Run the chroot code #TODO: Define the chroot user and group here helpers.initialize_chroot(2009, 1010) print "Starting up maze server" listensock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) listensock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) listensock.bind(("0.0.0.0", 7788)) print "Listening on port 7788" #We dont care for zombies signal.signal(signal.SIGCHLD, signal.SIG_IGN) listensock.listen(1) while True: (conn, address) = listensock.accept() print "Connection accepted from", address try:
correctCounter+=1 elapsed = (int(time.time()) - start) print elapsed if correctCounter == CORRECTANSWERS and elapsed < ELAPSEDTIME: conn.send(helpers.load_flag()) elif correctCounter == CORRECTANSWERS: conn.send("You unjumbled all the words but took to long") else: conn.send("You got %d / %d words correct" % (correctCounter,CORRECTANSWERS)) conn.close() #Run the chroot code #TODO: Define the chroot user and group here helpers.initialize_chroot(2008,1009) print "Starting up simple crypto challenge" listensock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) listensock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) listensock.bind(("0.0.0.0",5050)) print "Listening on port 5050" #We dont care for zombies signal.signal(signal.SIGCHLD,signal.SIG_IGN) listensock.listen(1) while True: (conn,address) = listensock.accept() print "Connection accepted from",address try: