-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initial mako support #38
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pycryptodomex | ||
malduck | ||
pymisp | ||
mwdblib>=3.3.0 | ||
mwdblib>=3.3.0 | ||
maco |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
from urllib.parse import urlparse | ||
|
||
from Cryptodome.PublicKey import RSA # type: ignore | ||
from maco import model # type: ignore | ||
from malduck import base64, rsa # type: ignore | ||
from pymisp import MISPAttribute, MISPObject # type: ignore | ||
|
||
|
@@ -201,8 +202,9 @@ def prettyprint(self) -> str: | |
class IocCollection: | ||
"""Represents a collection of parsed IoCs""" | ||
|
||
def __init__(self) -> None: | ||
def __init__(self, family: str) -> None: | ||
"""Creates an empty IocCollection instance""" | ||
self.family = family | ||
self.rsa_keys: List[RsaKey] = [] | ||
self.ecdsa_curves: List[EcdsaCurve] = [] | ||
self.keys: List[Tuple[str, str]] = [] # (keytype, hexencoded key) | ||
|
@@ -331,9 +333,83 @@ def to_misp(self) -> List[MISPObject]: | |
|
||
# filter out objects without any attributes | ||
to_return = list(filter(lambda x: bool(x.attributes), to_return)) | ||
|
||
return to_return | ||
|
||
def to_maco(self) -> model.ExtractorModel: | ||
output = model.ExtractorModel(family=self.family) | ||
|
||
for rsakey in self.rsa_keys: | ||
obj = model.ExtractorModel.Encryption( | ||
algorithm="rsa", | ||
public_key=str((rsakey.n, rsakey.e)), | ||
) | ||
if rsakey.d: | ||
obj.key = str((rsakey.n, rsakey.d)) | ||
output.encryption.append(obj) | ||
|
||
for curve in self.ecdsa_curves: | ||
output.encryption.append( | ||
model.ExtractorModel.Encryption( | ||
algorithm=curve.t, # for example, "ecdsa_pub_p384" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a convention for naming this types (we don't have an enum ourselves, though we map There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So far I don't believe we have a naming convention for the |
||
public_key=str((curve.x, curve.y)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here |
||
) | ||
) | ||
|
||
for key in self.keys: | ||
output.encryption.append( | ||
model.ExtractorModel.Encryption( | ||
algorithm=key[0], | ||
key=key[1], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hexencoded |
||
) | ||
) | ||
|
||
for password in self.passwords: | ||
output.password.append(password) | ||
|
||
def location_type_to_maco(location_type: LocationType) -> str: | ||
if location_type in [LocationType.CNC, LocationType.PANEL]: | ||
# Panel is not 100% technically correct here | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Panel should be close enough to C2 to do this mapping |
||
return "c2" | ||
elif location_type == LocationType.DOWNLOAD_URL: | ||
return "download" | ||
elif location_type in [LocationType.OTHER, LocationType.PEER]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No way to add a peer I think (it's not useful nowadays anyway) |
||
return "other" | ||
else: | ||
raise ValueError(f"Unknown location type: {location_type}") | ||
|
||
for netloc in self.network_locations: | ||
if netloc.scheme in ["https", "http"]: | ||
output.http.append( | ||
model.ExtractorModel.Http( | ||
protocol=netloc.scheme, | ||
uri=netloc.url.geturl(), | ||
usage=location_type_to_maco(netloc.location_type), | ||
) | ||
) | ||
else: | ||
output.tcp.append( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't keep track of connection type for non-http connections, sadly. But I can't think of a situation where this was not TCP |
||
model.ExtractorModel.Connection( | ||
server_ip=netloc.url.hostname, | ||
server_port=netloc.port, | ||
) | ||
) | ||
|
||
for mutex in self.mutexes: | ||
output.mutex.append(mutex) | ||
|
||
for filename in self.dropped_filenames: | ||
output.paths.append(filename) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think i'm not adhering to the spirit of this field - we only store filenames, not complete paths. |
||
|
||
# Not supported by Maco | ||
# for email in self.emails_to + self.emails_from: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, for credentials stealing |
||
# output.emails.append(email) | ||
Comment on lines
+403
to
+405
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this be covered under the |
||
|
||
# Not supported by Maco | ||
# for message in self.ransom_messages: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. used by ransomware There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this could be something added to |
||
# output.messages.append(message) | ||
|
||
return output.model_dump(exclude_defaults=True) | ||
|
||
def prettyprint(self) -> str: | ||
"""Pretty print for debugging""" | ||
result = [] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to use the
maco-model
package since it only contains the Pydantic models which is the only part in use in this feature.Module structure is the same as the full package so you won't have to update the imports 😁