-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[zerofox] Update ZeroFox Connector (#2207)
- Loading branch information
Showing
8 changed files
with
130 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 50 additions & 31 deletions
81
external-import/zerofox/src/collectors/mappers/malwareToMalware.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,71 @@ | ||
from typing import List, Union | ||
|
||
from stix2 import URL | ||
from stix2 import URL, File, Indicator | ||
from stix2 import Malware as stixMalware | ||
from stix2 import Relationship | ||
from stix2.v21.vocab import PATTERN_TYPE_STIX | ||
from zerofox.domain.malware import Malware | ||
|
||
|
||
def malware_to_malware( | ||
now: str, entry: Malware | ||
) -> List[Union[stixMalware, Relationship, URL]]: | ||
malware = stixMalware( | ||
name=f"Malware -- {entry.sha256}", | ||
labels=entry.tags, | ||
created=now, | ||
first_seen=entry.created_at, | ||
malware_types="unknown", | ||
is_family=False, | ||
) | ||
) -> List[Union[URL, File, Indicator, Relationship, stixMalware]]: | ||
urls = [URL(value=c2) for c2 in entry.c2] if entry.c2 else [] | ||
malware_families = ( | ||
[ | ||
stixMalware(name=f"Malware family:{family}", is_family=True) | ||
for family in entry.family | ||
] | ||
[stixMalware(name=family, is_family=True) for family in entry.family] | ||
if entry.family | ||
else [] | ||
) | ||
present_hashes = {} | ||
|
||
return ( | ||
[malware] | ||
+ urls | ||
+ [ | ||
Relationship( | ||
source_ref=malware.id, | ||
target_ref=domain_name.id, | ||
relationship_type="communicates-with", | ||
start_time=entry.created_at, | ||
) | ||
for domain_name in urls | ||
] | ||
+ malware_families | ||
+ [ | ||
if entry.sha512: | ||
present_hashes["SHA-512"] = entry.sha512 | ||
if entry.sha1: | ||
present_hashes["SHA-1"] = entry.sha1 | ||
if entry.md5: | ||
present_hashes["MD5"] = entry.md5 | ||
|
||
file = File( | ||
name=entry.sha256, | ||
hashes={ | ||
"SHA-256": entry.sha256, | ||
} | ||
| present_hashes, | ||
) | ||
|
||
pattern_string = f"[file:hashes.'SHA-256' = '{entry.sha256}'" | ||
for k, v in present_hashes.items(): | ||
pattern_string += f" OR file:hashes.'{k}' = '{v}'" | ||
pattern_string += "]" | ||
|
||
indicator = Indicator( | ||
name=entry.sha256, | ||
pattern_type=PATTERN_TYPE_STIX, | ||
pattern=pattern_string, | ||
) | ||
|
||
file_indicator_rel = Relationship( | ||
source_ref=indicator.id, target_ref=file.id, relationship_type="based-on" | ||
) | ||
|
||
malware_indicators_rel = ( | ||
[ | ||
Relationship( | ||
source_ref=malware.id, | ||
source_ref=indicator.id, | ||
target_ref=family.id, | ||
relationship_type="variant-of", | ||
start_time=entry.created_at, | ||
relationship_type="indicates", | ||
) | ||
for family in malware_families | ||
] | ||
if malware_families | ||
else [] | ||
) | ||
|
||
return ( | ||
urls | ||
+ malware_families | ||
+ malware_indicators_rel | ||
+ [file_indicator_rel] | ||
+ [file] | ||
+ [indicator] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 65 additions & 12 deletions
77
external-import/zerofox/src/collectors/mappers/ransomwareToMalware.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,76 @@ | ||
from typing import List | ||
from typing import List, Union | ||
|
||
from stix2 import File, Indicator | ||
from stix2 import Malware as stixMalware | ||
from stix2 import Relationship | ||
from stix2.v21.vocab import PATTERN_TYPE_STIX | ||
from zerofox.domain.ransomware import Ransomware | ||
|
||
|
||
def ransomware_to_malware(now: str, entry: Ransomware) -> List[stixMalware]: | ||
ransomware_name = ( | ||
entry.ransomware_name[0] | ||
if entry.ransomware_name and len(entry.ransomware_name) > 0 | ||
else "" | ||
) | ||
ransomware = stixMalware( | ||
name=f"Ransomware {ransomware_name} -- {entry.sha256}", | ||
description=f"Ransomware with note -- {entry.ransom_note}", | ||
def ransomware_to_malware( | ||
now: str, entry: Ransomware | ||
) -> List[Union[Relationship, Indicator, File, stixMalware]]: | ||
ransomware_name = "" | ||
family = False | ||
|
||
if entry.ransomware_name and len(entry.ransomware_name) > 0: | ||
ransomware_name = entry.ransomware_name[0] | ||
family = True | ||
else: | ||
ransomware_name = entry.sha256 | ||
|
||
malware = stixMalware( | ||
name=f"{ransomware_name}", | ||
description=f"```{entry.ransom_note}```", | ||
labels=entry.tags, | ||
first_seen=entry.created_at, | ||
created=now, | ||
malware_types="ransomware", | ||
is_family=False, | ||
is_family=family, | ||
) | ||
|
||
present_hashes = {} | ||
|
||
if entry.sha512: | ||
present_hashes["SHA-512"] = entry.sha512 | ||
if entry.sha1: | ||
present_hashes["SHA-1"] = entry.sha1 | ||
if entry.md5: | ||
present_hashes["MD5"] = entry.md5 | ||
|
||
file = File( | ||
name=entry.sha256, | ||
hashes={ | ||
"SHA-256": entry.sha256, | ||
} | ||
| present_hashes, | ||
) | ||
|
||
return [ransomware] | ||
pattern_string = f"[file:hashes.'SHA-256' = '{entry.sha256}'" | ||
for k, v in present_hashes.items(): | ||
pattern_string += f" OR file:hashes.'{k}' = '{v}'" | ||
pattern_string += "]" | ||
|
||
indicator = Indicator( | ||
name=entry.sha256, | ||
pattern_type=PATTERN_TYPE_STIX, | ||
pattern=pattern_string, | ||
) | ||
|
||
file_indicator_rel = Relationship( | ||
source_ref=indicator.id, target_ref=file.id, relationship_type="based-on" | ||
) | ||
|
||
malware_indicators_rel = Relationship( | ||
source_ref=indicator.id, | ||
target_ref=malware.id, | ||
relationship_type="indicates", | ||
) | ||
|
||
return ( | ||
[malware] | ||
+ [file] | ||
+ [indicator] | ||
+ [file_indicator_rel] | ||
+ [malware_indicators_rel] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters