Skip to content
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

Support for imperative config adding and maco-model standard #101

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

psrok1
Copy link
Member

@psrok1 psrok1 commented Jul 26, 2023

No description provided.

@psrok1 psrok1 force-pushed the feature/maco-model-support branch from cd6497e to 4508e36 Compare July 26, 2023 15:55
@psrok1 psrok1 force-pushed the refactor/malduck-extractor branch from 1a8482b to ed8c86f Compare July 26, 2023 16:13
Base automatically changed from refactor/malduck-extractor to master July 26, 2023 16:17
@psrok1 psrok1 force-pushed the feature/maco-model-support branch from 49d9936 to 675e579 Compare July 26, 2023 16:20
max_size=max_size,
usage=usage,
)
return self.push_config(dict(http=[http]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not compatible with ioc_extractor - should we add support to ioc_extractor for this, or ensure mwdb generates configs understood by ioc_extractor?

port=port,
usage=usage,
)
return self.push_config(dict(ssh=[ssh]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't repeat myself everywhere, but we can think about supporting all useful fields from here in mwdb_iocextract (or supporting mwdb_iocextract from here).


def add_ftp(
self,
username: Optional[str] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is everything really optional? (here and below) at least hostname sound important i guess

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I blindly folllowed Maco scheme there, but yeah, if we don't have alternative like ip vs domain, we should treat hostname as required.


:param others: Dictionary with other configuration fields
"""
return self.push_config(dict(others=others))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we add a special magic key called others? Would this work if we just did this instead:

Suggested change
return self.push_config(dict(others=others))
return self.push_config(others)

(of course there are some edge cases, like add_other({"tcp": 3}), but maybe it's a good tradeoff vs magic others key).

Copy link
Member Author

@psrok1 psrok1 Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it's support for other collection that is meant to contain anything extra, not included in the scheme itself: https://github.com/CybercentreCanada/Maco/blob/master/maco/model/model.py#L200.

And yeah, I see my mistake: the key is other, not others

Maco explicitly bans extra fields: https://github.com/CybercentreCanada/Maco/blob/master/maco/model/model.py#L12

json.dumps(config)
except (TypeError, OverflowError) as e:
log.debug("Config is not JSON-encodable (%s): %s", str(e), repr(config))
raise RuntimeError("Config must be JSON-encodable")

config = sanitize_config(config)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if jsonable is false and config was never json-encoded here? Won't this just crash later? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That jsonable field is added because I need to somehow support the binaries that contain bytes. CCCS also noted that it's not JSON-compatible https://github.com/CybercentreCanada/Maco/blob/master/maco/model/model.py#L214.

jsonable is only checked for configuration part, so it won't crash later in Extractor itself but may crash during further processing of configurations (e.g. malduck extract prints JSONs so we need some extra processing there)

jsonable sanity check was made to correct mistakes done by extractor writers. But if we follow the Maco scheme, we can trust that type-checking will help in spotting that kind of errors and bytes will be only under binaries key that can be treated specially.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Assemblyline, we've base64'd any bytes using a custom encoder (Base64Encoder) when dropping files to be shown in the analysis.

Not sure if you guys want to go the same route here, but thought I should mention it 😅

malduck/extractor/extractor.py Outdated Show resolved Hide resolved
@psrok1 psrok1 linked an issue Jul 26, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Output Standardization??
3 participants