Пример #1
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)
Пример #2
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)
Пример #3
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)
Пример #4
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)
Пример #5
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)
Пример #6
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)
Пример #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)
Пример #8
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)
Пример #9
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)
Пример #10
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse({}, 200),
             ), )
     ]
     return super()._monkeypatch(patches=patches)
Пример #11
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)
Пример #12
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse({"entries": [{"id": "test"}]}, 200),
             )
         )
     ]
     return super()._monkeypatch(patches=patches)
Пример #13
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)
Пример #14
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse(
                     {}, 200, content="Category: Test Fortiguard"
                 ),
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
Пример #15
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)
Пример #16
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)
Пример #17
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.post",
                 return_value=MockResponse(
                     {"data": [{
                         "sha256_hash": "test"
                     }]}, 200),
             ), )
     ]
     return super()._monkeypatch(patches=patches)
Пример #18
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)
Пример #19
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)
Пример #20
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)
Пример #21
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)
Пример #22
0
 def _monkeypatch(cls):
     patches = [
         if_mock_connections(
             patch(
                 "requests.get",
                 return_value=MockResponse(
                     json_data={},
                     status_code=200,
                     text='{"cond":"begin"}\n'
                     '{"obj":{"count":1,"zone_time_first":1349367341,'
                     '"zone_time_last":1440606099,"rrname":"mocked.data.net.",'
                     '"rrtype":"A","bailiwick":"net.",'
                     '"rdata":"0.0.0.0"}}\n'
                     '{"cond":"limited","msg":"Result limit reached"}\n',
                 ),
             ),
         )
     ]
     return super()._monkeypatch(patches=patches)
Пример #23
0
 def _monkeypatch(cls):
     cls.max_tries = 0  # for test
     cls.poll_distance = 0  # for test
     patches = [
         if_mock_connections(
             patch(
                 "requests.Session.request",
                 side_effect=[
                     MockResponse({
                         "id": 1,
                         "malware_type": "PE"
                     }, 201),  # __upload; sample ID
                     MockResponse({"id": 1}, 201),  # __upload; analysis ID
                     MockResponse(
                         {
                             "id":
                             1,
                             "created_at":
                             "2022-01-17T12:07:55.446274Z",
                             "status":
                             "ANALYZED",
                             "evaluation":
                             "MALICIOUS",
                             "weight":
                             120,
                             "malware_families": ["Ransomware", "Trojan"],
                             "mitre_techniques": [{
                                 "tid":
                                 "tactic_tid",
                                 "name":
                                 "test_tactic",
                                 "techniques": [{
                                     "tid": "technique_tid",
                                     "name": "test_technique",
                                 }],
                             }],
                             "sample": {
                                 "id": 1,
                                 "filename": "test"
                             },
                             "reports": [
                                 {
                                     "id": 1,
                                     "error": "Internal error",
                                     "profile": {
                                         "id": 1,
                                         "filename": "test.ql"
                                     },
                                 },
                             ],
                             "gui_url":
                             "dragonfly.certego.net/analysis/1",
                             "api_url":
                             "dragonfly.certego.net/api/analysis/1",
                         },
                         200,
                     ),  # __poll_and_fetch_result; Analysis.retrieve
                     MockResponse(
                         [{
                             "id": 1,
                             "rule": "testrule",
                             "weight": 0,
                             "matches": []
                         }],
                         200,
                     ),  # __poll_and_fetch_result; Report.matched_rules
                 ],
             ))
     ]
     return super()._monkeypatch(patches=patches)