pangea-sdk 1.3.0__py3-none-any.whl → 1.5.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
pangea/services/intel.py CHANGED
@@ -9,26 +9,39 @@ from pangea.response import APIRequestModel, APIResponseModel, PangeaResponse, P
9
9
  from .base import ServiceBase
10
10
 
11
11
 
12
- class FileReputationRequest(APIRequestModel):
12
+ class IntelCommonRequest(APIRequestModel):
13
13
  """
14
- File reputation request data
14
+ Intel common request data
15
15
 
16
- file_hash (str): Hash of the file to be looked up
17
- hash_type (str): Type of hash, can be "sha256", "sha" or "md5"
18
- provider (str, optional): Provider of the reputation information. ("reversinglabs"). Default provider defined by the configuration.
16
+ provider (str, optional): Provider of the information. Default provider defined by the configuration.
19
17
  verbose (bool, optional): Echo back the parameters of the API in the response
20
18
  raw (bool, optional): Return additional details from the provider.
21
19
  """
22
20
 
23
- hash: str
24
- hash_type: str
25
21
  verbose: Optional[bool] = None
26
22
  raw: Optional[bool] = None
27
23
  provider: Optional[str] = None
28
24
 
29
25
 
30
- class FileLookupRequest(FileReputationRequest):
31
- pass
26
+ class IntelCommonResult(PangeaResponseResult):
27
+ """
28
+ Intel common result data
29
+ """
30
+
31
+ parameters: Optional[Dict] = None
32
+ raw_data: Optional[Dict] = None
33
+
34
+
35
+ class FileReputationRequest(APIRequestModel):
36
+ """
37
+ File reputation request data
38
+
39
+ file_hash (str): Hash of the file to be looked up
40
+ hash_type (str): Type of hash, can be "sha256", "sha" or "md5"
41
+ """
42
+
43
+ hash: str
44
+ hash_type: str
32
45
 
33
46
 
34
47
  class FileReputationData(APIResponseModel):
@@ -47,31 +60,23 @@ class FileReputationResult(PangeaResponseResult):
47
60
  """
48
61
 
49
62
  data: FileReputationData
50
- parameters: Optional[Dict] = None
51
- raw_data: Optional[Dict] = None
52
63
 
53
64
 
54
- class FileLookupResult(FileReputationResult):
55
- pass
56
-
57
-
58
- class IPRepurationRequest(APIRequestModel):
65
+ class IPCommonRequest(IntelCommonRequest):
59
66
  """
60
- IP reputation request data
61
-
67
+ IP common request data
62
68
  ip (str): IP address to search for reputation information
63
- provider (str, optional): Provider of the reputation information. ("reversinglabs"). Default provider defined by the configuration.
64
- verbose (bool, optional): Echo back the parameters of the API in the response
65
- raw (bool, optional): Return additional details from the provider.
66
69
  """
67
70
 
68
71
  ip: str
69
- verbose: Optional[bool] = None
70
- raw: Optional[bool] = None
71
- provider: Optional[str] = None
72
72
 
73
73
 
74
- class IPLookupRequest(IPRepurationRequest):
74
+ class IPRepurationRequest(IPCommonRequest):
75
+ """
76
+ IP reputation request data
77
+
78
+ """
79
+
75
80
  pass
76
81
 
77
82
 
@@ -87,35 +92,117 @@ class IPReputationData(APIResponseModel):
87
92
 
88
93
  class IPReputationResult(PangeaResponseResult):
89
94
  """
