Пример #1
0
def main(workspace='', args=None, parser=None):
    parser.add_argument('host_id', help='Service Parent Host ID')
    parser.add_argument('name', help='Service Name')
    parser.add_argument('ports',
                        help='Service ports, as a comma separated list')
    parser.add_argument('--protocol', help='Service protocol', default='tcp')
    parser.add_argument('--status', help='Service status', default='open')
    parser.add_argument('--version', help='Service version', default='unknown')
    parser.add_argument('--description',
                        help='Service description',
                        default='')

    parser.add_argument(
        '--dry-run',
        action='store_true',
        help='Do not touch the database. Only print the object ID')

    parsed_args = parser.parse_args(args)

    ports = filter(None, parsed_args.ports.split(','))
    res_ids = []  #new service or old services ids affected by the command
    for port in ports:
        params = {
            'name': parsed_args.name,
            'port': port,
            'protocol': parsed_args.protocol,
            'host_id': parsed_args.host_id
        }

        obj = factory.createModelObject(models.Service.class_signature,
                                        parsed_args.name,
                                        workspace,
                                        protocol=parsed_args.protocol,
                                        ports=[port],
                                        status=parsed_args.status,
                                        version=parsed_args.version,
                                        description=parsed_args.description,
                                        parent_id=parsed_args.host_id)

        old = models.get_service(workspace, **params)

        if old is None:
            if not parsed_args.dry_run:
                models.create_service(workspace, obj)
                old = models.get_service(workspace, **params)
        else:
            print("A service with ID %s already exists!" % old.getID())

        res_ids.append(old.getID())

    return 0, res_ids
Пример #2
0
def main(workspace='', args=None, parser=None):
    parser.add_argument('interface_id', help='Interface ID')
    parser.add_argument('name', help='Service Name')
    parser.add_argument('ports', help='Service ports, as a comma separated list')
    parser.add_argument('--protocol', help='Service protocol', default='tcp')
    parser.add_argument('--status', help='Service status', default='running')
    parser.add_argument('--version', help='Service version', default='unknown')
    parser.add_argument('--description', help='Service description', default='')

    parser.add_argument('--dry-run', action='store_true', help='Do not touch the database. Only print the object ID')

    parsed_args = parser.parse_args(args)

    ports = filter(None, parsed_args.ports.split(','))

    obj = factory.createModelObject(models.Service.class_signature, parsed_args.name, workspace,
                                    protocol=parsed_args.protocol,
                                    ports=ports,
                                    status=parsed_args.status,
                                    version=parsed_args.version,
                                    description=parsed_args.description,
                                    parent_id=parsed_args.interface_id
                                    )

    old = models.get_service(workspace, obj.getID())

    if old is None:
        if not parsed_args.dry_run:
            models.create_service(workspace, obj)
    else:
        print "A service with ID %s already exists!" % obj.getID()
        return 2, None

    return 0, obj.getID()
Пример #3
0
def get_parent(ws, parent_tag):
    logger.debug("Getting parent")
    try:
        parent = models.get_host(ws, parent_tag) or models.get_service(ws, parent_tag)
    except ResourceDoesNotExist:
        parent = models.get_hosts(ws, name=parent_tag) or models.get_services(ws, name=parent_tag)
        if len(parent) == 0:
            return None

    return parent
Пример #4
0
def get_parent(ws, parent_tag):
    logger.debug("Getting parent")
    try:
        parent = models.get_host(ws, parent_tag) or models.get_service(ws, parent_tag)
    except ResourceDoesNotExist:
        parent = models.get_hosts(ws, name=parent_tag) or models.get_services(ws, name=parent_tag)
        if len(parent) == 0:
            return None

    return parent
