Пример #1
0
 def fromTarget(cls, arg):
     if '@' in arg and ':' in arg:
         auth, sep, endpoint = arg.partition('@')
         endpoint = Endpoint.findByIpPort(endpoint)
         if endpoint is None:
             raise ValueError("Supplied endpoint isn't in workspace")
         user, sep, cred = auth.partition(":")
         if sep == "":
             raise ValueError("No credentials supplied")
         user = User.findByUsername(user)
         if user is None:
             raise ValueError("Supplied user isn't in workspace")
         if cred[0] == "#":
             cred = cred[1:]
         cred = Creds.find(cred)
         if cred is None:
             raise ValueError("Supplied credentials aren't in workspace")
         return Connection(endpoint, user, cred)
     else:
         if ':' not in arg:
             arg = arg + ':22'
         endpoint = Endpoint.findByIpPort(arg)
         if endpoint is None:
             raise ValueError("Supplied endpoint isn't in workspace")
         connection = endpoint.getConnection()
         if connection == None:
             raise ValueError("No working connection for supplied endpoint")
         return connection
     return None
Пример #2
0
 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
Пример #3
0
 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")
Пример #4
0
 def delEndpoint(self,endpoint):
     try:
         endpoint = Endpoint.findByIpPort(endpoint)
     except ValueError:
         print("Could not find endpoint.")
         return False
     if endpoint is None:
         print("Could not find endpoint.")
         return False
     return endpoint.delete()
Пример #5
0
 def scanTarget(self,target,gateway=None):
     if not isinstance(target,Endpoint):
         target = Endpoint.findByIpPort(target)
     if gateway is not None:
         if gateway == "local":
             gateway = None
         else:
             gateway = Connection.fromTarget(gateway)
     else:
         gateway = "auto"
     working = target.scan(gateway=gateway)
     return working
Пример #6
0
 def setOption(self,option,value):
     if option == 'connection':
         if value is None:
             self.options['endpoint'] = None
             self.options['user'] = None
             self.options['creds'] = None
             for option in ['endpoint','user','creds']:
                 print(option+" => "+str(self.getOption(option)))
             return 
         if '@' not in value or ':' not in value:
             return
         connection = Connection.fromTarget(value)
         if connection == None:
             return
         self.options['endpoint'] = connection.getEndpoint()
         self.options['user'] = connection.getUser()
         self.options['creds'] = connection.getCred()
         for option in ['endpoint','user','creds']:
             print(option+" => "+str(self.getOption(option)))
         return 
     if not option in list(self.options.keys()):
         raise ValueError(option+" isn't a valid option.")
     if value != None:
         value = value.strip()
         if option == "endpoint":
             endpoint = Endpoint.findByIpPort(value)
             if endpoint is None:
                 raise ValueError
             value = endpoint
         elif option == "user":
             user = User.findByUsername(value)
             if user is None:
                 raise ValueError
             value = user
         elif option == "creds":
             if value[0] == '#':
                 credId = value[1:]
             else:
                 credId = value
             creds = Creds.find(credId)
             if creds is None:
                 raise ValueError
             value = creds
         elif option == "payload":
             value = Extensions.getPayload(value)
         self.options[option] = value
     else:
         self.options[option] = None
     print(option+" => "+str(self.getOption(option)))
Пример #7
0
    def findPath(self,dst):
        #DST is HOST
        #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 directly from the host.")
            return

        workingDirect = dst.scan(gateway=None,silent=True)
        if workingDirect:
            p = Path(None,dst)
            p.save()
            print("Could reach target directly, path added.")
            return

        for h in Path.getHostsOrderedClosest():
            e = h.getClosestEndpoint()
            gateway = Connection.findWorkingByEndpoint(e)
            working = dst.scan(gateway=gateway,silent=True)
            if working:
                p = Path(h,dst)
                p.save()
                print("Working with gw "+str(e)+" (host "+str(h)+")")
                return
        return
Пример #8
0
 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)