assemblyline-v4-service 4.4.1.dev284__py3-none-any.whl → 4.4.1.dev290__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of assemblyline-v4-service might be problematic. Click here for more details.

@@ -1 +1 @@
1
- 4.4.1.dev284
1
+ 4.4.1.dev290
@@ -2,6 +2,7 @@ import os
2
2
  import time
3
3
 
4
4
  import requests
5
+ from assemblyline_core.badlist_client import BadlistClient
5
6
  from assemblyline_core.safelist_client import SafelistClient
6
7
  from assemblyline_v4_service.common.utils import DEVELOPMENT_MODE
7
8
 
@@ -58,6 +59,51 @@ class ServiceAPI:
58
59
  retries += 1
59
60
  time.sleep(min(2, 2 ** (retries - 7)))
60
61
 
62
+ def lookup_badlist_tags(self, tag_map: dict):
63
+ if DEVELOPMENT_MODE:
64
+ return []
65
+
66
+ if not isinstance(tag_map, dict) and not all([isinstance(x, list) for x in tag_map.values()]):
67
+ raise ValueError("Parameter tag_list should be a dictionary tag_type mapping to a list of tag_values.")
68
+ url = f"{self.service_api_host}/api/v1/badlist/tags/"
69
+
70
+ return self._with_retries(self.session.post, url, data=tag_map)
71
+
72
+ def lookup_badlist(self, qhash):
73
+ if DEVELOPMENT_MODE:
74
+ return None
75
+ try:
76
+ return self._with_retries(self.session.get, f"{self.service_api_host}/api/v1/badlist/{qhash}/")
77
+ except ServiceAPIError as e:
78
+ if e.status_code == 404:
79
+ return None
80
+ else:
81
+ raise
82
+
83
+ def lookup_badlist_ssdeep(self, ssdeep):
84
+ if DEVELOPMENT_MODE:
85
+ return []
86
+ try:
87
+ data = {"ssdeep": ssdeep}
88
+ return self._with_retries(self.session.post, f"{self.service_api_host}/api/v1/badlist/ssdeep/", data=data)
89
+ except ServiceAPIError as e:
90
+ if e.status_code == 404:
91
+ return None
92
+ else:
93
+ raise
94
+
95
+ def lookup_badlist_tlsh(self, tlsh):
96
+ if DEVELOPMENT_MODE:
97
+ return []
98
+ try:
99
+ data = {"tlsh": tlsh}
100
+ return self._with_retries(self.session.post, f"{self.service_api_host}/api/v1/badlist/tlsh/", data=data)
101
+ except ServiceAPIError as e:
102
+ if e.status_code == 404:
103
+ return None
104
+ else:
105
+ raise
106
+
61
107
  def get_safelist(self, tag_list=None):
62
108
  if DEVELOPMENT_MODE:
63
109
  return {}
@@ -86,8 +132,33 @@ class ServiceAPI:
86
132
  class PrivilegedServiceAPI:
87
133
  def __init__(self, logger):
88
134
  self.log = logger
135
+ self.badlist_client = BadlistClient()
89
136
  self.safelist_client = SafelistClient()
90
137
 
138
+ def lookup_badlist_tags(self, tag_map):
139
+ if DEVELOPMENT_MODE:
140
+ return []
141
+
142
+ if not isinstance(tag_map, dict) and not all([isinstance(x, list) for x in tag_map.values()]):
143
+ raise ValueError("Parameter tag_list should be a dictionary tag_type mapping to a list of tag_values.")
144
+
145
+ return self.badlist_client.exists_tags(tag_map)
146
+
147
+ def lookup_badlist(self, qhash):
148
+ if DEVELOPMENT_MODE:
149
+ return None
150
+ return self.badlist_client.exists(qhash)
151
+
152
+ def lookup_badlist_ssdeep(self, ssdeep):
153
+ if DEVELOPMENT_MODE:
154
+ return []
155
+ return self.badlist_client.find_similar_ssdeep(ssdeep)
156
+
157
+ def lookup_badlist_tlsh(self, tlsh):
158
+ if DEVELOPMENT_MODE:
159
+ return []
160
+ return self.badlist_client.find_similar_tlsh(tlsh)
161
+
91
162
  def get_safelist(self, tag_list=None):
92
163
  if DEVELOPMENT_MODE:
93
164
  return {}
@@ -69,7 +69,7 @@ class ServiceBase:
69
69
 
70
70
  self._working_directory = None
71
71
 
