maco 1.2.7__py3-none-any.whl → 1.2.9__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.
maco/cli.py CHANGED
@@ -123,10 +123,15 @@ def process_filesystem(
123
123
  logger.error(f"not file or folder: {path_samples}")
124
124
  exit(2)
125
125
  try:
126
- for path, dirs, files in walker:
126
+ base_directory = os.path.abspath(path_samples)
127
+ for path, _, files in walker:
127
128
  for file in files:
128
129
  num_analysed += 1
129
- path_file = os.path.join(path, file)
130
+ path_file = os.path.abspath(os.path.join(path, file))
131
+ if not path_file.startswith(base_directory):
132
+ logger.error(f"Attempted path traversal detected: {path_file}")
133
+ continue
134
+
130
135
  try:
131
136
  with open(path_file, "rb") as stream:
132
137
  resp = process_file(
maco/collector.py CHANGED
@@ -5,11 +5,11 @@ import logging
5
5
  import logging.handlers
6
6
  import os
7
7
  import sys
8
- from multiprocessing import Manager, Process, Queue
9
8
  from tempfile import NamedTemporaryFile
10
9
  from types import ModuleType
11
- from typing import Any, BinaryIO, Dict, List, Union
10
+ from typing import Any, BinaryIO, Dict, List, TypedDict, Union
12
11
 
12
+ from multiprocess import Manager, Process, Queue
13
13
  from pydantic import BaseModel
14
14
 
15
15
  from maco import extractor, model, utils, yara
@@ -40,6 +40,26 @@ def _verify_response(resp: Union[BaseModel, dict]) -> Dict:
40
40
  return resp.model_dump(exclude_defaults=True)
41
41
 
42
42
 
43
+ class ExtractorMetadata(TypedDict):
44
+ """Extractor-supplied metadata."""
45
+
46
+ author: str
47
+ family: str
48
+ last_modified: str
49
+ sharing: str
50
+ description: str
51
+
52
+
53
+ class ExtractorRegistration(TypedDict):
54
+ """Registration collected by the collector for a single extractor."""
55
+
56
+ venv: str
57
+ module_path: str
58
+ module_name: str
59
+ extractor_class: str
60
+ metadata: ExtractorMetadata
61
+
62
+
43
63
  class Collector:
44
64
  def __init__(
45
65
  self,
@@ -60,7 +80,7 @@ class Collector:
60
80
 
61
81
  path_extractors = os.path.realpath(path_extractors)
62
82
  self.path: str = path_extractors
63
- self.extractors: Dict[str, Dict[str, str]] = {}
83
+ self.extractors: Dict[str, ExtractorRegistration] = {}
64
84
 
65
85
  with Manager() as manager:
66
86
  extractors = manager.dict()
maco/utils.py CHANGED
@@ -6,7 +6,6 @@ import inspect
6
6
  import json
7
7
  import logging
8
8
  import logging.handlers
9
- import multiprocessing
10
9
  import os
11
10
  import re
12
11
  import shutil
@@ -14,6 +13,8 @@ import subprocess
14
13
  import sys
15
14
  import tempfile
16
15
 
16
+ from multiprocess import Queue
17
+
17
18
  from maco import yara
18
19
 
19
20
  if sys.version_info >= (3, 11):
@@ -390,7 +391,7 @@ def register_extractors(
390
391
  break
391
392
 
392
393
 
393
- def proxy_logging(queue: multiprocessing.Queue, callback: Callable[[ModuleType, str], None], *args, **kwargs):
394
+ def proxy_logging(queue: Queue, callback: Callable[[ModuleType, str], None], *args, **kwargs):
394
395
  """Ensures logging is set up correctly for a child process and then executes the callback."""
395
396
  logger = logging.getLogger()
396
397
  qh = logging.handlers.QueueHandler(queue)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: maco
3
- Version: 1.2.7
3
+ Version: 1.2.9
4
4
  Author: sl-govau
5
5
  Maintainer: cccs-rs
6
6
  License: MIT License
@@ -35,6 +35,7 @@ Requires-Dist: tomli>=1.1.0; python_version < "3.11"
35
35
  Requires-Dist: uv
36
36
  Requires-Dist: yara-python
37
37
  Requires-Dist: yara-x==0.11.0
38
+ Requires-Dist: multiprocess>=0.70.17
38
39
 
39
40
  # Maco - Malware config extractor framework
40
41
 
@@ -9,19 +9,19 @@ demo_extractors/complex/complex.py,sha256=tXrzj_zWIXbTOwj7Lezapk-qkrM-lfwcyjd5m-
9
9
  demo_extractors/complex/complex_utils.py,sha256=aec8kJsYUrMPo-waihkVLt-0QpiOPkw7dDqfT9MNuHk,123
10
10
  maco/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  maco/base_test.py,sha256=cjGLEy2c69wl9sjn74QFz7X-VxWOfdin4W8MvYsXc4Q,2718
12
- maco/cli.py,sha256=NTzV8eu9V0qQNttRo592j-Rdzac7q1NAMraqJF2h_6k,8171
13
- maco/collector.py,sha256=LraWYlCA72FCmQP0dHWc-ekd7R1SxR6h6rMD95_6mMs,7077
12
+ maco/cli.py,sha256=pPS8euWaLV-6csBCCzT1Mtc7GwP7a_RikDjfUYxoxU8,8415
13
+ maco/collector.py,sha256=cBZEHx5qjFwf-EfAgEmXlu4kT4rWZkcDE926gBrOoN8,7493
14
14
  maco/extractor.py,sha256=uGSGiCQ4jd8jFmfw2T99BGcY5iQJzXHcG_RoTIxClTE,2802
15
- maco/utils.py,sha256=RbG36i04iWoe5gBUxbnbJ_lDvYY5OkYtiy0EdXF9OHw,20870
15
+ maco/utils.py,sha256=-ESB2JdfGCubEBTp7yt5M57z-FQUeYI1bmC37vNnsX0,20863
16
16
  maco/yara.py,sha256=8RVaGyeUWY5f8_wfQ25lDX1bcXsb_VoSja85ZC2SqGw,2913
17
17
  maco/model/__init__.py,sha256=ULdyHx8R5D2ICHZo3VoCk1YTlewTok36TYIpwx__pNY,45
18
18
  maco/model/model.py,sha256=4uY88WphbP3iu-L2WjuYwtgZCS_wNul_hr0bAVuTpvc,23740
19
19
  model_setup/maco/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  model_setup/maco/base_test.py,sha256=cjGLEy2c69wl9sjn74QFz7X-VxWOfdin4W8MvYsXc4Q,2718
21
- model_setup/maco/cli.py,sha256=NTzV8eu9V0qQNttRo592j-Rdzac7q1NAMraqJF2h_6k,8171
22
- model_setup/maco/collector.py,sha256=LraWYlCA72FCmQP0dHWc-ekd7R1SxR6h6rMD95_6mMs,7077
21
+ model_setup/maco/cli.py,sha256=pPS8euWaLV-6csBCCzT1Mtc7GwP7a_RikDjfUYxoxU8,8415
22
+ model_setup/maco/collector.py,sha256=cBZEHx5qjFwf-EfAgEmXlu4kT4rWZkcDE926gBrOoN8,7493
23
23
  model_setup/maco/extractor.py,sha256=uGSGiCQ4jd8jFmfw2T99BGcY5iQJzXHcG_RoTIxClTE,2802
24
- model_setup/maco/utils.py,sha256=RbG36i04iWoe5gBUxbnbJ_lDvYY5OkYtiy0EdXF9OHw,20870
24
+ model_setup/maco/utils.py,sha256=-ESB2JdfGCubEBTp7yt5M57z-FQUeYI1bmC37vNnsX0,20863
25
25
  model_setup/maco/yara.py,sha256=8RVaGyeUWY5f8_wfQ25lDX1bcXsb_VoSja85ZC2SqGw,2913
26
26
  model_setup/maco/model/__init__.py,sha256=ULdyHx8R5D2ICHZo3VoCk1YTlewTok36TYIpwx__pNY,45
27
27
  model_setup/maco/model/model.py,sha256=4uY88WphbP3iu-L2WjuYwtgZCS_wNul_hr0bAVuTpvc,23740
@@ -36,9 +36,9 @@ tests/extractors/basic_longer.py,sha256=1ClU2QD-Y0TOl_loNFvEqIEpTR5TSVJ6zg9ZmC-E
36
36
  tests/extractors/test_basic.py,sha256=FLKekfSGM69HaiF7Vu_7D7KDXHZko-9hZkMO8_DoyYA,697
37
37
  tests/extractors/bob/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
38
38
  tests/extractors/bob/bob.py,sha256=G5aOoz58J0ZQK2_lA7HRxAzeLzBxssWxBTZcv1pSbi8,176
39
- maco-1.2.7.dist-info/LICENSE.md,sha256=gMSjshPhXvV_F1qxmeNkKdBqGWkd__fEJf4glS504bM,1478
40
- maco-1.2.7.dist-info/METADATA,sha256=09_OhgEFJ1kNPB6tg0NiJQmIrlLDB51bbR2rnrdW-wU,15855
41
- maco-1.2.7.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
42
- maco-1.2.7.dist-info/entry_points.txt,sha256=TpcwG1gedIg8Y7a9ZOv8aQpuwEUftCefDrAjzeP-o6U,39
43
- maco-1.2.7.dist-info/top_level.txt,sha256=iMRwuzmrHA3zSwiSeMIl6FWhzRpn_st-I4fAv-kw5_o,49
44
- maco-1.2.7.dist-info/RECORD,,
39
+ maco-1.2.9.dist-info/LICENSE.md,sha256=gMSjshPhXvV_F1qxmeNkKdBqGWkd__fEJf4glS504bM,1478
40
+ maco-1.2.9.dist-info/METADATA,sha256=zkoQkUI4Ll9ii6AkDJTi01Y0-53eNfgoNbqK5CyB6es,15892
41
+ maco-1.2.9.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
42
+ maco-1.2.9.dist-info/entry_points.txt,sha256=TpcwG1gedIg8Y7a9ZOv8aQpuwEUftCefDrAjzeP-o6U,39
43
+ maco-1.2.9.dist-info/top_level.txt,sha256=iMRwuzmrHA3zSwiSeMIl6FWhzRpn_st-I4fAv-kw5_o,49
44
+ maco-1.2.9.dist-info/RECORD,,
model_setup/maco/cli.py CHANGED
@@ -123,10 +123,15 @@ def process_filesystem(
123
123
  logger.error(f"not file or folder: {path_samples}")
124
124
  exit(2)
125
125
  try:
126
- for path, dirs, files in walker:
126
+ base_directory = os.path.abspath(path_samples)
127
+ for path, _, files in walker:
127
128
  for file in files:
128
129
  num_analysed += 1
129
- path_file = os.path.join(path, file)
130
+ path_file = os.path.abspath(os.path.join(path, file))
131
+ if not path_file.startswith(base_directory):
132
+ logger.error(f"Attempted path traversal detected: {path_file}")
133
+ continue
134
+
130
135
  try:
131
136
  with open(path_file, "rb") as stream:
132
137
  resp = process_file(
@@ -5,11 +5,11 @@ import logging
5
5
  import logging.handlers
6
6
  import os
7
7
  import sys
8
- from multiprocessing import Manager, Process, Queue
9
8
  from tempfile import NamedTemporaryFile
10
9
  from types import ModuleType
11
- from typing import Any, BinaryIO, Dict, List, Union
10
+ from typing import Any, BinaryIO, Dict, List, TypedDict, Union
12
11
 
12
+ from multiprocess import Manager, Process, Queue
13
13
  from pydantic import BaseModel
14
14
 
15
15
  from maco import extractor, model, utils, yara
@@ -40,6 +40,26 @@ def _verify_response(resp: Union[BaseModel, dict]) -> Dict:
40
40
  return resp.model_dump(exclude_defaults=True)
41
41
 
42
42
 
43
+ class ExtractorMetadata(TypedDict):
44
+ """Extractor-supplied metadata."""
45
+
46
+ author: str
47
+ family: str
48
+ last_modified: str
49
+ sharing: str
50
+ description: str
51
+
52
+
53
+ class ExtractorRegistration(TypedDict):
54
+ """Registration collected by the collector for a single extractor."""
55
+
56
+ venv: str
57
+ module_path: str
58
+ module_name: str
59
+ extractor_class: str
60
+ metadata: ExtractorMetadata
61
+
62
+
43
63
  class Collector:
44
64
  def __init__(
45
65
  self,
@@ -60,7 +80,7 @@ class Collector:
60
80
 
61
81
  path_extractors = os.path.realpath(path_extractors)
62
82
  self.path: str = path_extractors
63
- self.extractors: Dict[str, Dict[str, str]] = {}
83
+ self.extractors: Dict[str, ExtractorRegistration] = {}
64
84
 
65
85
  with Manager() as manager:
66
86
  extractors = manager.dict()
model_setup/maco/utils.py CHANGED
@@ -6,7 +6,6 @@ import inspect
6
6
  import json
7
7
  import logging
8
8
  import logging.handlers
9
- import multiprocessing
10
9
  import os
11
10
  import re
12
11
  import shutil
@@ -14,6 +13,8 @@ import subprocess
14
13
  import sys
15
14
  import tempfile
16
15
 
16
+ from multiprocess import Queue
17
+
17
18
  from maco import yara
18
19
 
19
20
  if sys.version_info >= (3, 11):
@@ -390,7 +391,7 @@ def register_extractors(
390
391
  break
391
392
 
392
393
 
393
- def proxy_logging(queue: multiprocessing.Queue, callback: Callable[[ModuleType, str], None], *args, **kwargs):
394
+ def proxy_logging(queue: Queue, callback: Callable[[ModuleType, str], None], *args, **kwargs):
394
395
  """Ensures logging is set up correctly for a child process and then executes the callback."""
395
396
  logger = logging.getLogger()
396
397
  qh = logging.handlers.QueueHandler(queue)
File without changes