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

Improve shellbags plugin #470

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

JSCU-CNI
Copy link
Contributor

@JSCU-CNI JSCU-CNI commented Dec 6, 2023

A target system can contain non-utf-8 characters in a shellbag volume volume_name. This would break the shellbags plugin and is now fixed by escaping using backslashreplace.

A target system can contain non utf-8 characters in the shellbag volume_name.
This would break the shellbags plugin and is now fixed.
@@ -617,7 +617,7 @@ def __init__(self, buf):
if self.type == 0x2E:
self.identifier = uuid.UUID(bytes_le=buf[4:20].tobytes())
else:
self.volume_name = self.fh.read(20).rstrip(b"\x00").decode()
self.volume_name = self.fh.read(20).rstrip(b"\x00").decode(errors="backslashreplace")
Copy link
Member

Choose a reason for hiding this comment

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

Would a surrogateescape not be preferred?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I remember correctly surrogateescape does not work with ASCII incompatible encodings. Why would you prefer surrogates in this instance?

Copy link
Member

Choose a reason for hiding this comment

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

We use surrogateescape everywhere else and it's also the default error mode for filesystems. I'm not aware of any limitations with surrogateescape, do you have an example of that?

I'm definitely not an expert on decoding error modes, so I'm mostly going by with what I know works and what we use elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using surrogateescape here would not repair the shellbags plugin. You would still get the following error UnicodeDecodeError: 'utf-8' codec can't encode characters in position x-y: surrogates not allowed when encoding the record for the record stream. (https://stackoverflow.com/a/31898719)

Copy link
Member

Choose a reason for hiding this comment

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

TIL, thanks for the explanation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the status of this review? Do you propose a fix in flow.record?

Copy link
Contributor

@pyrco pyrco Feb 6, 2024

Choose a reason for hiding this comment

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

Yes, this should be fixed in flow.record. Unfortunately, there is no easy single spot there to fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could this be merged in the meantime?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather not, as it would deviated from all other places that use errors="surrogateescape"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When you compare the two in the dissect.target codebase I think it would be incorrect to state that surrogateescape is the de facto 'default'.

https://github.com/search?q=repo%3Afox-it%2Fdissect.target+surrogateescape&type=code
https://github.com/search?q=repo%3Afox-it%2Fdissect.target%20%22backslashreplace%22&type=code

I agree it would be nice if this gets a proper fix in flow.record eventually. Our current situation is that the shellbags plugin is broken as no encoding error handler is used when dealing with foreign volume names.

Using surrogateescape would still break the shellbags plugin as it is currently incompatible with flow.record. Not using any error handling keeps this plugin broken for us.

In my opinion using errors=backslashreplace is better than using no error handler at all. Please consider merging this as a temporary solution while we wait for a better fix in flow.record.

@JSCU-CNI JSCU-CNI mentioned this pull request Feb 1, 2024
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.

None yet

3 participants