def _handle_negotiate(self, client_id, ntlm_payload): self.log.debug("* client auth stage0") self.log.debug("connecting to host") server = None connected = False attempt = 0 while not connected and attempt < SAMBA_CONNECT_MAX_TRIES: try: attempt = attempt + 1 # TODO: we should query port 135 for the right service server = socket(AF_INET, SOCK_STREAM) server.connect((self.samba_host, SAMBA_PORT)) connected = True except: self.log.error( "NTLMAuthHandler: caught exception when" " connecting to samba host: attempt %d", attempt) sleep(1) if not connected: raise Exception("NTLMAuthHandler: unable to connect to samba host" " aborting after %d attempts" % attempt) self.log.debug("server.sockname: %s", str(server.getsockname())) self.log.debug("building bind packet") packet = RPCBindOutPacket() packet.ntlm_payload = ntlm_payload self.log.debug("sending bind packet") server.sendall(packet.make()) self.log.debug("sent bind packet, receiving response") packet = RPCPacket.from_file(server) self.log.debug("response parsed: %s", packet.pretty_dump()) if isinstance(packet, RPCBindACKPacket): self.log.debug("ACK received") self.client_data[client_id] = { "status": "challenged", "last_used": time(), "server": server } response = 1 ntlm_payload = packet.ntlm_payload else: response = 0 ntlm_payload = "" self.log.debug("* done with client auth stage0") return (response, ntlm_payload)
def _handle_negotiate(self, client_id, ntlm_payload): self.log.debug("* client auth stage0") self.log.debug("connecting to host") server = None connected = False attempt = 0 while not connected and attempt < SAMBA_CONNECT_MAX_TRIES : try: attempt = attempt + 1 # TODO: we should query port 135 for the right service server = socket(AF_INET, SOCK_STREAM) server.connect((self.samba_host, SAMBA_PORT)) connected = True except: self.log.error("NTLMAuthHandler: caught exception when" " connecting to samba host: attempt %d", attempt) sleep(1) if not connected: raise Exception("NTLMAuthHandler: unable to connect to samba host" " aborting after %d attempts" % attempt) self.log.debug("server.sockname: %s", str(server.getsockname())) self.log.debug("building bind packet") packet = RPCBindOutPacket() packet.ntlm_payload = ntlm_payload self.log.debug("sending bind packet") server.sendall(packet.make()) self.log.debug("sent bind packet, receiving response") packet = RPCPacket.from_file(server) self.log.debug("response parsed: %s", packet.pretty_dump()) if isinstance(packet, RPCBindACKPacket): self.log.debug("ACK received") self.client_data[client_id] = {"status": "challenged", "last_used": time(), "server": server} response = 1 ntlm_payload = packet.ntlm_payload else: response = 0 ntlm_payload = "" self.log.debug("* done with client auth stage0") return (response, ntlm_payload)
def _handle_negotiate(self, client_id, ntlm_payload): # print >> sys.stderr, "* client auth stage0" # print >> sys.stderr, "connecting to host" server = None connected = False attempt = 0 while not connected: try: attempt = attempt + 1 # TODO: we should query port 135 for the right service server = socket(AF_INET, SOCK_STREAM) server.connect((self.samba_host, SAMBA_PORT)) connected = True except: print >> sys.stderr, ("NTLMAuthHandler: caught exception when" " connecting to samba host: attempt %d" % attempt) sleep(1) # print >> sys.stderr, "host: %s" % str(server.getsockname()) # print >> sys.stderr, "building bind packet" packet = RPCBindOutPacket() packet.ntlm_payload = ntlm_payload # print >> sys.stderr, "sending bind packet" server.sendall(packet.make()) # print >> sys.stderr, "sent bind packet, receiving response" packet = RPCPacket.from_file(server) # print >> sys.stderr, "response parsed: %s" % packet.pretty_dump() if isinstance(packet, RPCBindACKPacket): # print >> sys.stderr, "ACK received" self.client_data[client_id] = { "status": "challenged", "last_used": time(), "server": server } response = 1 ntlm_payload = packet.ntlm_payload else: response = 0 ntlm_payload = "" # print >> sys.stderr, "* done with client auth stage0" return (response, ntlm_payload)
def _handle_negotiate(self, client_id, ntlm_payload): # print >> sys.stderr, "* client auth stage0" # print >> sys.stderr, "connecting to host" server = None connected = False attempt = 0 while not connected: try: attempt = attempt + 1 # TODO: we should query port 135 for the right service server = socket(AF_INET, SOCK_STREAM) server.connect((self.samba_host, SAMBA_PORT)) connected = True except: print >>sys.stderr, ( "NTLMAuthHandler: caught exception when" " connecting to samba host: attempt %d" % attempt ) sleep(1) # print >> sys.stderr, "host: %s" % str(server.getsockname()) # print >> sys.stderr, "building bind packet" packet = RPCBindOutPacket() packet.ntlm_payload = ntlm_payload # print >> sys.stderr, "sending bind packet" server.sendall(packet.make()) # print >> sys.stderr, "sent bind packet, receiving response" packet = RPCPacket.from_file(server) # print >> sys.stderr, "response parsed: %s" % packet.pretty_dump() if isinstance(packet, RPCBindACKPacket): # print >> sys.stderr, "ACK received" self.client_data[client_id] = {"status": "challenged", "last_used": time(), "server": server} response = 1 ntlm_payload = packet.ntlm_payload else: response = 0 ntlm_payload = "" # print >> sys.stderr, "* done with client auth stage0" return (response, ntlm_payload)