90
- IP lookup result
95
+ IP reputation result
91
96
  """
92
97
 
93
98
  data: IPReputationData
94
- parameters: Optional[Dict] = None
95
- raw_data: Optional[Dict] = None
96
99
 
97
100
 
98
- class IPLookupResult(IPReputationResult):
101
+ class IPGeolocateRequest(IPCommonRequest):
102
+ """
103
+ IP geolocate request data
104
+ """
105
+
99
106
  pass
100
107
 
101
108
 
102
- class DomainReputationRequest(APIRequestModel):
109
+ class IPGeolocateData(PangeaResponseResult):
110
+ """
111
+ IP geolocate data
103
112
  """
104
- Domain reputation request data
105
113
 
106
- domain (str): Domain address to search for reputation information
107
- provider (str, optional): Provider of the reputation information. ("domaintools"). Default provider defined by the configuration.
108
- verbose (bool, optional): Echo back the parameters of the API in the response
109
- raw (bool, optional): Return additional details from the provider.
114
+ country: str
115
+ city: str
116
+ latitude: float
117
+ longitude: float
118
+ postal_code: str
119
+ country_code: str
120
+
121
+
122
+ class IPGeolocateResult(IntelCommonResult):
123
+ """
124
+ IP geolocate result
125
+ """
126
+
127
+ data: IPGeolocateData
128
+
129
+
130
+ class IPDomainRequest(IPCommonRequest):
131
+ """
132
+ IP domain request data
133
+ """
134
+
135
+ pass
136
+
137
+
138
+ class IPDomainData(PangeaResponseResult):
139
+ domain_found: bool
140
+ domain: Optional[str] = None
141
+
142
+
143
+ class IPDomainResult(IntelCommonResult):
144
+ """
145
+ IP geolocate result
146
+ """
147
+
148
+ data: IPDomainData
149
+
150
+
151
+ class IPVPNRequest(IPCommonRequest):
152
+ """
153
+ IP VPN request data
154
+ """
155
+
156
+ pass
157
+
158
+
159
+ class IPVPNData(PangeaResponseResult):
160
+ is_vpn: bool
161
+
162
+
163
+ class IPVPNResult(IntelCommonResult):
164
+ """
165
+ IP geolocate result
166
+ """
167
+
168
+ data: IPVPNData
169
+
170
+
171
+ class IPProxyRequest(IPCommonRequest):
172
+ """
173
+ IP VPN request data
174
+ """
175
+
176
+ pass
177
+
178
+
179
+ class IPProxyData(PangeaResponseResult):
180
+ is_proxy: bool
181
+
182
+
183
+ class IPProxyResult(IntelCommonResult):
184
+ """
185
+ IP geolocate result
186
+ """
187
+
188
+ data: IPProxyData
189
+
190
+
191
+ class DomainCommonRequest(IntelCommonRequest):
192
+ """
193
+ Domain lookup request data
194
+
195
+ domain (str): Domain address to be analyzed
110
196
  """
111
197
 
112
198
  domain: str
113
- verbose: Optional[bool] = None
114
- raw: Optional[bool] = None
115
- provider: Optional[str] = None
116
199
 
117
200
 
118
- class DomainLookupRequest(DomainReputationRequest):
201
+ class DomainReputationRequest(DomainCommonRequest):
202
+ """
203
+ Domain reputation request data
204
+ """
205
+
119
206
  pass
120
207
 
121
208
 
@@ -135,31 +222,23 @@ class DomainReputationResult(PangeaResponseResult):
135
222
  """
136
223
 
137
224
  data: DomainReputationData
138
- parameters: Optional[Dict] = None
139
- raw_data: Optional[Dict] = None
140
-
141
-
142
- class DomainLookupResult(DomainReputationResult):
143
- pass
144
225
 
145
226
 
146
- class URLReputationRequest(APIRequestModel):
227
+ class URLCommonRequest(IntelCommonRequest):
147
228
  """
148
- URL reputation request data
229
+ URL common request data
149
230
 
150
- url (str): URL address to search for reputation information
151
- provider (str, optional): Provider of the reputation information. ("crowdstrike"). Default provider defined by the configuration.
152
- verbose (bool, optional): Echo back the parameters of the API in the response
153
- raw (bool, optional): Return additional details from the provider.
231
+ url (str): URL address to be analyzed
154
232
  """
155
233
 
156
234
  url: str
157
- verbose: Optional[bool] = None
158
- raw: Optional[bool] = None
159
- provider: Optional[str] = None
160
235
 
