Ejemplo n.º 1
0
    def run(self):
        source_server = CONF.getCouchURI()
        if not source_server:
            logger.info("""No DB configuration found.
                    To upgrade your DB please configure a valid CouchDB URI in:
                    ~/.faraday/config/user.xml configuration file.""")
            return

        serv = couchdbkit.Server(source_server)

        logger.info('We are about to upload CouchdbViews in Server [%s]' %
                    source_server)
        if not query_yes_no(
                "Faraday won't behave correctly with older versions, proceed?",
                'no'):
            return

        dbs = filter(lambda x: not x.startswith("_") and 'backup' not in x and \
                'reports' not in x, serv.all_dbs())
        logger.info('Dbs to upgrade: %s' % (', '.join(dbs)))

        logger.info('Preparing updates on Couchdbs')
        processed = 0
        views_uploader = ViewsManager()
        for db_name in dbs:
            db_source = couchdbkit.Database("/".join((source_server, db_name)))
            views_uploader.addViews(db_source, force=True)
Ejemplo n.º 2
0
def checkVersion():
    try:
        f = open(CONST_VERSION_FILE)
        f_version = f.read().strip()
        if not args.update:
            if getInstanceConfiguration().getVersion(
            ) != None and getInstanceConfiguration().getVersion() != f_version:
                logger.warning(
                    "You have different version of Faraday since your last run.\nRun ./faraday.py --update to update configuration!"
                )
                if query_yes_no('Do you want to close Faraday?', 'yes'):
                    exit(-1)

        getInstanceConfiguration().setVersion(f_version)
        f.close()

        doc = {"ver": getInstanceConfiguration().getVersion()}

        if os.path.isfile(CONST_CONFIG):
            os.remove(CONST_CONFIG)
        with open(CONST_CONFIG, "w") as doc_file:
            json.dump(doc, doc_file)
    except Exception as e:
        getLogger("launcher").error(
            "It seems that something's wrong with your version\nPlease contact customer support"
        )
        exit(-1)
Ejemplo n.º 3
0
    def doUpdates(self):
        logger.info('Removing old pyc files')
        subprocess.call(['find', '.', '-name', '*.pyc', '-delete'])
        logger.info('Pulling latest Github Master copy')
        if query_yes_no('Proceed?', 'yes'):
            subprocess.call(['git', 'pull'])
        logger.info('Checking qt3 libs')
        try:
            import qt
        except:
            for name in ['libqt.so', 'libqt.so.3', 'libqt.so.3.3',
                         'libqt.so.3.3.8', 'libqui.so', 'libqui.so.1',
                         'libqui.so.1.0', 'libqui.so.1.0.0']:

                qt_path = '/usr/local/qt/lib/'
                lib_path = '/usr/local/lib/'
                if os.path.exists(os.path.join(qt_path, name)):
                    if not os.path.exists(os.path.join(lib_path, name)):
                        shutil.copy(os.path.join(qt_path, name), os.path.join(lib_path, name))
                else:
                    logger.error("QT Dependencies not met. Have you run install.sh?")
                    sys.exit(-1)
            os.system('ldconfig')
        logger.info('Installing missing dependencies in pip')
        pip.main(['install', '-r', CONST_REQUIREMENTS_FILE, '--user'])
        logger.info('Upgrading DBs to latest version')
        DB().run() 
Ejemplo n.º 4
0
def check_dependencies_or_exit():
    """
    Dependency resolver based on a previously specified CONST_REQUIREMENTS_FILE.
    Currently checks a list of dependencies from a file and exits if they are not met.
    """

    installed_deps, missing_deps, conflict_deps = dependencies.check_dependencies(
        requirements_file=FARADAY_REQUIREMENTS_FILE)

    logger.info("Checking dependencies...")

    if conflict_deps:
        logger.info(
            "Some dependencies are old. Update them with \"pip install -r requirements_server.txt -U\""
        )

    if missing_deps:

        install_deps = query_yes_no("Do you want to install them?",
                                    default="no")

        if install_deps:
            dependencies.install_packages(missing_deps)
            logger.info(
                "Dependencies installed. Please launch Faraday Server again.")
            sys.exit(0)
        else:
            logger.error(
                "Dependencies not met. Please refer to the documentation in order to install them. [%s]",
                ", ".join(missing_deps))
            sys.exit(1)

    logger.info("Dependencies met")
