Skip to content

Commit

Permalink
More precise field selection when searching (#3044)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchop authored Feb 29, 2024
1 parent 45e1400 commit d17f984
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions timesketch/lib/analyzers/yetiindicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,34 @@ def save_intelligence(self):
overwrite=True,
)

def build_query_from_indicator(self, indicator: Dict) -> Dict:
"""Builds a query DSL from a Yeti indicator.
Args:
indicator: a dictionary representing a Yeti indicator object.
Returns:
A dictionary representing a query DSL.
"""
field = ""
if indicator["location"] == "registry":
field = "key_path.keyword"
elif indicator["location"] == "filesystem":
field = "filename.keyword"
else:
field = "message.keyword"

return {
"query": {
"regexp": {
field: {
"value": f".*{indicator['pattern']}.*",
"case_insensitive": True,
}
}
}
}

def run(self):
"""Entry point for the analyzer.
Expand All @@ -289,13 +317,7 @@ def run(self):
entity, max_hops=5, neighbor_types=self._TARGET_NEIGHBOR_TYPE
)
for indicator in indicators.values():
query_dsl = {
"query": {
"regexp": {
"message.keyword": ".*" + indicator["pattern"] + ".*"
}
}
}
query_dsl = self.build_query_from_indicator(indicator)
events = self.event_stream(
query_dsl=query_dsl, return_fields=["message"], scroll=False
)
Expand Down

0 comments on commit d17f984

Please sign in to comment.