161
236
 
162
- class URLLookupRequest(URLReputationRequest):
237
+ class URLReputationRequest(URLCommonRequest):
238
+ """
239
+ URL reputation request data
240
+ """
241
+
163
242
  pass
164
243
 
165
244
 
@@ -173,18 +252,12 @@ class URLReputationData(APIResponseModel):
173
252
  verdict: str
174
253
 
175
254
 
176
- class URLReputationResult(PangeaResponseResult):
255
+ class URLReputationResult(IntelCommonResult):
177
256
  """
178
- URL lookup result
257
+ URL Reputation result
179
258
  """
180
259
 
181
260
  data: URLReputationData
182
- parameters: Optional[Dict] = None
183
- raw_data: Optional[Dict] = None
184
-
185
-
186
- class URLLookupResult(URLReputationResult):
187
- pass
188
261
 
189
262
 
190
263
  class FileIntel(ServiceBase):
@@ -222,9 +295,9 @@ class FileIntel(ServiceBase):
222
295
  provider: Optional[str] = None,
223
296
  verbose: Optional[bool] = None,
224
297
  raw: Optional[bool] = None,
225
- ) -> PangeaResponse[FileLookupResult]:
298
+ ) -> PangeaResponse[FileReputationResult]:
226
299
  """
227
- File reputation
300
+ Reputation check
228
301
 
229
302
  Retrieve hash-based file reputation from a provider, including an optional detailed report.
230
303
 
@@ -244,11 +317,10 @@ class FileIntel(ServiceBase):
244
317
 
245
318
  Examples:
246
319
  response = file_intel.lookup(hash="142b638c6a60b60c7f9928da4fb85a5a8e1422a9ffdc9ee49e17e56ccca9cf6e", hash_type="sha256", provider="reversinglabs")
247
-
248
320
  """
249
321
  input = FileReputationRequest(hash=hash, hash_type=hash_type, verbose=verbose, raw=raw, provider=provider)
250
322
  response = self.request.post("reputation", data=input.dict(exclude_none=True))
251
- response.result = FileLookupResult(**response.raw_result)
323
+ response.result = FileReputationResult(**response.raw_result)
252
324
  return response
253
325
 
254
326
  def hashReputation(
@@ -260,7 +332,7 @@ class FileIntel(ServiceBase):
260
332
  raw: Optional[bool] = None,
261
333
  ) -> PangeaResponse[FileReputationResult]:
262
334
  """
263
- File reputation
335
+ Reputation check
264
336
 
265
337
  Retrieve hash-based file reputation from a provider, including an optional detailed report.
266
338
 
@@ -294,9 +366,9 @@ class FileIntel(ServiceBase):
294
366
  provider: Optional[str] = None,
295
367
  verbose: Optional[bool] = None,
296
368
  raw: Optional[bool] = None,
297
- ) -> PangeaResponse[FileLookupResult]:
369
+ ) -> PangeaResponse[FileReputationResult]:
298
370
  """
299
- File reputation, from filepath
371
+ Reputation, from filepath
300
372
 
301
373
  Retrieve hash-based file reputation from a provider, including an optional detailed report.
302
374
 
@@ -322,7 +394,7 @@ class FileIntel(ServiceBase):
322
394
 
323
395
  input = FileReputationRequest(hash=hash, hash_type="sha256", verbose=verbose, raw=raw, provider=provider)
324
396
  response = self.request.post("reputation", data=input.dict(exclude_none=True))
325
- response.result = FileLookupResult(**response.raw_result)
397
+ response.result = FileReputationResult(**response.raw_result)
326
398
  return response
327
399
 
328
400
  def filepathReputation(
@@ -333,7 +405,7 @@ class FileIntel(ServiceBase):
333
405
  raw: Optional[bool] = None,
334
406
  ) -> PangeaResponse[FileReputationResult]:
335
407
  """
336
- File reputation, from filepath
408
+ Reputation, from filepath
337
409
 
338
410
  Retrieve hash-based file reputation from a provider, including an optional detailed report.
339
411
  This function take care of calculate filepath hash and make the request to service
@@ -394,9 +466,9 @@ class DomainIntel(ServiceBase):
394
466
  @pangea_deprecated(version="1.2.0", reason="Should use DomainIntel.reputation()")
395
467
  def lookup(
396
468
  self, domain: str, verbose: Optional[bool] = None, raw: Optional[bool] = None, provider: Optional[str] = None
397
- ) -> PangeaResponse[DomainLookupResult]:
469
+ ) -> PangeaResponse[DomainReputationResult]:
398
470
  """
399
- Domain reputation
471
+ Reputation check
400
472
 
401
473
  Retrieve reputation for a domain from a provider, including an optional detailed report.
402
474
 
@@ -418,14 +490,14 @@ class DomainIntel(ServiceBase):
418
490
  """
419
491
  input = DomainReputationRequest(domain=domain, verbose=verbose, provider=provider, raw=raw)
420
492
  response = self.request.post("reputation", data=input.dict(exclude_none=True))
421
- response.result = DomainLookupResult(**response.raw_result)
493
+ response.result = DomainReputationResult(**response.raw_result)
422
494
  return response
423
495
 
424
496
  def reputation(
425
497
  self, domain: str, verbose: Optional[bool] = None, raw: Optional[bool] = None, provider: Optional[str] = None
426
498
  ) -> PangeaResponse[DomainReputationResult]:
427
499
  """
428
- Domain reputation
500
+ Reputation check
429
501
 
430
502
  Retrieve reputation for a domain from a provider, including an optional detailed report.
431
503
 
@@ -483,7 +555,7 @@ class IpIntel(ServiceBase):
483
555
  self, ip: str, verbose: Optional[bool] = None, raw: Optional[bool] = None, provider: Optional[str] = None
484
556
  ) -> PangeaResponse[IPReputationResult]:
485
557
  """
486
- IP reputation
558
+ Reputation
487
559
 
488
560
  Retrieve a reputation score for an IP address from a provider, including an optional detailed report.
489
561
 
@@ -513,7 +585,7 @@ class IpIntel(ServiceBase):
513
585
  self, ip: str, verbose: Optional[bool] = None, raw: Optional[bool] = None, provider: Optional[str] = None
514
586
  ) -> PangeaResponse[IPReputationResult]:
515
587
  """
516
- IP reputation
588
+ Reputation
517
589
 
518
590
  Retrieve a reputation score for an IP address from a provider, including an optional detailed report.
519
591
 
@@ -538,6 +610,122 @@ class IpIntel(ServiceBase):
538
610
  response.result = IPReputationResult(**response.raw_result)
539
611
  return response
540
612
 