Пример #5
0
def main(workspace='', args=None, parser=None):
    parser.add_argument('interface_id', help='Interface ID')
    parser.add_argument('name', help='Service Name')
    parser.add_argument('ports',
                        help='Service ports, as a comma separated list')
    parser.add_argument('--protocol', help='Service protocol', default='tcp')
    parser.add_argument('--status', help='Service status', default='running')
    parser.add_argument('--version', help='Service version', default='unknown')
    parser.add_argument('--description',
                        help='Service description',
                        default='')

    parser.add_argument(
        '--dry-run',
        action='store_true',
        help='Do not touch the database. Only print the object ID')

    parsed_args = parser.parse_args(args)

    ports = filter(None, parsed_args.ports.split(','))

    obj = factory.createModelObject(models.Service.class_signature,
                                    parsed_args.name,
                                    workspace,
                                    protocol=parsed_args.protocol,
                                    ports=ports,
                                    status=parsed_args.status,
                                    version=parsed_args.version,
                                    description=parsed_args.description,
                                    parent_id=parsed_args.interface_id)

    old = models.get_service(workspace, obj.getID())

    if old is None:
        if not parsed_args.dry_run:
            models.create_service(workspace, obj)
    else:
        print "A service with ID %s already exists!" % obj.getID()
        return 2, None

    return 0, obj.getID()
Пример #6
0
def main(workspace="", args=None, parser=None):

    WORKSPACE = workspace

    parser.add_argument("--csv", help="Csv file to import")
    parsed_args = parser.parse_args(args)

    if not parsed_args.csv:
        print "Error: Give a CSV file to import with --csv"
        return 2, None

    try:
        file_csv = open(parsed_args.csv, "r")
    except:
        print "Error: Unreadeable CSV file, check the path"
        raise

    counter = 0
    csv_reader = csv.DictReader(file_csv, delimiter=",", quotechar='"')
    for register in csv_reader:

        host, interface, service, vulnerability, vulnerability_web = parse_register(register)

        # Set all IDs and create objects
        if host is not None:

            host.setID(None)
            if not models.get_host(WORKSPACE, host.getID()):

                counter += 1
                print "New host: " + host.getName()
                models.create_host(WORKSPACE, host)

        if interface is not None:

            interface.setID(host.getID())
            if not models.get_interface(WORKSPACE, interface.getID()):

                counter += 1
                print "New interface: " + interface.getName()
                models.create_interface(WORKSPACE, interface)

        if service is not None:

            service.setID(interface.getID())
            if not models.get_service(WORKSPACE, service.getID()):

                counter += 1
                print "New service: " + service.getName()
                models.create_service(WORKSPACE, service)

        # Check if Service exist, then create the vuln with parent Service.
        # If not exist the Service, create the vuln with parent Host.
        if vulnerability is not None:

            if service is None:
                vulnerability.setID(host.getID())
            else:
                vulnerability.setID(service.getID())
            if not models.get_vuln(WORKSPACE, vulnerability.getID()):

                counter += 1
                print "New vulnerability: " + vulnerability.getName()
                models.create_vuln(WORKSPACE, vulnerability)

        elif vulnerability_web is not None:

            vulnerability_web.setID(service.getID())
            if not models.get_web_vuln(WORKSPACE, vulnerability_web.getID()):

                counter += 1
                print "New web vulnerability: " + vulnerability_web.getName()
                models.create_vuln_web(WORKSPACE, vulnerability_web)

    print "[*]", counter, "new Faraday objects created."
    file_csv.close()
    return 0, None
