コード例 #1
0
ファイル: Tool.py プロジェクト: u53r55/jok3r
    def createToolDirectory(self, output):
        """
		Create the tool reserved directory if necessary
		@Args		output: 	CLIOutput instance
		@Returns	Boolean indicating if dir was successfully created
		"""
        # if FileUtils.is_dir(self.tool_dir):
        # 	if not FileUtils.remove_directory(self.tool_dir):
        # 		output.printFail('Unable to delete directory \'{0}\'. Check permissions and/or re-run with sudo.'.format(self.tool_dir))
        # 	else:
        # 		output.printInfo('Directory \'{0}\' deleted'.format(self.tool_dir))
        if FileUtils.is_dir(self.tool_dir):
            output.printInfo('Directory \'{0}\' already exists'.format(
                self.tool_dir))
            return True

        try:
            FileUtils.create_directory(self.tool_dir)
        except Exception as e:
            output.printError(
                'Unable to create new directory \'{0}\': {1}.'.format(
                    self.tool_dir, e))
            return False
        output.printInfo('New directory \'{0}\' created'.format(self.tool_dir))
        return True
コード例 #2
0
ファイル: Tool.py プロジェクト: 5l1v3r1/jok3r-1
    def __create_tool_dir(self):
        """
        Create the tool directory if necessary.

        :return: Status
        :rtype: bool
        """
        if self.tool_dir:
            if FileUtils.is_dir(self.tool_dir):
                logger.info('Directory "{dir}" already exists'.format(
                    dir=self.tool_dir))
                return True

            try:
                FileUtils.create_directory(self.tool_dir)
            except Exception as e:
                logger.error(
                    'Unable to create new directory "{dir}": {exc}'.format(
                        dir=self.tool_dir, exc=e))
                return False
            logger.info(
                'New directory "{dir}" created'.format(dir=self.tool_dir))
            return True
        else:
            return False
コード例 #3
0
	def createToolDirectory(self, output):
		"""
		Create the tool directory if necessary

		@Args		output: 	CLIOutput instance
		@Returns	Boolean indicating operation status
		"""
		if FileUtils.is_dir(self.tool_dir):
			output.printInfo('Directory "{0}" already exists'.format(self.tool_dir))
			return True

		try:
			FileUtils.create_directory(self.tool_dir)
		except Exception as e:
			output.printError('Unable to create new directory "{0}": {1}'.format(self.tool_dir, e))
			return False
		output.printInfo('New directory "{0}" created'.format(self.tool_dir))
		return True
コード例 #4
0
    def runToolboxAgainstService(self):
        """
		Run the tools from the toolbox that target the service chosen by the user.
		Categories selection is taken into account.
		"""
        service = self.arguments.args.service
        for cat in self.arguments.selected_tools_categories:
            print
            self.output.printTitle0('Tools Category - {0}'.format(cat))
            if not self.settings.toolbox.tools[service][cat]:
                self.output.printInfo('No tool to run in this category')
                continue

            if not self.arguments.args.auto_yes:
                self.output.printPrompt('Run tools in this category ? [Y/n]')
                if not CLIUtils.promptYesNo(self.output, default='Y'):
                    self.output.printWarning('Category skipped.')
                    continue

            output_dir = FileUtils.concat_path(self.arguments.args.output_dir,
                                               cat)
            if not FileUtils.create_directory(output_dir):
                self.output.printFail(
                    'Impossible to create output subdir "{0}"'.format(subdir))
                sys.exit(0)
            self.output.printInfo(
                'Output subdir "{0}" created'.format(output_dir))
            for tool in self.settings.toolbox.tools[service][cat]:
                print
                self.output.printTitle1('   ' + tool.name)

                try:
                    tool.runTool(
                        self.settings,
                        self.output,
                        output_dir,
                        self.arguments.target,
                        self.arguments.specific,
                        ignore_specific=self.arguments.args.ignore_specific,
                        auto_yes=self.arguments.args.auto_yes)
                except KeyboardInterrupt, SystemExit:
                    print
                    self.output.printError('Tool execution aborted')
                print
