コード例 #1
0
ファイル: cape_sandbox.py プロジェクト: TIA568B/IntelOwl
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.Session.get",
                 return_value=MockResponse(
                     {
                         "error": False,
                         "data": "completed"
                     }, 200),
             ),
             patch(
                 "requests.Session.post",
                 return_value=MockResponse(
                     {
                         "error": False,
                         "data": {
                             "task_ids": [1234],
                         },
                         "errors": [],
                         "url": ["http://fake_url.com/submit/status/1234/"],
                     },
                     200,
                 ),
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #2
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.Session.get",
                 return_value=MockResponse(
                     {
                         "tasks": {
                             "task_1": {},
                             "task_2": {}
                         },
                         "data": []
                     }, 200),
             ),
             patch(
                 "requests.Session.post",
                 return_value=MockResponse(
                     {
                         "id": "sample_id",
                         "status": "pending"
                     }, 200),
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #3
0
 def _monkeypatch(self, patches: list = None):
     """
     Here, `_monkeypatch` is an instance method and not a class method.
     This is because when defined with `@classmethod`, we were getting the error
     ```
     '_patch' object has no attribute 'is_local'
     ```
     whenever multiple analyzers with same parent class were being called.
     """
     if patches is None:
         patches = []
     # no need to sleep during tests
     self.poll_distance = 0
     patches.append(
         if_mock_connections(
             patch(
                 "requests.get",
                 side_effect=mocked_docker_analyzer_get,
             ),
             patch(
                 "requests.post",
                 side_effect=mocked_docker_analyzer_post,
             ),
         )
     )
     for mock_fn in patches:
         self.start = mock_fn(self.start)
コード例 #4
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 side_effect=[
                     MockResponse(
                         {},
                         404),  # 404 so `__submit_for_analysis` is called
                     MockResponse(
                         {
                             "status": "done",
                             "data": {
                                 "test": "test"
                             }
                         }, 200),
                 ],
             ),
             patch(
                 "requests.post",
                 side_effect=lambda *args, **kwargs: MockResponse(
                     {"qid": 1}, 200),
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #5
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.Session.post",
                 return_value=MockResponse({"api": "test"}, 200),
             ),
             patch("requests.Session.get", return_value=MockResponse({}, 200)),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #6
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 side_effect=[
                     # for _vt_get_report
                     MockResponse(
                         {
                             "data": {
                                 "attributes": {
                                     "status": "completed",
                                     "last_analysis_results": {
                                         "test": "test"
                                     },
                                     # must be earlier than 30 days ago
                                     "last_analysis_date": 1590000000,
                                 }
                             }
                         },
                         200,
                     ),
                     # for _vt_scan_file
                     MockResponse(
                         {
                             "data": {
                                 "attributes": {
                                     "status": "completed",
                                 }
                             }
                         },
                         200,
                     ),
                     # for /behaviour_summary
                     MockResponse({}, 200),
                     # for /sigma_analyses
                     MockResponse({}, 200),
                 ],
             ),
             patch(
                 "requests.post",
                 # for _vt_scan_file
                 return_value=MockResponse(
                     {
                         "scan_id": "scan_id_test",
                         "data": {
                             "id": "id_test"
                         }
                     }, 200),
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #7
0
ファイル: intelx.py プロジェクト: 0x0elliot/IntelOwl
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.Session.post",
                 return_value=MockResponse({"id": 1}, 200),
             ),
             patch(
                 "requests.Session.get",
                 return_value=MockResponse({"selectors": []}, 200),
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #8
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse({"allFinished": True}, 200),
             ),
             patch(
                 "requests.post",
                 return_value=MockResponse({"flow_id": 1}, 200),
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #9
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.Session.get",
                 return_value=MockResponse({"task": {
                     "status": "reported"
                 }}, 200),
             ),
             patch(
                 "requests.Session.post",
                 return_value=MockResponse({}, 200),
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #10
0
    def _monkeypatch(cls):
        mock_obs = [{
            "id": 1,
            "observable_value": "8.8.8.8",
            "objectMarkingIds": []
        }]
        mock_report = [{"id": 1, "observable_value": "8.8.8.8", "objects": []}]

        patches = [
            if_mock_connections(
                patch("pycti.OpenCTIApiClient", return_value=None),
                patch("pycti.StixCyberObservable.list", return_value=mock_obs),
                patch("pycti.Report.list", return_value=mock_report),
            )
        ]
        return super()._monkeypatch(patches=patches)
コード例 #11
0
ファイル: misp.py プロジェクト: intelowlproject/IntelOwl
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch("pymisp.PyMISP", return_value=MockResponseNoOp({}, 200)),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #12
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "mwdblib.MWDB",
                 side_effect=mocked_mwdb_response,
             ), )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #13
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse(
                     {"data": {"attributes": {"status": "completed"}}}, 200
                 ),
             ),
             patch(
                 "requests.post",
                 return_value=MockResponse(
                     {"scan_id": "scan_id_test", "data": {"id": "id_test"}}, 200
                 ),
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #14
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "pyhashlookup.Hashlookup", return_value=MockResponseNoOp({}, 200)
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #15
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "api_app.analyzers_manager.observable_analyzers.dns."
                 "dns_malicious_detectors.google_webrisk.WebRiskServiceClient"
             ))
     ]
     return super()._monkeypatch(patches=patches)