Ejemplo n.º 5
0
    def run(self):
        source_server = CONF.getCouchURI()
        if not source_server:
            logger.info("""No DB configuration found.
                    To upgrade your DB please configure a valid CouchDB URI in:
                    ~/.faraday/config/user.xml configuration file.""")
            return

        serv = couchdbkit.Server(source_server)

        logger.info('We are about to upgrade dbs in Server [%s]' %
                    source_server)
        dbs = filter(
            lambda x: not x.startswith("_") and 'backup' not in x and x not in
            CONST_BLACKDBS, serv.all_dbs())
        logger.info('Dbs to upgrade: %s' % (', '.join(dbs)))

        if not query_yes_no('Proceed?', 'no'):
            return

        logger.info('Preparing updates on Couchdbs')
        processed = 0
        logger.info('About to upgrade %d dbs' % len(dbs))
        for db_name in dbs:
            logger.info('Updating db %s' % db_name)
            try:
                self.update_db(db_name)
                processed = processed + 1
            except Exception as e:
                logger.error(e)
            logger.info('Updated DB [%s]. %d remaining' %
                        (db_name, len(dbs) - processed))
        logger.info(
            "Update process finish, be kind to review the process.\nBackuped databases won't be accesible"
        )
Ejemplo n.º 6
0
    def run(self):
        source_server = CONF.getCouchURI()
        if not source_server:
            logger.info("""No DB configuration found.
                    To upgrade your DB please configure a valid CouchDB URI in:
                    ~/.faraday/config/user.xml configuration file.""")
            return

        serv = couchdbkit.Server(source_server)

        logger.info('We are about to upload CouchdbViews in Server [%s]' % source_server)
        if not query_yes_no("Faraday won't behave correctly with older versions, proceed?", 'no'):
            return

        dbs = filter(lambda x: not x.startswith("_") and 'backup' not in x and \
                'reports' not in x, serv.all_dbs())
        logger.info('Dbs to upgrade: %s' % (', '.join(dbs)))


        logger.info('Preparing updates on Couchdbs')
        processed = 0
        views_uploader = ViewsManager()
        for db_name in dbs:
            db_source = couchdbkit.Database("/".
                    join((source_server, db_name)))
            views_uploader.addViews(db_source, force = True)
Ejemplo n.º 7
0
def setup_environment(check_deps=False):
    # Configuration files generation
    server.config.copy_default_config_to_local()

    if check_deps:

        # Check dependencies
        installed_deps, missing_deps, conflict_deps = dependencies.check_dependencies(
            requirements_file=server.config.REQUIREMENTS_FILE)

        logger.info("Checking dependencies...")

        if conflict_deps:
            logger.info("Some dependencies are old. Update them with \"pip install -r requirements_server.txt -U\"")

        if missing_deps:

            install_deps = query_yes_no("Do you want to install them?", default="no")

            if install_deps:
                dependencies.install_packages(missing_deps)
                logger.info("Dependencies installed. Please launch Faraday Server again.")
                sys.exit(0)
            else:
                logger.error("Dependencies not met. Please refer to the documentation in order to install them. [%s]",
                             ", ".join(missing_deps))

        logger.info("Dependencies met")

    # Web configuration file generation
    server.config.gen_web_config()
Ejemplo n.º 8
0
def main(workspace='', args=None, parser=None):

    parser.add_argument('-y', '--yes', action="store_true")
    parsed_args = parser.parse_args(args)

    try:
        vulns = models.get_all_vulns(workspace)
    except ResourceDoesNotExist:
        print ("Invalid workspace name: ", workspace)
        return 1, None

    if not parsed_args.yes:
        if not query_yes_no("Are you sure you want to change the status to closed of all the vulns in workspace %s" % workspace, default='no'):
            return 1, None

    count = 0
    for vuln in vulns:
        old_status = vuln.status

        # Valid status
        if vuln.status != "closed":

            vuln.status = "closed"
            count += 1

            if vuln.class_signature == "Vulnerability":
                models.update_vuln(workspace, vuln)

            elif vuln.class_signature == "VulnerabilityWeb":
                models.update_vuln_web(workspace, vuln)

            print (vuln.name, ": Status changed from", old_status,"to closed successfully")

    print ("End of process:", count, "vulnerabilities changed to closed")
    return 0, None