コード例 #5
0
ファイル: ArgumentsParser.py プロジェクト: u53r55/jok3r
    def checkArgsOutput(self):
        """
		Check arguments related to Output
		"""
        if not self.contparsing or self.args.list_specific:
            return

        if self.args.output_dir:
            self.args.output_dir = self.args.output_dir.strip()
        else:
            self.args.output_dir = self.defineOutputDir(
                self.args.output_dir, self.target.host, self.target.port,
                self.target.protocol, self.target.service)

        if FileUtils.is_dir(self.args.output_dir):
            self.output.printError(
                'Directory "{0}" already exists. Choose another name.'.format(
                    self.args.output_dir))
            sys.exit(0)
        if not FileUtils.create_directory(self.args.output_dir):
            self.output.printError(
                'Impossible to create output directory "{0}". Check permissions'
                .format(self.args.output_dir))
            sys.exit(0)
コード例 #6
0
    def run(self):

        # Create report directory
        dirname = '{mission}-{datetime}'.format(
            mission=StringUtils.clean(self.mission.replace(' ', '_'),
                                      allowed_specials=('_', '-')),
            datetime=datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
        self.output_path = self.output_path + '/' + dirname

        if not FileUtils.create_directory(self.output_path):
            logger.error('Unable to create report directory: "{path}"'.format(
                path=self.output_path))
            return False

        # Retrieve all services in selected mission
        req = ServicesRequester(self.sqlsession)
        req.select_mission(self.mission)
        services = req.get_results()

        # Generate screenshots
        processor = ScreenshotsProcessor(self.mission, self.sqlsession)
        processor.run()

        screens_dir = self.output_path + '/screenshots'
        if not FileUtils.create_directory(screens_dir):
            logger.warning(
                'Unable to create screenshots directory: "{path}"'.format(
                    path=screens_dir))
        else:
            for service in services:
                if service.name == 'http' and service.screenshot is not None \
                        and service.screenshot.status == ScreenStatus.OK:

                    img_name = 'scren-{ip}-{port}-{id}'.format(
                        ip=str(service.host.ip),
                        port=service.port,
                        id=service.id)
                    path = screens_dir + '/' + img_name

                    ImageUtils.save_image(service.screenshot.image,
                                          path + '.png')
                    ImageUtils.save_image(service.screenshot.thumbnail,
                                          path + '.thumb.png')

        # Create index.html
        html = self.__generate_index()
        if FileUtils.write(self.output_path + '/index.html', html):
            logger.info('index.html file generated')
        else:
            logger.error('An error occured while generating index.html')
            return False

        # Create results-<service>.html (1 for each service)
        for service in services:
            # Useless to create page when no check has been run for the service
            if len(service.results) == 0:
                continue

            html = self.__generate_results_page(service)
            # Create a unique name for the service HTML file
            filename = 'results-{ip}-{port}-{service}-{id}.html'.format(
                ip=str(service.host.ip),
                port=service.port,
                service=service.name,
                id=service.id)
            if FileUtils.write(self.output_path + '/' + filename, html):
                logger.info(
                    '{filename} file generated'.format(filename=filename))
            else:
                logger.error(
                    'An error occured while generating {filename}'.format(
                        filename=filename))
                return False

        logger.success('HTML Report written with success in: {path}'.format(
            path=self.output_path))
        logger.info('Important: If running from Docker container, make sure to run ' \
            '"xhost +" on the host before')
        if Output.prompt_confirm('Would you like to open the report now ?',
                                 default=True):
            webbrowser.open(self.output_path + '/index.html')

        return True
コード例 #7
0
                output.printTitle0('Tools Category - {0}'.format(cat))
                if not self.settings.toolbox.tools[service][cat]:
                    output.printInfo('No tool to run in this category')
                    continue

                if not self.arguments.args.auto_yes:
                    output.printPrompt('Run tools in this category ? [Y/n]')
                    # Prompt
                    to_run = CLIUtils.promptYesNo(output, default='Y')
                    if not to_run:
                        output.printWarning('Category skipped.')
                        continue

                subdir = FileUtils.concat_path(self.arguments.args.output_dir,
                                               cat)
                if not FileUtils.create_directory(subdir):
                    output.printFail(
                        'Impossible to create output subdir "{0}"'.format(
                            subdir))
                    sys.exit(0)
                output.printInfo('Output subdir "{0}" created'.format(subdir))
                for tool in self.settings.toolbox.tools[service][cat]:
                    print
                    output.printTitle1('   ' + tool.name)

                    # Output for each tool is stored into a file
                    output_file = FileUtils.absolute_path(
                        FileUtils.concat_path(subdir, tool.name + '.txt'))
                    # Some tools (e.g. skipfish) required an output dir too
                    output_dir = FileUtils.absolute_path(
                        FileUtils.concat_path(subdir, tool.name))