613
+ def geolocate(
614
+ self, ip: str, verbose: Optional[bool] = None, raw: Optional[bool] = None, provider: Optional[str] = None
615
+ ) -> PangeaResponse[IPGeolocateResult]:
616
+ """
617
+ Geolocate
618
+
619
+ Retrieve information about the location of an IP address.
620
+
621
+ Args:
622
+ ip (str): IP address to be geolocated
623
+ provider (str, optional): Use geolocation data from this provider ("digitalelement"). Default provider defined by the configuration.
624
+ verbose (bool, optional): Echo the API parameters in the response
625
+ raw (bool, optional): Include raw data from this provider
626
+
627
+ Raises:
628
+ PangeaAPIException: If an API Error happens
629
+
630
+ Returns:
631
+ A PangeaResponse where the IP information is in the
632
+ response.result field. Available response fields can be found in our [API documentation](/docs/api/ip-intel)
633
+
634
+ Examples:
635
+ response = ip_intel.geolocate(ip="93.231.182.110", provider="digitalelement")
636
+ """
637
+ input = IPGeolocateRequest(ip=ip, verbose=verbose, raw=raw, provider=provider)
638
+ response = self.request.post("geolocate", data=input.dict(exclude_none=True))
639
+ response.result = IPGeolocateResult(**response.raw_result)
640
+ return response
641
+
642
+ def get_domain(
643
+ self, ip: str, verbose: Optional[bool] = None, raw: Optional[bool] = None, provider: Optional[str] = None
644
+ ) -> PangeaResponse[IPDomainResult]:
645
+ """
646
+ Domain
647
+
648
+ Retrieve the domain name associated with an IP address.
649
+
650
+ Args:
651
+ ip (str): IP address to be geolocated
652
+ provider (str, optional): Use geolocation data from this provider ("digitalelement"). Default provider defined by the configuration.
653
+ verbose (bool, optional): Echo the API parameters in the response
654
+ raw (bool, optional): Include raw data from this provider
655
+
656
+ Raises:
657
+ PangeaAPIException: If an API Error happens
658
+
659
+ Returns:
660
+ A PangeaResponse where the IP information is in the
661
+ response.result field. Available response fields can be found in our [API documentation](/docs/api/ip-intel)
662
+
663
+ Examples:
664
+ response = ip_intel.get_domain(ip="93.231.182.110", provider="digitalelement")
665
+ """
666
+ input = IPDomainRequest(ip=ip, verbose=verbose, raw=raw, provider=provider)
667
+ response = self.request.post("domain", data=input.dict(exclude_none=True))
668
+ response.result = IPDomainResult(**response.raw_result)
669
+ return response
670
+
671
+ def is_vpn(
672
+ self, ip: str, verbose: Optional[bool] = None, raw: Optional[bool] = None, provider: Optional[str] = None
673
+ ) -> PangeaResponse[IPVPNResult]:
674
+ """
675
+ VPN
676
+
677
+ Determine if an IP address is provided by a VPN service.
678
+
679
+ Args:
680
+ ip (str): IP address to be geolocated
681
+ provider (str, optional): Use geolocation data from this provider ("digitalelement"). Default provider defined by the configuration.
682
+ verbose (bool, optional): Echo the API parameters in the response
683
+ raw (bool, optional): Include raw data from this provider
684
+
685
+ Raises:
686
+ PangeaAPIException: If an API Error happens
687
+
688
+ Returns:
689
+ A PangeaResponse where the IP information is in the
690
+ response.result field. Available response fields can be found in our [API documentation](/docs/api/ip-intel)
691
+
692
+ Examples:
693
+ response = ip_intel.is_vpn(ip="93.231.182.110", provider="digitalelement")
694
+ """
695
+ input = IPVPNRequest(ip=ip, verbose=verbose, raw=raw, provider=provider)
696
+ response = self.request.post("vpn", data=input.dict(exclude_none=True))
697
+ response.result = IPVPNResult(**response.raw_result)
698
+ return response
699
+
700
+ def is_proxy(
701
+ self, ip: str, verbose: Optional[bool] = None, raw: Optional[bool] = None, provider: Optional[str] = None
702
+ ) -> PangeaResponse[IPProxyResult]:
703
+ """
704
+ Proxy
705
+
706
+ Determine if an IP address is provided by a proxy service.
707
+
708
+ Args:
709
+ ip (str): IP address to be geolocated
710
+ provider (str, optional): Use geolocation data from this provider ("digitalelement"). Default provider defined by the configuration.
711
+ verbose (bool, optional): Echo the API parameters in the response
712
+ raw (bool, optional): Include raw data from this provider
713
+
714
+ Raises:
715
+ PangeaAPIException: If an API Error happens
716
+
717
+ Returns:
718
+ A PangeaResponse where the IP information is in the
719
+ response.result field. Available response fields can be found in our [API documentation](/docs/api/ip-intel)
720
+
721
+ Examples:
722
+ response = ip_intel.is_proxy(ip="93.231.182.110", provider="digitalelement")
723
+ """
724
+ input = IPProxyRequest(ip=ip, verbose=verbose, raw=raw, provider=provider)
725
+ response = self.request.post("proxy", data=input.dict(exclude_none=True))
726
+ response.result = IPProxyResult(**response.raw_result)
727
+ return response
728
+
541
729
 