Ejemplo n.º 9
0
    def run(self):
        source_server = CONF.getCouchURI()
        if not source_server:
            logger.info("""No DB configuration found.
                    To upgrade your DB please configure a valid CouchDB URI in:
                    ~/.faraday/config/user.xml configuration file.""")
            return

        serv = couchdbkit.Server(source_server)

        logger.info('We are about to upgrade dbs in Server [%s]' % source_server)
        dbs = filter(lambda x: not x.startswith("_") and 'backup' not in x and 'reports' not in x, serv.all_dbs())
        logger.info('Dbs to upgrade: %s' % (', '.join(dbs)))

        if not query_yes_no('Proceed?', 'no'):
            return

        logger.info('Preparing updates on Couchdbs')
        processed = 0
        logger.info('About to upgrade %d dbs' % len(dbs))
        for db_name in dbs:
            logger.info('Updating db %s' % db_name)
            try:
                self.update_db(db_name)
                processed = processed + 1
            except Exception as e:
                logger.error(e) 
            logger.info('Updated DB [%s]. %d remaining' % (db_name, len(dbs) - processed)) 
        logger.info("Update process finish, be kind to review the process.\nBackuped databases won't be accesible") 
Ejemplo n.º 10
0
def setup_environment(check_deps=False):
    # Configuration files generation
    server.config.copy_default_config_to_local()

    if check_deps:

        # Check dependencies
        installed_deps, missing_deps = dependencies.check_dependencies(
            requirements_file=server.config.REQUIREMENTS_FILE)

        logger.info("Checking dependencies...")

        if missing_deps:

            install_deps = query_yes_no("Do you want to install them?", default="no")

            if install_deps:
                dependencies.install_packages(missing_deps)
                logger.info("Dependencies installed. Please launch Faraday Server again.")
                sys.exit(0)
            else:
                logger.error("Dependencies not met. Please refer to the documentation in order to install them. [%s]",
                             ", ".join(missing_deps))

        logger.info("Dependencies met")

    # Web configuration file generation
    server.config.gen_web_config()

    # Reports DB creation
    server.couchdb.push_reports()
Ejemplo n.º 11
0
def check_dependencies_or_exit():
    """Dependency resolver based on a previously specified CONST_REQUIREMENTS_FILE.

    Currently checks a list of dependencies from a file and exits if they are not met.

    """

    installed_deps, missing_deps = dependencies.check_dependencies(requirements_file=FARADAY_REQUIREMENTS_FILE)

    logger.info("Checking dependencies...")

    if missing_deps:

        install_deps = query_yes_no("Do you want to install them?", default="no")

        if install_deps:
            dependencies.install_packages(missing_deps)
            logger.info("Dependencies installed. Please launch Faraday Server again.")
            sys.exit(0)
        else:
            logger.error("Dependencies not met. Please refer to the documentation in order to install them. [%s]",
                         ", ".join(missing_deps))
            sys.exit(1)

    logger.info("Dependencies met")
Ejemplo n.º 12
0
def ask_to_install(missing_packages):
    logger = get_logger(__name__)
    logger.warning("The following packages are not installed:")
    for package in missing_packages:
        logger.warning("%s" % package)
    res = query_yes_no("Do you want to install them?", default="no")
    if res:
        checker = DependencyChecker(server.config.REQUIREMENTS_FILE)
        checker.install_packages(missing_packages)
    return res
Ejemplo n.º 13
0
def ask_to_install(missing_packages):
    logger = get_logger(__name__)
    logger.warning("The following packages are not installed:")
    for package in missing_packages:
        logger.warning("%s" % package)
    res = query_yes_no("Do you want to install them?", default="no")
    if res:
        checker = DependencyChecker(server.config.REQUIREMENTS_FILE)
        checker.install_packages(missing_packages)
    return res
Ejemplo n.º 14
0
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
Ejemplo n.º 15
0
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
Ejemplo n.º 16
0
def checkVersion():
    try:
        f = open(FARADAY_VERSION_FILE)
        f_version = f.read().strip()
        if not args.update:
            if getInstanceConfiguration().getVersion() != None and getInstanceConfiguration().getVersion() != f_version:
                logger.warning("You have different version of Faraday since your last run.\nRun ./faraday.py --update to update configuration!")
                if query_yes_no('Do you want to close Faraday?', 'yes'):
                    sys.exit(-1)

        getInstanceConfiguration().setVersion(f_version)
        f.close()

    except Exception as e:
        getLogger("launcher").error("It seems that something's wrong with your version\nPlease contact customer support")
        sys.exit(-1)
