def main(workspace='', args=None, parser=None): parser.add_argument('protocol', help="Desired protocol", default="") parser.add_argument('--path', help="Saves the Image in a given path", default=".") parsed_args = parser.parse_args(args) protocols = parsed_args.protocol.split(",") path = parsed_args.path for protocol in protocols: if not os.path.exists(path): print("Invalid Path") sys.exit() try: services = models.get_services(workspace) except ResourceDoesNotExist: print("Invalid workspace name: ", workspace) return 1, None for service in services: service_protocol = service.protocol.lower() if service_protocol == protocol: port = str(service.ports[0]) interface_id = ".".join(service.id.split(".")[:2]) interface = models.get_interface(workspace, interface_id) ip = interface.ipv4["address"] print(protocol + "://" + ip + ":" + port) screenshot(path, protocol, ip, port) return 0, None
def search_hosts_by_service(workspace, b_service): output = "" all_hosts = list(models.get_hosts(workspace)) all_services = list(models.get_services(workspace)) for host in all_hosts: for service in all_services: id_service_host = service.parent_id if host.id == id_service_host and service.name == b_service: output += host.name + "\n" break return output
def main(workspace='', args=None, parser=None): parser.add_argument('-y', '--yes', action="store_true") parsed_args = parser.parse_args(args) if not parsed_args.yes: if not query_yes_no( "Are you sure you want to delete all closed services in the " "workspace %s" % workspace, default='no'): return 1, None for service in models.get_services(workspace): if service.status != 'open' and service.status != 'opened': print('Deleted service: ' + service.name) models.delete_service(workspace, service.id) return 0, None
def get_services(self, **params): return models.get_services(self.active_workspace, **params)
def main(workspace='', args=None, parser=None): parser.add_argument('-p', type=int, nargs='+', metavar='port', help='List of ports to filter', default=[]) parser.add_argument('services', nargs='*', help='List of service names', default=[]), parser.add_argument('--columns', help='Comma separated list of columns to show.', default="host,service,ports,protocol,status,host_os", choices=COLUMNS.keys()) parser.add_argument('--status', help='Comma separated list of status to filter for.') parser.add_argument('-a', help='Show additional information, like ports filtered and column headers.', action='store_true', dest='additional_info') parser.add_argument('-f', help='Do not apply any filter. Print every host.', action='store_true', dest='no_filter') parser.add_argument('-s', '--sorted', help='Print the list sorted IP..', action='store_true') parsed_args = parser.parse_args(args) port_list = parsed_args.p for service in parsed_args.services: if service in SERVICES: port_list += SERVICES[service] else: sys.stderr.write(Fore.YELLOW + "WARNING: Service definition not found. [%s]\n" % service + Fore.RESET) if not port_list and not parsed_args.no_filter: print("Empty filter set.") return 1, None if parsed_args.additional_info and not parsed_args.no_filter: print('Filtering services for ports: ' + ', '.join(map(str, sorted(port_list)))) columns = filter(None, parsed_args.columns.split(',')) status_filter = None if parsed_args.status is not None: status_filter = filter(None, parsed_args.status.split(',')) lines = [] for service in models.get_services(workspace): for port in service.ports: if port in port_list or parsed_args.no_filter: if not parsed_args.no_filter and status_filter is not None and not service.status in status_filter: continue column_data = [] for column in columns: column_data += [COLUMNS[column](service, workspace)] lines += [column_data] if not lines: print("No services running on that port found.") return 0, None col_width = max(len(word) for row in lines for word in row) + 2 if parsed_args.additional_info: print(''.join(col.ljust(col_width) for col in columns)) print('-' * (col_width * len(columns))) if parsed_args.sorted: # Compare lines using the first column (IP) for row in sorted(lines, cmp=lambda l1, l2: cmp(l1[0], l2[0])): print("".join(word.ljust(col_width) for word in row)) else: for row in lines: print("".join(word.ljust(col_width) for word in row)) return 0, None