コード例 #16
0
ファイル: misp.py プロジェクト: TIA568B/IntelOwl
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "pymisp.PyMISP",
                 side_effect=MockPyMISP,
             ))
     ]
     return super()._monkeypatch(patches=patches)
コード例 #17
0
ファイル: xforce.py プロジェクト: 0x0elliot/IntelOwl
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse({}, 200),
             ), )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #18
0
ファイル: unpac_me.py プロジェクト: intelowlproject/IntelOwl
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse(
                     {
                         "id": "test",
                         "status": "complete"
                     }, 200),
             ),
             patch(
                 "requests.post",
                 return_value=MockResponse({"id": "test"}, 200),
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #19
0
ファイル: dehashed.py プロジェクト: TIA568B/IntelOwl
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse({"entries": [{"id": "test"}]}, 200),
             )
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #20
0
ファイル: robtex.py プロジェクト: intelowlproject/IntelOwl
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse(
                     {}, 200,
                     text='{"test1":"test1"}\r\n{"test2":"test2"}'),
             ), )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #21
0
ファイル: mwdb_scan.py プロジェクト: intelowlproject/IntelOwl
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "mwdblib.MWDB",
                 side_effect=mocked_mwdb_response,
             ),
             patch.object(cls, "file_analysis", return_value=True),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #22
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse(
                     {}, 200, content="Category: Test Fortiguard"
                 ),
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #23
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse(
                     {"Answer": [{
                         "data": "0.0.0.0"
                     }]}, 200),
             ), )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #24
0
ファイル: abuseipdb.py プロジェクト: intelowlproject/IntelOwl
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse(
                     {"data": {"reports": [{"categories": [1, 2]}]}}, 200
                 ),
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #25
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.post",
                 return_value=MockResponse(
                     {"data": [{
                         "sha256_hash": "test"
                     }]}, 200),
             ), )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #26
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "darksearch.Client.search",
                 return_value=[{
                     "total": 1,
                     "last_page": 0,
                     "data": ["test"]
                 }],
             ))
     ]
     return super()._monkeypatch(patches=patches)
コード例 #27
0
ファイル: virushee.py プロジェクト: intelowlproject/IntelOwl
 def _monkeypatch(cls):
     cls.poll_distance = 0  # for tests
     patches = [
         if_mock_connections(
             patch(
                 "requests.Session.get",
                 return_value=MockResponse({"message": "hash_not_found"}, 404),
             ),
             patch(
                 "requests.Session.post",
                 return_value=MockResponse({"task": "123-456-789"}, 201),
             ),
             patch(
                 "requests.Session.get",
                 return_value=MockResponse({"message": "analysis_in_progress"}, 202),
             ),
             patch(
                 "requests.Session.get",
                 return_value=MockResponse({"result": "test"}, 200),
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #28
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.post",
                 return_value=MockResponse(
                     [{
                         "job_id": "1",
                         "sha256": "abcdefgh",
                     }],
                     200,
                 ),
             ), )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #29
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse(
                     json_data={},
                     status_code=200,
                     text="""0.0.0.0/8\n
                             1.10.16.0/20\n
                             1.19.0.0/16\n
                             3.90.198.217\n""",
                 ),
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
コード例 #30
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse(
                     {
                         "items": [],
                         "count": 0,
                         "count_search_params": 1,
                         "method": "and",
                     },
                     200,
                 ),
             ), )
     ]
     return super()._monkeypatch(patches=patches)