def recordNmapScan(self, scan, descriptor): #Performs the NMap scan using python-nmap library. Returns the exitnodes with the open ports found in the scanning process. for host in scan.all_hosts(): torNode = TorNodeData() torNode.host = host torNode.nickName = descriptor.nickname torNode.fingerprint = descriptor.fingerprint torNode.torVersion = descriptor.tor_version if descriptor.contact is not None: torNode.contactData = descriptor.contact.decode("utf-8", "replace") if scan[host].has_key('status'): torNode.state = scan[host]['status']['state'] torNode.reason = scan[host]['status']['reason'] for protocol in ["tcp", "udp", "icmp"]: if scan[host].has_key(protocol): ports = scan[host][protocol].keys() for port in ports: torNodePort = TorNodePort() torNodePort.port = port torNodePort.state = scan[host][protocol][port]['state'] if scan[host][protocol][port].has_key('reason'): torNodePort.reason = scan[host][protocol][port]['reason'] if scan[host][protocol][port].has_key('name'): torNodePort.name = scan[host][protocol][port]['name'] if scan[host][protocol][port].has_key('version'): torNodePort.version = scan[host][protocol][port]['version'] if 'open' in (scan[host][protocol][port]['state']): torNode.openPorts.append(torNodePort) else: torNode.closedFilteredPorts.append(torNodePort) self.exitNodes.append(torNode) else: self.cli.logger.warn(term.format("[-] There's no match in the Nmap scan with the specified protocol %s" %(protocol), term.Color.RED))
def recordNmapScan(self, scan, descriptor): #Performs the NMap scan using python-nmap library. Returns the exitnodes with the open ports found in the scanning process. for host in scan.all_hosts(): torNode = TorNodeData() torNode.host = host torNode.nickName = descriptor.nickname torNode.fingerprint = descriptor.fingerprint torNode.torVersion = descriptor.tor_version if descriptor.contact is not None: torNode.contactData = descriptor.contact.decode( "utf-8", "replace") if scan[host].has_key('status'): torNode.state = scan[host]['status']['state'] torNode.reason = scan[host]['status']['reason'] for protocol in ["tcp", "udp", "icmp"]: if scan[host].has_key(protocol): ports = scan[host][protocol].keys() for port in ports: torNodePort = TorNodePort() torNodePort.port = port torNodePort.state = scan[host][protocol][port][ 'state'] if scan[host][protocol][port].has_key('reason'): torNodePort.reason = scan[host][protocol][ port]['reason'] if scan[host][protocol][port].has_key('name'): torNodePort.name = scan[host][protocol][port][ 'name'] if scan[host][protocol][port].has_key('version'): torNodePort.version = scan[host][protocol][ port]['version'] if 'open' in (scan[host][protocol][port]['state']): torNode.openPorts.append(torNodePort) else: torNode.closedFilteredPorts.append(torNodePort) self.exitNodes.append(torNode) else: self.cli.logger.warn( term.format( "[-] There's no match in the Nmap scan with the specified protocol %s" % (protocol), term.Color.RED))
def searchExitNodes(self, numberOfScans, scanIdentifier): if self.cursor is None: self.initDatabase() exitNodes = [] if scanIdentifier is None: self.cursor.execute(database.selectTorScan, (numberOfScans,)) else: self.cursor.execute(database.selectTorScanIdentifier, (scanIdentifier,)) for row in self.cursor.fetchall(): scanId, scanDate = row self.cursor.execute(database.selectTorNodeData, (scanId,)) for node in self.cursor.fetchall(): torNodeId, host, state, reason, nickName = node nodeData = TorNodeData() nodeData.id = torNodeId nodeData.host = host nodeData.state = state nodeData.reason = reason nodeData.nickName = nickName ports = self.cursor.execute(database.selectTorNodePort, (torNodeId,) ) for port in ports.fetchall(): (portId, portState, portReason, portNumber, portName, portVersion, torNode) = port nodePort = TorNodePort() nodePort.id = portId nodePort.state = portState nodePort.reason = portReason nodePort.port = portNumber nodePort.name = portName nodePort.version = portVersion nodePort.torNodeId = torNode if "open" in portState: nodeData.openPorts.append(nodePort) else: nodeData.closedFilteredPorts.append(nodePort) exitNodes.append(nodeData) return exitNodes