pySigma 1.3.0__tar.gz → 1.3.2__tar.gz

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.
Files changed (65) hide show
  1. {pysigma-1.3.0 → pysigma-1.3.2}/PKG-INFO +1 -1
  2. {pysigma-1.3.0 → pysigma-1.3.2}/pyproject.toml +1 -1
  3. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/conversion/base.py +10 -0
  4. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/pipeline.py +12 -1
  5. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/resolver.py +1 -1
  6. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/validators/core/tags.py +12 -2
  7. {pysigma-1.3.0 → pysigma-1.3.2}/LICENSE +0 -0
  8. {pysigma-1.3.0 → pysigma-1.3.2}/README.md +0 -0
  9. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/backends/test/__init__.py +0 -0
  10. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/backends/test/backend.py +0 -0
  11. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/collection.py +0 -0
  12. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/conditions.py +0 -0
  13. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/conversion/__init__.py +0 -0
  14. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/conversion/deferred.py +0 -0
  15. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/conversion/state.py +0 -0
  16. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/correlations.py +0 -0
  17. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/data/mitre_attack.py +0 -0
  18. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/data/mitre_d3fend.py +0 -0
  19. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/exceptions.py +0 -0
  20. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/filters.py +0 -0
  21. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/modifiers.py +0 -0
  22. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/pipelines/base.py +0 -0
  23. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/pipelines/common.py +0 -0
  24. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/pipelines/test/__init__.py +0 -0
  25. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/pipelines/test/pipeline.py +0 -0
  26. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/plugins.py +0 -0
  27. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/__init__.py +0 -0
  28. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/condition_expressions.py +0 -0
  29. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/conditions/__init__.py +0 -0
  30. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/conditions/base.py +0 -0
  31. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/conditions/fields.py +0 -0
  32. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/conditions/rule.py +0 -0
  33. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/conditions/state.py +0 -0
  34. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/conditions/values.py +0 -0
  35. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/finalization.py +0 -0
  36. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/postprocessing.py +0 -0
  37. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/templates.py +0 -0
  38. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/tracking.py +0 -0
  39. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/transformations/__init__.py +0 -0
  40. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/transformations/base.py +0 -0
  41. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/transformations/condition.py +0 -0
  42. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/transformations/detection_item.py +0 -0
  43. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/transformations/failure.py +0 -0
  44. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/transformations/fields.py +0 -0
  45. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/transformations/meta.py +0 -0
  46. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/transformations/placeholder.py +0 -0
  47. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/transformations/rule.py +0 -0
  48. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/transformations/state.py +0 -0
  49. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/processing/transformations/values.py +0 -0
  50. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/py.typed +0 -0
  51. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/rule/__init__.py +0 -0
  52. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/rule/attributes.py +0 -0
  53. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/rule/base.py +0 -0
  54. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/rule/detection.py +0 -0
  55. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/rule/logsource.py +0 -0
  56. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/rule/rule.py +0 -0
  57. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/types.py +0 -0
  58. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/validation.py +0 -0
  59. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/validators/base.py +0 -0
  60. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/validators/core/__init__.py +0 -0
  61. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/validators/core/condition.py +0 -0
  62. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/validators/core/logsources.py +0 -0
  63. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/validators/core/metadata.py +0 -0
  64. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/validators/core/modifiers.py +0 -0
  65. {pysigma-1.3.0 → pysigma-1.3.2}/sigma/validators/core/values.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pySigma
3
- Version: 1.3.0
3
+ Version: 1.3.2
4
4
  Summary: Sigma rule processing and conversion tools
5
5
  License-Expression: LGPL-2.1-only
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pySigma"
3
- version = "1.3.0"
3
+ version = "1.3.2"
4
4
  license = "LGPL-2.1-only"
5
5
  description = "Sigma rule processing and conversion tools"