Ejemplo n.º 17
0
def checkVersion():
    try:
        f = open(FARADAY_VERSION_FILE)
        f_version = f.read().strip()
        if not args.update:
            if getInstanceConfiguration().getVersion() is not None and getInstanceConfiguration().getVersion() != f_version:
                logger.warning("You have different version of Faraday since your last run.\nRun ./faraday.py --update to update configuration!")
                if query_yes_no('Do you want to close Faraday?', 'yes'):
                    sys.exit(-1)

        getInstanceConfiguration().setVersion(f_version)
        f.close()

    except Exception as e:
        getLogger("launcher").error(
            "It seems that something's wrong with your version\nPlease contact customer support")
        sys.exit(-1)
Ejemplo n.º 18
0
    def doUpdates(self):
        logger.info('Removing old pyc files')
        subprocess.call(['find', '.', '-name', '*.pyc', '-delete'])
        logger.info('Pulling latest Github Master copy')
        if query_yes_no('Proceed?', 'yes'):
            subprocess.call(['git', 'pull'])

        logger.info('Checking qt3 libs')
        QT().run()

        logger.info('Installing missing dependencies in pip')
        pip.main(['install', '-r', CONST_REQUIREMENTS_FILE, '--user'])

        logger.info('Upgrading DBs to latest version')
        DB().run() 

        logger.info('Upgrading DBs to latest version')
        CouchViews().run()
Ejemplo n.º 19
0
    def doUpdates(self):
        logger.info('Removing old pyc files')
        subprocess.call(['find', '.', '-name', '*.pyc', '-delete'])
        logger.info('Pulling latest Github Master copy')
        if query_yes_no('Proceed?', 'yes'):
            subprocess.call(['git', 'pull'])

        logger.info('Checking qt3 libs')
        QT().run()

        logger.info('Installing missing dependencies in pip')
        pip.main(['install', '-r', CONST_REQUIREMENTS_FILE, '--user'])

        # logger.info('Upgrading DBs to latest version')
        # DB().run()

        logger.info('Upgrading DBs to latest version')
        CouchViews().run()
Ejemplo n.º 20
0
def main(workspace='', args=None, parser=None):

    parser.add_argument('-y', '--yes', action="store_true")
    parsed_args = parser.parse_args(args)

    try:
        vulns = models.get_all_vulns(workspace)
    except ResourceDoesNotExist:
        print("Invalid workspace name: ", workspace)
        return 1, None

    if not parsed_args.yes:
        if not query_yes_no(
                "Are you sure you want to change the status to closed of all the vulns in workspace %s"
                % workspace,
                default='no'):
            return 1, None

    count = 0
    for vuln in vulns:
        old_status = vuln.status

        # Valid status
        if vuln.status != "closed":

            vuln.status = "closed"
            count += 1

            if vuln.class_signature == "Vulnerability":
                models.update_vuln(workspace, vuln)

            elif vuln.class_signature == "VulnerabilityWeb":
                models.update_vuln_web(workspace, vuln)

            print(vuln.name, ": Status changed from", old_status,
                  "to closed successfully")

    print("End of process:", count, "vulnerabilities changed to closed")
    return 0, None
Ejemplo n.º 21
0
def checkVersion():
    try:
        f = open(CONST_VERSION_FILE)
        f_version = f.read().strip()
        if not args.update:
            if getInstanceConfiguration().getVersion() != None and getInstanceConfiguration().getVersion() != f_version:
                logger.warning("You have different version of Faraday since your last run.\nRun ./faraday.py --update to update configuration!")
                if query_yes_no('Do you want to close Faraday?', 'yes'):
                    exit(-1)

        getInstanceConfiguration().setVersion(f_version)
        f.close()

        doc = {"ver": getInstanceConfiguration().getVersion()}

        if os.path.isfile(CONST_CONFIG):
            os.remove(CONST_CONFIG)
        with open(CONST_CONFIG, "w") as doc_file:
            json.dump(doc, doc_file)
    except Exception as e:
        getLogger("launcher").error("It seems that something's wrong with your version\nPlease contact customer support")
        exit(-1)