Exemple #1
0
    def default(self):
        """Default command"""
        host = None
        port = None

        # Check for hostname
        if self.app.pargs.host:
            host = self.app.pargs.host

        # Check for port
        if self.app.pargs.port:
            port = int(self.app.pargs.port)

        # Read SQLite data
        if self.app.pargs.filename:
            from smalisca.modules.module_sql_models import AppSQLModel

            # Read SQLite data
            appSQL = AppSQLModel(self.app.pargs.filename)
            log.info("Successfully opened SQLite DB")

            # Create API endpoints
            flask_app = create_flask_app()

            # Start web server
            log.info("Starting web application ...")
            web_server = WebServer(host, port, flask_app)
            web_server.create_blueprints(appSQL.get_session())
            web_server.run()
    def default(self):
        """Default command"""
        host = None
        port = None

        # Check for hostname
        if self.app.pargs.host:
            host = self.app.pargs.host

        # Check for port
        if self.app.pargs.port:
            port = int(self.app.pargs.port)

        # Read SQLite data
        if self.app.pargs.filename:
            from smalisca.modules.module_sql_models import AppSQLModel

            # Read SQLite data
            appSQL = AppSQLModel(self.app.pargs.filename)
            log.info("Successfully opened SQLite DB")

            # Create API endpoints
            flask_app = create_flask_app()

            # Start web server
            log.info("Starting web application ...")
            web_server = WebServer(host, port, flask_app)
            web_server.create_blueprints(appSQL.get_session())
            web_server.run()
Exemple #3
0
    def default(self):
        """Default command"""

        if (self.app.pargs.filename) and (self.app.pargs.fileformat):
            # Create new app
            app = App(__name__)

            # Analysis obj
            analysis = None

            # Check for config file
            if self.app.pargs.config_file:
                config.smalisca_conf.read(self.app.pargs.config_file)
            else:
                log.info("Using default conf (%s)" % config.PROJECT_CONF)
                config.smalisca_conf.read(config.PROJECT_CONF)

            config.smalisca_conf.parse()

            # Read SQLite data
            if self.app.pargs.fileformat == "sqlite":
                from smalisca.analysis.analysis_sqlite import AnalyzerSQLite
                from smalisca.modules.module_sql_models import AppSQLModel

                # Read SQLite data
                appSQL = AppSQLModel(self.app.pargs.filename)
                log.info("Successfully opened SQLite DB")

                # Create analysis framework
                log.info("Creating analyzer framework ...")
                analysis = AnalyzerSQLite(appSQL.get_session())

            # Where to read commands from?
            if self.app.pargs.commands_file:
                commands = open(self.app.pargs.commands_file, "rt")
                try:
                    log.info("Reading commands from %s" %
                             self.app.pargs.commands_file)
                    cmd_shell = AnalyzerShell(analysis)
                    cmd_shell.use_rawinput = False
                    cmd_shell.stdin = commands
                    cmd_shell.prompt = ''
                    cmd_shell.cmdloop()
                finally:
                    commands.close()
            else:
                # Start new shell
                log.info("Starting new analysis shell")
                cmd_shell = AnalyzerShell(analysis)
                cmd_shell.cmdloop()