72
- # Initialize interface for interacting with system safelist
72
+ # Initialize interface for interacting with system badlist and safelist
73
73
  self._api_interface = None
74
74
 
75
75
  self.dependencies = self._get_dependencies_info()
@@ -261,7 +261,8 @@ class ServiceBase:
261
261
  resp = requests.get(url_base + 'status', verify=verify)
262
262
  resp.raise_for_status()
263
263
  status = resp.json()
264
- if self.update_time is not None and self.update_time >= status['local_update_time'] and self.update_hash == status['local_update_hash']:
264
+ if self.update_time is not None and self.update_time >= status['local_update_time'] and \
265
+ self.update_hash == status['local_update_hash']:
265
266
  self.log.info(f"There are no new signatures. ({self.update_time} >= {status['local_update_time']})")
266
267
  return
267
268
  if status['download_available']:
@@ -287,3 +287,11 @@ class ServiceRequest:
287
287
  @property
288
288
  def sid(self) -> str:
289
289
  return self.task.sid
290
+
291
+ @property
292
+ def ssdeep(self) -> str:
293
+ return self.task.fileinfo.ssdeep
294
+
295
+ @property
296
+ def tlsh(self) -> str:
297
+ return self.task.fileinfo.tlsh
@@ -424,7 +424,7 @@ class TableSectionBody(SectionBody):
424
424
  self._data.append(row)
425
425
  self.set_column_order(list(row.keys()))
426
426
 
427
- def set_column_order(self, order: List[str])-> None:
427
+ def set_column_order(self, order: List[str]) -> None:
428
428
  if not order:
429
429
  return
430
430
 
@@ -2,8 +2,6 @@ import os
2
2
  import shutil
3
3
  import tempfile
4
4
  import time
5
- import traceback
6
- from io import StringIO
7
5
  from logging import Logger
8
6
  from shutil import make_archive
9
7
  from typing import Any, Dict, List, Optional, Tuple