542
730
  class UrlIntel(ServiceBase):
543
731
  """URL Intel service client.
@@ -569,9 +757,9 @@ class UrlIntel(ServiceBase):
569
757
  @pangea_deprecated(version="1.2.0", reason="Should use UrlIntel.reputation()")
570
758
  def lookup(
571
759
  self, url: str, verbose: Optional[bool] = None, raw: Optional[bool] = None, provider: Optional[str] = None
572
- ) -> PangeaResponse[URLLookupResult]:
760
+ ) -> PangeaResponse[URLReputationResult]:
573
761
  """
574
- URL reputation
762
+ Reputation check
575
763
 
576
764
  Retrieve URL address reputation from a provider.
577
765
 
@@ -594,14 +782,14 @@ class UrlIntel(ServiceBase):
594
782
 
595
783
  input = URLReputationRequest(url=url, provider=provider, verbose=verbose, raw=raw)
596
784
  response = self.request.post("reputation", data=input.dict(exclude_none=True))
597
- response.result = URLLookupResult(**response.raw_result)
785
+ response.result = URLReputationResult(**response.raw_result)
598
786
  return response
599
787
 
600
788
  def reputation(
601
789
  self, url: str, verbose: Optional[bool] = None, raw: Optional[bool] = None, provider: Optional[str] = None
602
790
  ) -> PangeaResponse[URLReputationResult]:
603
791
  """
604
- URL reputation
792
+ Reputation check
605
793
 
606
794
  Retrieve URL address reputation from a provider.
607
795
 
@@ -0,0 +1,67 @@
1
+ # Copyright 2022 Pangea Cyber Corporation
2
+ # Author: Pangea Cyber Corporation
3
+ from typing import Optional
4
+
5
+ from pangea.response import APIRequestModel, PangeaResponseResult
6
+ from pangea.services.vault.models.common import (
7
+ AsymmetricAlgorithm,
8
+ CommonGenerateRequest,
9
+ CommonGenerateResult,
10
+ CommonStoreRequest,
11
+ CommonStoreResult,
12
+ EncodedPrivateKey,
13
+ EncodedPublicKey,
14
+ KeyPurpose,
15
+ )
16
+
17
+
18
+ class AsymmetricGenerateRequest(CommonGenerateRequest):
19
+ algorithm: AsymmetricAlgorithm
20
+ purpose: KeyPurpose
21
+
22
+
23
+ class AsymmetricGenerateResult(CommonGenerateResult):
24
+ algorithm: str
25
+ purpose: str
26
+ public_key: EncodedPublicKey
27
+
28
+
29
+ class AsymmetricStoreRequest(CommonStoreRequest):
30
+ algorithm: AsymmetricAlgorithm
31
+ public_key: EncodedPublicKey
32
+ private_key: EncodedPrivateKey
33
+ purpose: KeyPurpose
34
+
35
+
36
+ class AsymmetricStoreResult(CommonStoreResult):
37
+ algorithm: str
38
+ purpose: str
39
+ public_key: EncodedPublicKey
40
+
41
+
42
+ class SignRequest(APIRequestModel):
43
+ id: str
44
+ message: str
45
+ version: Optional[int] = None
46
+
47
+
48
+ class SignResult(PangeaResponseResult):
49
+ id: str
50
+ version: int
51
+ algorithm: str
52
+ signature: str
53
+ public_key: Optional[EncodedPublicKey] = None
54
+
55
+
56
+ class VerifyRequest(APIRequestModel):
57
+ id: str
58
+ message: str
59
+ signature: str
60
+ version: Optional[int] = None
61
+
62
+
63
+ class VerifyResult(PangeaResponseResult):
64
+ id: str
65
+ version: int
66
+ algorithm: str
67
+ valid_signature: bool