Skip to content

Commit

Permalink
as lists and fix rule
Browse files Browse the repository at this point in the history
  • Loading branch information
fcosantos committed Nov 24, 2023
1 parent 6e58600 commit 2693c24
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
31 changes: 23 additions & 8 deletions examples/livehunt_network_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,19 @@ async def upload_rulesets(queue):
)
try:
# Fix for https://github.com/VirusTotal/vt-py/issues/155 issue.
await client.patch_async(
result = await client.patch_async(
path="/intelligence/hunting_rulesets/" + task.get("id"),
json_data={"data": ruleset.to_dict()},
)
print(f'Ruleset {name} [{RULESET_LINK}{task["id"]}] updated.')
except vt.error.APIError as e:
print(f"Error updating {name}: {e}")

response = await result.json_async()
if response.get('error') != None:
print(f'{name}: {response}')

print(f'Ruleset {name} [{RULESET_LINK}{task["id"]}] updated.')

else:
ruleset = vt.Object(
obj_type="hunting_ruleset",
Expand All @@ -146,10 +151,15 @@ async def upload_rulesets(queue):
result = await client.post_object_async(
path="/intelligence/hunting_rulesets", obj=ruleset
)
print(f"Ruleset {name} [{RULESET_LINK}{result.id}] created.")
except vt.error.APIError as e:
print(f"Error saving {name}: {e}")

response = await result.json_async()
if response.get('error') != None:
print(f'{name}: {response}')

print(f"Ruleset {name} [{RULESET_LINK}{result.id}] created.")

queue.task_done()


Expand Down Expand Up @@ -182,11 +192,15 @@ async def main():
parser.add_argument(
"-a",
"--add-domain",
action="append",
type=str,
help="Add a domain to the list.",
)
parser.add_argument(
"-d",
"--delete-domain",
action="append",
type=str,
help="Remove a domain from the list.",
)
parser.add_argument(
Expand Down Expand Up @@ -243,13 +257,14 @@ async def main():

else:
if args.add_domain:
new_domain_list.append(args.add_domain)
new_domain_list += args.add_domain

if args.delete_domain:
if not args.delete_domain in new_domain_list:
print(f"* {args.delete_domain} not in list")
sys.exit(1)
new_domain_list.remove(args.delete_domain)
for deleted_domain in args.delete_domain:
if not deleted_domain in new_domain_list:
print(f"* {deleted_domain} not in list")
sys.exit(1)
new_domain_list.remove(deleted_domain)

new_domain_list = list(set(new_domain_list))
new_domain_list.sort()
Expand Down
2 changes: 1 addition & 1 deletion examples/netwatch_templates/domain.yara
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rule network_watch_${domain_escaped} : ${domain_escaped} {
rule network_watch_${domain_escaped} : domain_${domain_escaped} {
meta:
description = "Monitor new subdomains for ${domain}"
target_entity = "domain"
Expand Down
4 changes: 2 additions & 2 deletions examples/netwatch_templates/file.yara
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rule network_watch_${domain_escaped} : ${domain_escaped} {
rule network_watch_${domain_escaped} : domain_${domain_escaped} {
meta:
description = "New files downloaded from ${domain}"
target_entity = "file"
Expand All @@ -8,7 +8,7 @@ condition:
}


rule network_watch_contact_${domain_escaped} : ${domain_escaped} {
rule network_watch_contact_${domain_escaped} : domain_${domain_escaped} {
meta:
description = "New files contacting ${domain}"
target_entity = "file"
Expand Down
2 changes: 1 addition & 1 deletion examples/netwatch_templates/ip_address.yara
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rule network_watch_${domain_escaped} : ${domain_escaped} {
rule network_watch_${domain_escaped} : domain_${domain_escaped} {
meta:
description = "New IP addresses resolving domain ${domain} or its subdomains"
target_entity = "ip_address"
Expand Down
2 changes: 1 addition & 1 deletion examples/netwatch_templates/url.yara
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rule network_watch_${domain_escaped} : ${domain_escaped} {
rule network_watch_${domain_escaped} : domain_${domain_escaped} {
meta:
description = "Monitor new URLs in ${domain}"
target_entity = "url"
Expand Down

0 comments on commit 2693c24

Please sign in to comment.