Example #1
0
    def test_no_output_when_error_display_false(self):
        with patch('sys.stdout', new=io.BytesIO()) as fake_out:
            jo = JsonOutput()
            jo.warn("""Things have not gone according to plan. Please exit the
                    building in an orderly fashion.""")

            val = fake_out.getvalue()

        assert val == b""
Example #2
0
    def test_no_output_when_error_display_false(self):
        with patch('sys.stdout', new=io.BytesIO()) as fake_out:
            jo = JsonOutput()
            jo.warn("""Things have not gone according to plan. Please exit the
                    building in an orderly fashion.""")

            val = fake_out.getvalue()

        assert val == b""
Example #3
0
    def test_log_output_when_error_display_false(self):

        warn_string = 'warn_string'
        error_file = '/tmp/a'

        with patch('sys.stdout', new=io.StringIO()) as fake_out:
            jo = JsonOutput(error_log=error_file)
            jo.error_log = io.StringIO()
            jo.warn(warn_string)

            file_output = jo.error_log.getvalue()
            standard_out = fake_out.getvalue()

        assert standard_out == ""
        assert warn_string in file_output
Example #4
0
    def test_log_output_when_error_display_false(self):

        warn_string = 'warn_string'
        error_file = '/tmp/a'

        with patch('sys.stdout', new=io.StringIO()) as fake_out:
            jo = JsonOutput(error_log=error_file)
            jo.error_log = io.StringIO()
            jo.warn(warn_string)

            file_output = jo.error_log.getvalue()
            standard_out = fake_out.getvalue()

        assert standard_out == ""
        assert warn_string in file_output
Example #5
0
    def plugin_init(self):
        time_start = datetime.now()
        opts = self._options()

        if opts['output'] == 'json' or 'url_file' in opts:
            output = JsonOutput(error_log=opts['error_log'])
        else:
            output = StandardOutput(error_log=opts['error_log'])

        debug_requests = opts['debug_requests']
        self._general_init(output=output, debug_requests=debug_requests)

        hide_progressbar = True if debug_requests else False
        if debug_requests:
            opts['threads'] = 1

        functionality = self._functionality(opts)
        enabled_functionality = self._enabled_functionality(functionality, opts)
        if 'url_file' in opts:
            with open(opts['url_file']) as url_file:
                timeout_host = opts['timeout_host']
                i = 0
                with ThreadPoolExecutor(max_workers=opts['threads']) as executor:
                    results = []
                    for url in url_file:
                        args = [url, opts, functionality, enabled_functionality,
                                True]

                        future = executor.submit(self.url_scan, *args)

                        results.append({
                            'future': future,
                            'url': url.rstrip('\n'),
                        })

                        if i % 1000 == 0:
                            self._process_results_multisite(results,
                                    functionality, timeout_host)
                            results = []

                        i += 1

                    if len(results) > 0:
                        self._process_results_multisite(results, functionality,
                                timeout_host)
                        results = []

        else:
            output = self.url_scan(opts['url'], opts, functionality,
                    enabled_functionality, hide_progressbar=hide_progressbar)

            self.out.result(output, functionality)

        self.out.echo('\033[95m[+] Scan finished (%s elapsed)\033[0m' %
                str(datetime.now() - time_start))
        self.out.close()
Example #6
0
    def plugin_init(self):
        time_start = datetime.now()
        opts = self._options()

        if opts['output'] == 'json':
            output = JsonOutput()
        else:
            output = StandardOutput()

        self._general_init(output=output)

        functionality = self._functionality(opts)
        enabled_functionality = self._enabled_functionality(
            functionality, opts)

        if 'url_file' in opts:
            with open(opts['url_file']) as url_file:
                with ThreadPoolExecutor(
                        max_workers=opts['threads']) as executor:
                    results = []
                    for url in url_file:
                        args = [
                            url, opts, functionality, enabled_functionality
                        ]

                        future = executor.submit(self.url_scan, *args)

                        results.append({
                            'future': future,
                            'url': url.rstrip('\n'),
                        })

                    for result in results:
                        try:
                            output = result['future'].result()
                            output['host'] = result['url']
                            self.out.result(output, functionality)
                        except:
                            exc = traceback.format_exc()
                            self.out.warn(exc)

        else:
            output = self.url_scan(opts['url'], opts, functionality,
                                   enabled_functionality)

            self.out.result(output, functionality)

        self.out.echo('\033[95m[+] Scan finished (%s elapsed)\033[0m' %
                      str(datetime.now() - time_start))
Example #7
0
    def test_no_output_when_error_display_false(self, mock_print):
        jo = JsonOutput()
        jo.warn("""Things have not gone according to plan. Please exit the
                building in an orderly fashion.""")

        assert mock_print.called == False
Example #8
0
    def test_no_output_when_error_display_false(self, mock_print):
        jo = JsonOutput()
        jo.warn("""Things have not gone according to plan. Please exit the
                building in an orderly fashion.""")

        assert mock_print.called == False
Example #9
0
    def test_output_defaults(self):
        jo = JsonOutput()
        so = StandardOutput()

        assert jo.errors_display == False
        assert so.errors_display == True
Example #10
0
    def test_can_choose_output(self):
        output = JsonOutput()
        self.scanner._general_init(output=output)

        assert isinstance(self.scanner.out, JsonOutput)