Skip to content

Commit

Permalink
fix potential dupes
Browse files Browse the repository at this point in the history
  • Loading branch information
fcosantos committed Nov 24, 2023
1 parent 2693c24 commit fd8199d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion examples/livehunt_network_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,21 @@ def render_template(entity, domains):
template += "\n"

kind_template = os.path.join(TEMPLATE_DIR, entity + ".yara")
escaped_domains = {}
with open(kind_template, encoding="utf-8") as f:
rule_block = f.read()

for domain in domains:
domain_escaped = re.compile(r"[^\w\d]").sub("_", domain)
domain_escaped = re.compile(r"[^[a-z\d]").sub("_", domain)
domain_escaped = re.compile(r'(_(?i:_)+)').sub('_', domain_escaped)

if not domain_escaped in escaped_domains:
escaped_domains[domain_escaped] = 0
escaped_domains[domain_escaped] += 1

if escaped_domains[domain_escaped] > 1:
domain_escaped = f"{domain_escaped}_{escaped_domains[domain_escaped]}"

template += rule_block.replace("${domain}", domain).replace(
"${domain_escaped}", domain_escaped
)
Expand Down

0 comments on commit fd8199d

Please sign in to comment.