6
6
  authors = [
@@ -987,6 +987,11 @@ class Backend(ABC):
987
987
  This is the place where syntactic elements of the target format for the specific query are added,
988
988
  e.g. adding query metadata.
989
989
  """
990
+ if output_format not in self.formats:
991
+ raise SigmaBackendError(
992
+ f"Unknown output format '{output_format}', "
993
+ f"must be one of: {', '.join(self.formats.keys())}"
994
+ )
990
995
  backend_query = self.__getattribute__("finalize_query_" + output_format)(
991
996
  rule, query, index, state
992
997
  )
@@ -1003,6 +1008,11 @@ class Backend(ABC):
1003
1008
 
1004
1009
  def finalize(self, queries: list[Any], output_format: str) -> Any:
1005
1010
  """Finalize output. Dispatches to format-specific method."""
1011
+ if output_format not in self.formats:
1012
+ raise SigmaBackendError(
1013
+ f"Unknown output format '{output_format}', "
1014
+ f"must be one of: {', '.join(self.formats.keys())}"
1015
+ )
1006
1016
  output = self.__getattribute__("finalize_output_" + output_format)(queries)
1007
1017
  return self.last_processing_pipeline.finalize(output)
1008
1018
 
@@ -4,6 +4,7 @@ from collections import defaultdict
4
4
  from dataclasses import dataclass, field
5
5
  from functools import partial
6
6
  import hashlib
7
+ import os
7
8
  from typing import (
8
9
  Literal,
9
10
  Mapping,
@@ -858,8 +859,18 @@ class ProcessingPipeline:
858
859
  processing_pipeline: str,
859
860
  allow_template_vars: bool = False,
860
861
  vars_allowed_paths: tuple[str, ...] | None = None,
862
+ source_path: str | None = None,
861
863
  ) -> "ProcessingPipeline":
862
- """Convert YAML input string into processing pipeline."""
864
+ """Convert YAML input string into processing pipeline.
865
+
866
+ If *source_path* is provided and *vars_allowed_paths* is ``None``, the
867
+ directory containing *source_path* is automatically used as the only
868
+ allowed base directory for template vars files. This prevents a
869
+ pipeline YAML from referencing vars files outside its own directory
870
+ tree.
871
+ """
872
+ if vars_allowed_paths is None and source_path is not None:
873
+ vars_allowed_paths = (os.path.dirname(os.path.realpath(source_path)),)
863
874
  try:
864
875
  parsed_pipeline = yaml.safe_load(processing_pipeline)
865
876
  except yaml.parser.ParserError as e:
@@ -63,7 +63,7 @@ class ProcessingPipelineResolver:
63
63
  except KeyError: # identifier not found, try it as path
64
64
  try:
65
65
  with open(spec, "r") as f:
66
- return ProcessingPipeline.from_yaml(f.read())
66
+ return ProcessingPipeline.from_yaml(f.read(), source_path=spec)
67
67
  except OSError as e:
68
68
  raise SigmaPipelineNotFoundError(spec)
69
69
 
@@ -43,7 +43,10 @@ class ATTACKTagValidator(SigmaTagValidator):
43
43
  """Check for usage of valid MITRE ATT&CK tags."""
44
44
 
45
45
  def __init__(self) -> None:
46
- self.allowed_tags = (
46
+ self.allowed_tags: set[str] | None = None
47
+
48
+ def _load_allowed_tags(self) -> set[str]:
49
+ return (
47
50
  {tactic.lower() for tactic in mitre_attack.mitre_attack_tactics.values()}
48
51
  .union({technique.lower() for technique in mitre_attack.mitre_attack_techniques.keys()})
49
52
  .union(
@@ -62,6 +65,8 @@ class ATTACKTagValidator(SigmaTagValidator):
62
65
  )
63
66
 
64
67
  def validate_tag(self, tag: SigmaRuleTag) -> list[SigmaValidationIssue]:
68
+ if self.allowed_tags is None:
69
+ self.allowed_tags = self._load_allowed_tags()
65
70
  if tag.namespace == "attack" and tag.name not in self.allowed_tags:
66
71
  return [InvalidATTACKTagIssue([self.rule], tag)]
67
72
  return []
@@ -78,13 +83,18 @@ class D3FENDTagValidator(SigmaTagValidator):
78
83
  """Check for usage of valid MITRE D3FEND tags."""
79
84
 
80
85
  def __init__(self) -> None:
81
- self.allowed_tags = (
86
+ self.allowed_tags: set[str] | None = None
87
+
88
+ def _load_allowed_tags(self) -> set[str]:
89
+ return (
82
90
  {tactic.lower() for tactic in mitre_d3fend.mitre_d3fend_tactics.keys()}
83
91
  .union({technique.lower() for technique in mitre_d3fend.mitre_d3fend_techniques.keys()})
84
92
  .union({artefact for artefact in mitre_d3fend.mitre_d3fend_artifacts.keys()})
85
93
  )
86
94
 
87
95
  def validate_tag(self, tag: SigmaRuleTag) -> list[SigmaValidationIssue]:
96
+ if self.allowed_tags is None:
97
+ self.allowed_tags = self._load_allowed_tags()
88
98
  if tag.namespace == "d3fend" and tag.name not in self.allowed_tags:
89
99
  return [InvalidD3FENDagIssue([self.rule], tag)]
90
100
  return []
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes