def test_send_analysis_by_file_with_disable_unpacking(self):
        # Arrange
        with responses.RequestsMock() as mock:
            mock.add('POST',
                     url=self.full_url + '/analyze',
                     status=201,
                     json={'result_url': 'a/sd/asd'})
            mock.add('GET',
                     url=self.full_url + '/analyses/asd',
                     status=200,
                     json={'result': 'report'})
            analysis = Analysis(file_path='a',
                                disable_dynamic_unpacking=True,
                                disable_static_unpacking=True)
            with patch(self.patch_prop, mock_open(read_data='data')):
                # Act
                analysis.send(wait=True)

            # Assert
            self.assertEqual(analysis.status, consts.AnalysisStatusCode.FINISH)
            self.assertEqual(analysis.result(), 'report')
            request_body = mock.calls[0].request.body.decode()
            self.assertTrue(
                'Content-Disposition: form-data; name="disable_static_extraction"\r\n\r\nTrue'
                in request_body)
            self.assertTrue(
                'Content-Disposition: form-data; name="disable_dynamic_execution"\r\n\r\nTrue'
                in request_body)
Exemple #2
0
def send_file_with_wait(
        file_path,
        dynamic_unpacking=None,
        static_unpacking=None):  # type: (str, bool, bool) -> None
    api.set_global_api('<api_key>')
    analysis = Analysis(file_path=file_path,
                        dynamic_unpacking=dynamic_unpacking,
                        static_unpacking=static_unpacking)
    analysis.send(wait=True)
    pprint(analysis.result())
Exemple #3
0
def send_file_without_wait(
        file_path, dynamic_unpacking,
        static_unpacking):  # type: (str, bool, bool) -> None
    api.set_global_api('<api_key>')
    analysis = Analysis(file_path=file_path,
                        dynamic_unpacking=dynamic_unpacking,
                        static_unpacking=static_unpacking)
    analysis.send()
    analysis.wait_for_completion()
    pprint(analysis.result())
    def test_send_analysis_by_file_and_get_report(self):
        # Arrange
        with responses.RequestsMock() as mock:
            mock.add('POST',
                     url=self.full_url + '/analyze',
                     status=201,
                     json={'result_url': 'a/sd/asd'})
            mock.add('GET',
                     url=self.full_url + '/analyses/asd',
                     status=200,
                     json={'result': 'report'})
            analysis = Analysis(file_path='a')
            with patch(self.patch_prop, mock_open(read_data='data')):
                # Act
                analysis.send(wait=True)

        # Assert
        self.assertEqual(analysis.status, consts.AnalysisStatusCode.FINISH)
        self.assertEqual(analysis.result(), 'report')
Exemple #5
0
def intezer_upload():
    if not len(config.INTEZER_APIKEY):
        return jsonify({"error": "NO API KEY"}), 200

    path = request.args.get('path', '')

    if not os.path.isfile(path):
        return jsonify({"error": "%s is not a valid file or the system could not access it" % path}), 200

    try:
        api.set_global_api(config.INTEZER_APIKEY)
        analysis = Analysis(file_path=path,
                            dynamic_unpacking=None,
                            static_unpacking=None)

        analysis.send(True)
    except errors.IntezerError as e:
        return jsonify({"error": "Error occurred: " + e.args[0]}), 200

    return jsonify(analysis.result()), 200
Exemple #6
0
    def run(self):
        result = {}

        try:
            intezer_sdk.consts.USER_AGENT = "IntelOwl"
            # run analysis
            analysis = Analysis(file_hash=self.observable_name)
            analysis.send(wait=False)
            analysis.wait_for_completion(
                interval=self.poll_interval,
                sleep_before_first_check=True,
                timeout=timedelta(seconds=self.timeout),
            )
            result.update(analysis.result(), hash_found=True)
        except (intezer_errors.HashDoesNotExistError,
                intezer_errors.InsufficientQuota):
            result.update(hash_found=False)
        except intezer_errors.IntezerError as e:
            raise AnalyzerRunException(e)

        return result
 def test_analysis_get_report_for_not_finish_analyze_raise_error(self):
     # Arrange
     analysis = Analysis(file_hash='a')
     # Act + Assert
     with self.assertRaises(errors.ReportDoesNotExistError):
         analysis.result()
Exemple #8
0
def analysis_by_hash_with_wait(file_hash):  # type: (str) -> None
    api.set_global_api('<api_key>')
    analysis = Analysis(file_hash=file_hash)
    analysis.send(wait=True)
    pprint(analysis.result())
Exemple #9
0
def analysis_by_hash_without_wait(file_hash):  # type: (str) -> None
    api.set_global_api('<api_key>')
    analysis = Analysis(file_hash=file_hash)
    analysis.send()
    analysis.wait_for_completion()
    pprint(analysis.result())