Beispiel #1
0
 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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #7
0
 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)
Beispiel #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)
 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)
Beispiel #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)
Beispiel #11
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch("pymisp.PyMISP", return_value=MockResponseNoOp({}, 200)),
         )
     ]
     return super()._monkeypatch(patches=patches)
Beispiel #12
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "mwdblib.MWDB",
                 side_effect=mocked_mwdb_response,
             ), )
     ]
     return super()._monkeypatch(patches=patches)
Beispiel #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)
Beispiel #14
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "pyhashlookup.Hashlookup", return_value=MockResponseNoOp({}, 200)
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
 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)
Beispiel #16
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "pymisp.PyMISP",
                 side_effect=MockPyMISP,
             ))
     ]
     return super()._monkeypatch(patches=patches)
Beispiel #17
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse({}, 200),
             ), )
     ]
     return super()._monkeypatch(patches=patches)
Beispiel #18
0
 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)
Beispiel #19
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse({"entries": [{"id": "test"}]}, 200),
             )
         )
     ]
     return super()._monkeypatch(patches=patches)
Beispiel #20
0
 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)
Beispiel #21
0
 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)
Beispiel #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)
Beispiel #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)
Beispiel #24
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse(
                     {"data": {"reports": [{"categories": [1, 2]}]}}, 200
                 ),
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
Beispiel #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)
Beispiel #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)
Beispiel #27
0
 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)
Beispiel #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)
Beispiel #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)
 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)