Пример #7
0
def main(workspace="", args=None, parser=None):

    WORKSPACE = workspace

    parser.add_argument("--csv", help="Csv file to import")
    parsed_args = parser.parse_args(args)

    if not parsed_args.csv:
        print "Error: Give a CSV file to import with --csv"
        return 2, None

    try:
        file_csv = open(parsed_args.csv, "r")
    except:
        print "Error: Unreadeable CSV file, check the path"
        raise

    counter = 0
    csv_reader = csv.DictReader(file_csv, delimiter=",", quotechar='"')
    for register in csv_reader:

        host, service, vulnerability, vulnerability_web = parse_register(register)

        # Set all IDs and create objects
        if host is not None:
            old_host = models.get_host(WORKSPACE, ip=host.getName())
            if not old_host:

                counter += 1
                print "New host: " + host.getName()
                models.create_host(WORKSPACE, host)
            host = models.get_host(WORKSPACE, ip=host.getName())

        if service is not None:
            service.setParent(host.getID())
            service_params = {
                'name': service.getName(),
                'port': service.getPorts()[0],
                'protocol': service.getProtocol(),
                'host_id': service.getParent()
            }
            old_service = models.get_service(WORKSPACE, **service_params)
            if not old_service:

                counter += 1
                print "New service: " + service.getName()
                models.create_service(WORKSPACE, service)
            service = models.get_service(WORKSPACE, **service_params)

        # Check if Service exist, then create the vuln with parent Service.
        # If not exist the Service, create the vuln with parent Host.
        if vulnerability is not None:
            if host and not service:
                parent_type = 'Host'
                parent_id = host.getID()
            if host and service:
                parent_type = 'Service'
                parent_id = service.getID()
            vulnerability.setParent(parent_id)
            vulnerability.setParentType(parent_type)

            vuln_params = {
                'name': vulnerability.getName(),
                'description': vulnerability.getDescription(),
                'parent_type': parent_type,
                'parent': parent_id,
            }
            if not models.get_vuln(WORKSPACE, **vuln_params):

                counter += 1
                print "New vulnerability: " + vulnerability.getName()
                models.create_vuln(WORKSPACE, vulnerability)

        elif vulnerability_web is not None:

            vuln_web_params = {
                'name': vulnerability_web.getName(),
                'description': vulnerability_web.getDescription(),
                'parent': service.getID(),
                'parent_type': 'Service',
                'method': vulnerability_web.getMethod(),
                'parameter_name': vulnerability_web.getParams(),
                'path': vulnerability_web.getPath(),
                'website': vulnerability_web.getWebsite(),
            }
            vulnerability_web.setParent(service.getID())
            if not models.get_web_vuln(WORKSPACE, **vuln_web_params):

                counter += 1
                print "New web vulnerability: " + vulnerability_web.getName()
                models.create_vuln_web(WORKSPACE, vulnerability_web)

    print "[*]", counter, "new Faraday objects created."
    file_csv.close()
    return 0, None
Пример #8
0
def main(workspace="", args=None, parser=None):

    WORKSPACE = workspace

    parser.add_argument("--csv", help="Csv file to import")
    parsed_args = parser.parse_args(args)

    if not parsed_args.csv:
        print "Error: Give a CSV file to import with --csv"
        return 2, None

    try:
        file_csv = open(parsed_args.csv, "r")
    except:
        print "Error: Unreadeable CSV file, check the path"
        raise

    counter = 0
    csv_reader = csv.DictReader(file_csv, delimiter=",", quotechar='"')
    for register in csv_reader:

        host, interface, service, vulnerability, vulnerability_web = parse_register(
            register)

        # Set all IDs and create objects
        if host is not None:

            host.setID(None)
            if not models.get_host(WORKSPACE, host.getID()):

                counter += 1
                print "New host: " + host.getName()
                models.create_host(WORKSPACE, host)

        if interface is not None:

            interface.setID(host.getID())
            if not models.get_interface(WORKSPACE, interface.getID()):

                counter += 1
                print "New interface: " + interface.getName()
                models.create_interface(WORKSPACE, interface)

        if service is not None:

            service.setID(interface.getID())
            if not models.get_service(WORKSPACE, service.getID()):

                counter += 1
                print "New service: " + service.getName()
                models.create_service(WORKSPACE, service)

        # Check if Service exist, then create the vuln with parent Service.
        # If not exist the Service, create the vuln with parent Host.
        if vulnerability is not None:

            if service is None:
                vulnerability.setID(host.getID())
            else:
                vulnerability.setID(service.getID())
            if not models.get_vuln(WORKSPACE, vulnerability.getID()):

                counter += 1
                print "New vulnerability: " + vulnerability.getName()
                models.create_vuln(WORKSPACE, vulnerability)

        elif vulnerability_web is not None:

            vulnerability_web.setID(service.getID())
            if not models.get_web_vuln(WORKSPACE, vulnerability_web.getID()):

                counter += 1
                print "New web vulnerability: " + vulnerability_web.getName()
                models.create_vuln_web(WORKSPACE, vulnerability_web)

    print "[*]", counter, "new Faraday objects created."
    file_csv.close()
    return 0, None
Пример #9
0
def main(workspace="", args=None, parser=None):

    WORKSPACE = workspace

    parser.add_argument("--csv", help="Csv file to import")
    parsed_args = parser.parse_args(args)

    if not parsed_args.csv:
        print "Error: Give a CSV file to import with --csv"
        return 2, None

    try:
        file_csv = open(parsed_args.csv, "r")
    except:
        print "Error: Unreadeable CSV file, check the path"
        raise

    counter = 0
    csv_reader = csv.DictReader(file_csv, delimiter=",", quotechar='"')
    for register in csv_reader:
        try:
            host, service, vulnerability, vulnerability_web = parse_register(register)

            # Set all IDs and create objects
            if host is not None:
                old_host = models.get_host(WORKSPACE, ip=host.getName())
                if not old_host:

                    counter += 1

                    print "New host: " + host.getName()
                    try:
                        models.create_host(WORKSPACE, host)
                    except Exception as ex:
                        import ipdb; ipdb.set_trace()
                host = models.get_host(WORKSPACE, ip=host.getName())

            if service is not None:
                service.setParent(host.getID())
                service_params = {
                    'name': service.getName(),
                    'port': service.getPorts()[0],
                    'protocol': service.getProtocol(),
                    'host_id': service.getParent()
                }
                old_service = models.get_service(WORKSPACE, **service_params)
                if not old_service:

                    counter += 1
                    print "New service: " + service.getName()
                    models.create_service(WORKSPACE, service)
                service = models.get_service(WORKSPACE, **service_params)

            # Check if Service exist, then create the vuln with parent Service.
            # If not exist the Service, create the vuln with parent Host.
            if vulnerability is not None:
                if host and not service:
                    parent_type = 'Host'
                    parent_id = host.getID()
                if host and service:
                    parent_type = 'Service'
                    parent_id = service.getID()
                vulnerability.setParent(parent_id)
                vulnerability.setParentType(parent_type)

                vuln_params = {
                    'name': vulnerability.getName(),
                    'description': vulnerability.getDescription(),
                    'parent_type': parent_type,
                    'parent': parent_id,
                }

                if not models.get_vuln(WORKSPACE, **vuln_params):
                    counter += 1
                    print "New vulnerability: " + vulnerability.getName()
                    models.create_vuln(WORKSPACE, vulnerability)

            elif vulnerability_web is not None:

                vuln_web_params = {
                    'name': vulnerability_web.getName(),
                    'description': vulnerability_web.getDescription(),
                    'parent': service.getID(),
                    'parent_type': 'Service',
                    'method': vulnerability_web.getMethod(),
                    'parameter_name': vulnerability_web.getParams(),
                    'path': vulnerability_web.getPath(),
                    'website': vulnerability_web.getWebsite(),
                }
                vulnerability_web.setParent(service.getID())
                if not models.get_web_vuln(WORKSPACE, **vuln_web_params):

                    counter += 1
                    print "New web vulnerability: " + vulnerability_web.getName()
                    models.create_vuln_web(WORKSPACE, vulnerability_web)
        except ConflictInDatabase:
            print('Conflict in Database, skiping csv row')
        except CantCommunicateWithServerError as ex:
            print(register)
            print('Error', ex)
    print "[*]", counter, "new Faraday objects created."
    file_csv.close()
    return 0, None