Exemple #4
0
    def default(self):
        """Default command"""

        if (self.app.pargs.filename) and (self.app.pargs.fileformat):
            # Create new app
            app = App(__name__)

            # Analysis obj
            analysis = None

            # Check for config file
            if self.app.pargs.config_file:
                config.smalisca_conf.read(self.app.pargs.config_file)
            else:
                log.info("Using default conf (%s)" % config.PROJECT_CONF)
                config.smalisca_conf.read(config.PROJECT_CONF)

            config.smalisca_conf.parse()

            # Read SQLite data
            if self.app.pargs.fileformat == "sqlite":
                from smalisca.analysis.analysis_sqlite import AnalyzerSQLite
                from smalisca.modules.module_sql_models import AppSQLModel

                # Read SQLite data
                appSQL = AppSQLModel(self.app.pargs.filename)
                log.info("Successfully opened SQLite DB")

                # Create analysis framework
                log.info("Creating analyzer framework ...")
                analysis = AnalyzerSQLite(appSQL.get_session())

            # Where to read commands from?
            if self.app.pargs.commands_file:
                commands = open(self.app.pargs.commands_file, "rt")
                try:
                    log.info("Reading commands from %s" % self.app.pargs.commands_file)
                    cmd_shell = AnalyzerShell(analysis)
                    cmd_shell.use_rawinput = False
                    cmd_shell.stdin = commands
                    cmd_shell.prompt = ''
                    cmd_shell.cmdloop()
                finally:
                    commands.close()
            else:
                # Start new shell
                log.info("Starting new analysis shell")
                cmd_shell = AnalyzerShell(analysis)
                cmd_shell.cmdloop()
    def default(self):
        """Default command"""

        if self.app.pargs.location and self.app.pargs.suffix:
            self.location = self.app.pargs.location
            self.suffix = self.app.pargs.suffix

            # Create new parser
            parser = SmaliParser(self.location, self.suffix)
            parser.run()

            # Output results
            if (self.app.pargs.output) and (self.app.pargs.fileformat):
                results = parser.get_results()
                app = App(__name__)

                # Add additional info
                app.add_location(self.location)
                app.add_parser("%s - %s" %
                               (config.PROJECT_NAME, config.PROJECT_VERSION))

                # Append classes
                for c in results:
                    app.add_class_obj(c)

                # Write results to JSON
                if self.app.pargs.fileformat == 'json':
                    log.info("Exporting results to JSON")
                    app.write_json(self.app.pargs.output)
                    log.info("\tWrote results to %s" % self.app.pargs.output)

                # Write results to sqlite
                elif self.app.pargs.fileformat == 'sqlite':
                    appSQL = AppSQLModel(self.app.pargs.output)

                    try:
                        log.info("Exporting results to SQLite")
                        # Add classes
                        log.info("\tExtract classes ...")
                        for c in app.get_classes():
                            appSQL.add_class(c)

                        # Add properties
                        log.info("\tExtract class properties ...")
                        for p in app.get_properties():
                            appSQL.add_property(p)

                        # Add const-strings
                        log.info("\tExtract class const-strings ...")
                        for c in app.get_const_strings():
                            appSQL.add_const_string(c)

                        # Add methods
                        log.info("\tExtract class methods ...")
                        for m in app.get_methods():
                            appSQL.add_method(m)

                        # Add calls
                        log.info("\tExtract calls ...")
                        for c in app.get_calls():
                            appSQL.add_call(c)

                        # Commit changes
                        log.info("\tCommit changes to SQLite DB")
                        appSQL.commit()
                        log.info("\tWrote results to %s" %
                                 self.app.pargs.output)

                    finally:
                        log.info("Finished scanning")
    def default(self):
        """Default command"""

        if self.app.pargs.location and self.app.pargs.suffix:
            self.location = self.app.pargs.location
            self.suffix = self.app.pargs.suffix

            # How many jobs (workers)?
            if self.app.pargs.jobs and self.app.pargs.jobs > 0:
                self.jobs = self.app.pargs.jobs
            else:
                self.jobs = multiprocessing.cpu_count()

            # Walk location to which depth?
            if self.app.pargs.depth and self.app.pargs.depth > 0:
                self.depth = self.app.pargs.depth
            else:
                self.depth = 1

            # Create new concurrent parser instance
            concurrent_parser = ConcurrentParser(
                self.location, self.suffix,
                self.jobs, self.depth)
            concurrent_parser.walk_location()
            concurrent_parser.run()

            # Output results
            if (self.app.pargs.output) and (self.app.pargs.fileformat):
                results = concurrent_parser.get_results()
                app = App(__name__)

                # Add additional info
                app.add_location(self.location)
                app.add_parser("%s - %s" % (config.PROJECT_NAME, config.PROJECT_VERSION))

                # Append classes
                for c in results:
                    app.add_class_obj(c)

                # Write results to JSON
                if self.app.pargs.fileformat == 'json':
                    log.info("Exporting results to JSON")
                    app.write_json(self.app.pargs.output)
                    log.info("\tWrote results to %s" % self.app.pargs.output)

                # Write results to sqlite
                elif self.app.pargs.fileformat == 'sqlite':
                    appSQL = AppSQLModel(self.app.pargs.output)

                    try:
                        log.info("Exporting results to SQLite")
                        # Add classes
                        log.info("\tExtract classes ...")
                        for c in app.get_classes():
                            appSQL.add_class(c)

                        # Add properties
                        log.info("\tExtract class properties ...")
                        for p in app.get_properties():
                            appSQL.add_property(p)

                        # Add const-strings
                        log.info("\tExtract class const-strings ...")
                        for c in app.get_const_strings():
                            appSQL.add_const_string(c)

                        # Add methods
                        log.info("\tExtract class methods ...")
                        for m in app.get_methods():
                            appSQL.add_method(m)

                        # Add calls
                        log.info("\tExtract calls ...")
                        for c in app.get_calls():
                            appSQL.add_call(c)

                        # Commit changes
                        log.info("\tCommit changes to SQLite DB")
                        appSQL.commit()
                        log.info("\tWrote results to %s" % self.app.pargs.output)

                    finally:
                        log.info("Finished scanning")