): return False return True class Handler(SocketServer.BaseRequestHandler): def handle(self): try: stream = self.request.makefile("r+", bufsize=0) stream.write("Enter your name: ") name = stream.readline().strip() if is_lucky(name): stream.write("Seems like you are lucky enough!\nFlag is {0}\n".format(flag)) else: stream.write("Sorry, we don't need losers in our team\n") except Exception as e: logger.exception() finally: stream.close() if __name__ == "__main__": logsetup("lucky.log", "DEBUG") with open("flag.txt") as f: flag = f.read().strip() SocketServer.ThreadingTCPServer.allow_reuse_address = True server = SocketServer.ThreadingTCPServer((HOST, PORT), Handler) server.allow_reuse_address = True server.daemon_threads = True server.serve_forever()
self.send("no such user!") raise Exception() server_iv = os.urandom(16) client_iv = os.urandom(16) self.send(server_iv) self.send(client_iv) self.init_ciphers(self.user, client_iv, server_iv) self.send(self.banner + self.prompt) self.running = True while self.running: command_str = self.recv().strip() output = "\n\n".join( map(self.process_command, filter(None, map( str.strip, command_str.split(";"))))) + self.prompt self.send(output) except Exception as e: logger.exception("Exception from %s", self.peername) raise finally: self.stream.close() if __name__ == "__main__": logsetup("chained.log", "DEBUG") SocketServer.ThreadingTCPServer.allow_reuse_address = True server = SocketServer.ThreadingTCPServer((HOST, PORT), Handler) server.allow_reuse_address = True server.daemon_threads = True server.serve_forever()
self.user = self.recv() print "User: "******"no such user!") raise Exception() server_iv = os.urandom(16) client_iv = os.urandom(16) self.send(server_iv) self.send(client_iv) self.init_ciphers(self.user, client_iv, server_iv) self.send(self.banner + self.prompt) self.running = True while self.running: command_str = self.recv().strip() output = "\n\n".join(map(self.process_command, filter(None, map(str.strip, command_str.split(";")))))+self.prompt self.send(output) except Exception as e: logger.exception("Exception from %s", self.peername) raise finally: self.stream.close() if __name__ == "__main__": logsetup("chained.log", "DEBUG") SocketServer.ThreadingTCPServer.allow_reuse_address = True server = SocketServer.ThreadingTCPServer((HOST, PORT), Handler) server.allow_reuse_address = True server.daemon_threads = True server.serve_forever()
if sum(digest_num[::2]) != sum(digest_num[1::2]) or sum(digest_num[:len(digest_num)/2]) != sum(digest_num[len(digest_num)/2:]): return False return True class Handler(SocketServer.BaseRequestHandler): def handle(self): try: stream = self.request.makefile('r+', bufsize=0) stream.write("Enter your name: ") name = stream.readline().strip() if is_lucky(name): stream.write("Seems like you are lucky enough!\nFlag is {0}\n".format(flag)) else: stream.write("Sorry, we don't need losers in our team\n") except Exception as e: logger.exception() finally: stream.close() if __name__ == "__main__": logsetup("lucky.log", "DEBUG") with open("flag.txt") as f: flag = f.read().strip() SocketServer.ThreadingTCPServer.allow_reuse_address = True server = SocketServer.ThreadingTCPServer((HOST, PORT), Handler) server.allow_reuse_address = True server.daemon_threads = True server.serve_forever()