示例#1
0
    def do_hosts(self, args):
        """Says hello. If you provide a name, it will greet you with it."""

        parser = self.hosts_args()
        try:
            params = parser.parse_args(args.split(' '))
        except:
            return

        filters = True
        if params.S:
            for search in params.S:
                filters = and_(
                    filters, or_(
                        Host.comment.ilike('%{}%'.format(search)),
                        Host.ipv4.ilike('%{}%'.format(search)),
                        Host.hostname.ilike('%{}%'.format(search)),
                    )
                )

        fmt = "{}{:<15}  {}{:<39}  {}{}"
        hosts = self.controller.db.filter(Host, filters)

        print(fmt.format(Fore.GREEN, 'host', Fore.YELLOW,
              'hostname', Style.RESET_ALL, 'comment'))
        for host in hosts:
            print(fmt.format(Fore.GREEN, host.ipv4, Fore.YELLOW,
                  host.hostname, Style.RESET_ALL, host.comment))
示例#2
0
def index():
    return cursor.query(Link).filter(and_(Link.combined_prediction == True,or_(Link.hidden == None,Link.hidden == False))).order_by(Link.evaluation_date.desc()).limit(5).from_self().order_by(Link.evaluation_date.asc()).all() \
         + cursor.query(Link).filter(and_(Link.evaluation_date == None,Link.combined_prediction == True,or_(Link.hidden == None,Link.hidden == False))).order_by(Link.date.desc()).limit(45).all()
示例#3
0
def disliked():
    return cursor.query(Link).filter(and_(Link.evaluation == False,or_(Link.hidden == None,Link.hidden == False))).order_by(Link.date.asc()).limit(50).all()
示例#4
0
    def do_services(self, args):
        """list stored services"""
        parser = self.services_args()
        args = [] if args == '' else args.split(' ')

        try:
            params = parser.parse_args(args)
        except:
            return

        filters = True

        # ilike filter in version banner
        if params.S:
            for search in params.S:
                filters = and_(filters, or_(
                    *[Service.version.ilike('%{}%'.format(search))
                      for search in params.S]
                ))

        # filter open ports
        if params.u:
            filters = and_(filters, Service.state == 'open')

        # filter specific
        if params.p:
            pfilter = or_(*[(Service.port == port) for port in params.p])
            filters = and_(filters, pfilter)

        # filter hostname
        if params.H:
            try:
                for host in params.H:
                    hosts = self.controller.db.filter(
                        Host,
                        Host.ipv4.like('%{}%'.format(host))
                    )
                    hosts_id = [h.id for h in hosts]
                    filters = and_(filters, Service.host_id.in_(hosts_id))
            except NoResultFound:
                print('no such host')
                return

        colormap = {
            'closed': Fore.RED,
            'open': Fore.GREEN,
            'filtered': Fore.YELLOW
        }
        line = "{:<15} {:<10} {:<20} {:<15} {}"
        services = self.controller.db.filter(Service, filters)

        print(line.format('host', 'port', 'service', 'state', 'version'))
        for service in services:
            color = colormap[service.state]
            if not service.version:
                service.version = ''

            print(line.format(
                service.host.ipv4, str(service.port)+'/'+service.proto,
                service.service, color + service.state + Style.RESET_ALL,
                service.version)
            )
        print(line.format('host', 'port', 'service', 'state', 'version'))