def identifyObject(self,target): if target[0] == "#": credsId = target[1:] else: credsId = target creds = Creds.find(credsId) if creds is not None: return creds user = User.findByUsername(target) if user is not None: return user try: dst = Endpoint.findByIpPort(target) if dst is not None: return dst except: pass hosts = Host.findByName(target) if len(hosts) > 1: print("Multiple hosts matching, use endpoints") return None if len(hosts) == 1: return hosts[0] print("Could not identify object.") return None
def addPath(self,src,dst): if src.lower() != "local": if src not in self.getHostsNames(): print("Not a known Host name.") return hosts = Host.findByName(src) if len(hosts) > 1: print("Several hosts corresponding. Add failed") return src = hosts[0] if src is None: print("The source Host provided doesn't exist in this workspace") return else: src = None try: dst = Endpoint.findByIpPort(dst) except: print("Please specify valid destination endpoint in the IP:PORT form") if dst is None: print("The destination endpoint provided doesn't exist in this workspace") return p = Path(src,dst) p.save() print("Path saved")
def delHost(self,host): if host not in self.getHostsNames(): print("Not a known Host name.") return False hosts = Host.findByName(host) if len(hosts) > 1: print("Several hosts corresponding. Please delete endpoints.") return False return hosts[0].delete()
def runTarget(self,arg,payloadName,stmt): if arg in self.getHostsNames(): hosts = Host.findByName(arg) if len(hosts) > 1: print("Several hosts corresponding. Please target endpoint.") return False arg = str(hosts[0].getClosestEndpoint()) connection = Connection.fromTarget(arg) if not connection.working: print("Please check connection "+str(connection)+" with connect first") return False payload = Extensions.getPayload(payloadName) return connection.run(payload,self.workspaceFolder,stmt)
def run(cls, stmt, workspace): nmapfile = getattr(stmt, 'nmapfile') fromHost = getattr(stmt, 'from', "Local") if fromHost is None: src = None print("No source host specified, using Local") elif fromHost == "Local": src = None else: hosts = Host.findByName(fromHost) if len(hosts) > 1: print("Several hosts corresponding.") return False elif len(hosts) == 0: print("No host corresponding.") return False src = hosts[0] try: report = NmapParser.parse_fromfile(nmapfile) except Exception as e: print("Failed to read source file: " + str(e)) return False count = 0 countNew = 0 for host in report.hosts: for s in host.services: if s.service == "ssh": count = count + 1 newEndpoint = Endpoint(host.address, s.port) if newEndpoint.getId() is None: countNew = countNew + 1 newEndpoint.save() newPath = Path(src, newEndpoint) newPath.save() print( str(count) + " endpoints found, " + str(countNew) + " new endpoints saved") return True
def getPathToDst(self,dst): if dst in self.getHostsNames(): hosts = Host.findByName(dst) if len(hosts) > 1: print("Several hosts corresponding. Please target endpoint.") return False dst = str(hosts[0].getClosestEndpoint()) try: dst = Endpoint.findByIpPort(dst) except: print("Please specify a valid endpoint in the IP:PORT form") return if dst is None: print("The endpoint provided doesn't exist in this workspace") return if Path.hasDirectPath(dst): print("The destination should be reachable from the host") return chain = Path.getPath(None,dst) if chain is None: print("No path could be found to the destination") return for path in chain: print(path)