@@ -48,7 +46,8 @@ def filter_downloads(output_path, pattern, default_pattern=".*") -> List[Tuple[s
48
46
 
49
47
  f_files = []
50
48
  if not pattern:
51
- # Regex will either match on the filename, directory, or filepath, either with default or given pattern for source
49
+ # Regex will either match on the filename, directory, or filepath,
50
+ # either with default or given pattern for source
52
51
  pattern = default_pattern
53
52
 
54
53
  if os.path.isfile(output_path):
@@ -12,8 +12,8 @@ import random
12
12
  import tarfile
13
13
  import threading
14
14
  import subprocess
15
+ import hashlib
15
16
  from contextlib import contextmanager
16
- from hashlib import sha256
17
17
  from passlib.hash import bcrypt
18
18
  from zipfile import ZipFile, BadZipFile
19
19
 
@@ -53,7 +53,8 @@ SOURCE_STATUS_KEY = 'status'
53
53
  UI_SERVER = os.getenv('UI_SERVER', 'https://nginx')
54
54
  UI_SERVER_ROOT_CA = os.environ.get('UI_SERVER_ROOT_CA', '/etc/assemblyline/ssl/al_root-ca.crt')
55
55
  UPDATER_DIR = os.getenv('UPDATER_DIR', os.path.join(tempfile.gettempdir(), 'updater'))
56
- UPDATER_API_ROLES = ['signature_import', 'signature_download', 'signature_view', 'safelist_manage', 'apikey_access', 'signature_manage']
56
+ UPDATER_API_ROLES = ['badlist_manage', 'signature_import', 'signature_download',
57
+ 'signature_view', 'safelist_manage', 'apikey_access', 'signature_manage']
57
58
  STATUS_FILE = '/tmp/status'
58
59
 
59
60
  classification = forge.get_classification()
@@ -187,7 +188,7 @@ class ServiceUpdater(ThreadedCoreBase):
187
188
  return 0
188
189
 
189
190
  def get_local_update_hash(self) -> str:
190
- return sha256(open(self._update_tar, "rb").read()).hexdigest()
191
+ return hashlib.sha256(open(self._update_tar, "rb").read()).hexdigest()
191
192
 
192
193
  def status(self):
193
194
  return {
@@ -393,7 +394,9 @@ class ServiceUpdater(ThreadedCoreBase):
393
394
  username = self.ensure_service_account()
394
395
  with temporary_api_key(self.datastore, username) as api_key:
395
396
  with tempfile.TemporaryDirectory() as update_dir:
396
- al_client = get_client(UI_SERVER, apikey=(username, api_key), verify=self.verify, datastore=self.datastore)
397
+ al_client = get_client(
398
+ UI_SERVER, apikey=(username, api_key),
399
+ verify=self.verify, datastore=self.datastore)
397
400
  self.log.info("Connected!")
398
401
 
399
402
  # Parse updater configuration
@@ -550,7 +553,8 @@ class ServiceUpdater(ThreadedCoreBase):
550
553
  new_tar = ''
551
554
 
552
555
  # Before serving directory, let's maintain a map of the different signatures and their current deployment state
553
- # This map allows the service to be more responsive to changes made locally to the system such as classification changes
556
+ # This map allows the service to be more responsive to changes made locally to the system such as
557
+ # classification changes.
554
558
  # This also avoids the need to have to insert this kind of metadata into the signature itself
555
559
  if self._service.update_config.generates_signatures:
556
560
  # Pull signature metadata from the API
@@ -564,7 +568,7 @@ class ServiceUpdater(ThreadedCoreBase):
564
568
  signature_map = {
565
569
  source.name: {'classification': source['default_classification'].value}
566
570
  for source in self._service.update_config.sources
567
- }
571
+ }
568
572
  open(os.path.join(new_directory, SIGNATURES_META_FILENAME), 'w').write(json.dumps(signature_map, indent=2))
569
573
 
570
574
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: assemblyline-v4-service
3
- Version: 4.4.1.dev284
3
+ Version: 4.4.1.dev290
4
4
  Summary: Assemblyline 4 - Service base
5
5
  Home-page: https://github.com/CybercentreCanada/assemblyline-v4-service/
6
6
  Author: CCCS Assemblyline development team
@@ -1,16 +1,16 @@
1
- assemblyline_v4_service/VERSION,sha256=rZwd43FGMQ562-Eb4NYplGQ_bZ_wGpZxmJtg3T4Nt_Q,13
1
+ assemblyline_v4_service/VERSION,sha256=-vORzedMvp3ySVvPpGg60CPBgZgsXvGmwJm2eb5TwX4,13
2
2
  assemblyline_v4_service/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  assemblyline_v4_service/healthz.py,sha256=sS1cFkDLw8hUPMpj7tbHXFv8ZmHcazrwZ0l6oQDwwkQ,1575
4
4
  assemblyline_v4_service/run_privileged_service.py,sha256=9uTfHetXR5G-EDKMDrgfWUOw34yr64-cj6Cm9eZaCbQ,14547
5
5
  assemblyline_v4_service/run_service.py,sha256=RCqxdm-OAwJhl15BnKFkuavpQ5k6eTX3ZGeSna5JJBw,5557
6
6
  assemblyline_v4_service/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- assemblyline_v4_service/common/api.py,sha256=KPEwOiK1yUlX5GDjZJ-VRXXCCqdHgtnayW1JFdEjpKk,3989
8
- assemblyline_v4_service/common/base.py,sha256=f0ocyMh59RwAoMbXlFMDgXChQMrFiO78j6CU-DEwz7Y,13576
7
+ assemblyline_v4_service/common/api.py,sha256=dIGU_k0mYZjC545WUwox0wp2GVZa8v1taI80Kofgh4Y,6538
8
+ assemblyline_v4_service/common/base.py,sha256=9xufnspN99J1EHTru1fdkflRwB6PGdfyCUDvYwUIBEk,13610
9
9
  assemblyline_v4_service/common/helper.py,sha256=xs9quuf-M1JOdKieBqOmWaOece0CtzXFhhe85xQYmuY,3289
10
10
  assemblyline_v4_service/common/ocr.py,sha256=erKJMioiOL53i7qiEq9zve4-FnwW22twILboX19M5eQ,4555
11
11
  assemblyline_v4_service/common/ontology_helper.py,sha256=QpwerYoS5hXjWzpx3Pmwv6j2330PQVYqxYGamjcpW3I,7890
12
- assemblyline_v4_service/common/request.py,sha256=QeRJhJSQGffiQxLuaKtFb0xQGnEtyDtGiawRPxDVGT4,11311
13
- assemblyline_v4_service/common/result.py,sha256=SNj-qAOF2Lvvws7YM6--6hyBcyG_rFT-Bf62SzZyryY,32345
12
+ assemblyline_v4_service/common/request.py,sha256=Ji_xCptED_-xhSrks06wBxaVUNHZBpp_sY_1E_phYKE,11477
13
+ assemblyline_v4_service/common/result.py,sha256=GiFEFbHlaJorOfCB0XWtFs_jloI8Y5KeiF-g1x2-w98,32346
14
14
  assemblyline_v4_service/common/task.py,sha256=erg6-pGi_Avpzj0Fkn6opUTevi6xFgaWK2oT-RaZ7fg,12985
15
15
  assemblyline_v4_service/common/utils.py,sha256=k2__d-V5LjB6o2IKbjVe7tJWKcKuUHto5TyT5oKhIa0,3890
16
16
  assemblyline_v4_service/dev/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -20,8 +20,8 @@ assemblyline_v4_service/updater/__main__.py,sha256=9Os-u8Tf7MD73JSrUSPmOaErTgfve
20
20
  assemblyline_v4_service/updater/app.py,sha256=Mtmx4bkXfP4nFqqa5q15jW8QIXr4JK84lCovxAVyvPs,3317
21
21
  assemblyline_v4_service/updater/client.py,sha256=VKmkiDz3klvMzXiGSQTH7QN-MfHuJnwaIR7BaXy9aZM,5156
22
22
  assemblyline_v4_service/updater/gunicorn_config.py,sha256=p3j2KPBeD5jvMw9O5i7vAtlRgPSVVxIG9AO0DfN82J8,1247
23
- assemblyline_v4_service/updater/helper.py,sha256=br-sT6mnhaII50HMBhGNdYwqPXLVFQ_Xmi9yPek7lOs,9457
24
- assemblyline_v4_service/updater/updater.py,sha256=VB8jt5qg604HZyG6epHqGqG-7yPUCE5-i6uHOO2n72s,32045
23
+ assemblyline_v4_service/updater/helper.py,sha256=iUR2D3BQ8nVuC6hj4EoTBLGL9DiuikFfY0Dc9Ohs--s,9426
24
+ assemblyline_v4_service/updater/updater.py,sha256=UDqkKF4tQQbBF13fhCQzfJcmlNhYS5iI23odbpKpofE,32131
25
25
  test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
26
  test/test_healthz.py,sha256=oOUjzfcuxNuu5DcdFK6JyhH1XcvU3944lL8UTdlpoF8,133
27
27
  test/test_run_privileged_service.py,sha256=DkeLUlrb7rGx3nZ04aADU9HXXu5mZTf_DBwT0xhzIv4,7
@@ -36,8 +36,8 @@ test/test_common/test_request.py,sha256=CoTIwz4gL2SH-upGrzyuwOC1p86kBVeHImWx6hkz
36
36
  test/test_common/test_result.py,sha256=sJHJ4CXHv_FkqBFp1ELV6XsSjUhqKY4Qa1nCoyXI8Os,42088
37
37
  test/test_common/test_task.py,sha256=WQ1nZG2ina5BiDHRSWxC4RHJKebZ76t0rL8D6eajpsI,18506
38
38
  test/test_common/test_utils.py,sha256=TbnBxqpS_ZC5ptXR9XJX3xtbItD0mTbtiBxxdyP8J5k,5904
39
- assemblyline_v4_service-4.4.1.dev284.dist-info/LICENCE.md,sha256=NSkYo9EH8h5oOkzg4VhjAHF4339MqPP2cQ8msTPgl-c,1396
40
- assemblyline_v4_service-4.4.1.dev284.dist-info/METADATA,sha256=Nw4DJfuMdUdeu6fursmOsqKwpFyRsAz9xRik_2hQqGU,9691
41
- assemblyline_v4_service-4.4.1.dev284.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
42
- assemblyline_v4_service-4.4.1.dev284.dist-info/top_level.txt,sha256=LpTOEaVCatkrvbVq3EZseMSIa2PQZU-2rhuO_FTpZgY,29
43
- assemblyline_v4_service-4.4.1.dev284.dist-info/RECORD,,
39
+ assemblyline_v4_service-4.4.1.dev290.dist-info/LICENCE.md,sha256=NSkYo9EH8h5oOkzg4VhjAHF4339MqPP2cQ8msTPgl-c,1396
40
+ assemblyline_v4_service-4.4.1.dev290.dist-info/METADATA,sha256=ta7QZExSW8wvO_eJTrstj8cEBtc6W-oVa3gN-J_ybz0,9691
41
+ assemblyline_v4_service-4.4.1.dev290.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
42
+ assemblyline_v4_service-4.4.1.dev290.dist-info/top_level.txt,sha256=LpTOEaVCatkrvbVq3EZseMSIa2PQZU-2rhuO_FTpZgY,29
43
+ assemblyline_v4_service-4.4.1.dev290.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.41.2)
2
+ Generator: bdist_wheel (0.41.3)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5