-
Notifications
You must be signed in to change notification settings - Fork 90
WIP: add support for MSI #1244
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
Open
jcrussell
wants to merge
4
commits into
onekey-sec:main
Choose a base branch
from
jcrussell:msi
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
WIP: add support for MSI #1244
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| """MSI Handler | ||
|
|
||
| Extracts uses 7z for now. Could migrate to fully implementation: | ||
|
|
||
| https://github.com/nightlark/pymsi | ||
| """ | ||
|
|
||
| from typing import Optional | ||
| import io | ||
|
|
||
| import pymsi | ||
| from structlog import get_logger | ||
|
|
||
| from unblob.extractors import Command | ||
|
|
||
| from ...models import ( | ||
| File, | ||
| Handler, | ||
| HandlerDoc, | ||
| HandlerType, | ||
| HexString, | ||
| Reference, | ||
| ValidChunk, | ||
| ) | ||
|
|
||
| logger = get_logger() | ||
|
|
||
|
|
||
| class MsiHandler(Handler): | ||
| NAME = "msi" | ||
|
|
||
| PATTERNS = [ | ||
| HexString("D0 CF 11 E0 A1 B1 1A E1") | ||
| ] | ||
| EXTRACTOR = Command("7z", "x", "-p", "-y", "{inpath}", "-o{outdir}") | ||
|
|
||
| DOC = HandlerDoc( | ||
| name="MSI", | ||
| description="Microsoft Installer (MSI) files are used for the installation, maintenance, and removal of software.", | ||
| handler_type=HandlerType.ARCHIVE, | ||
| vendor="Microsoft", | ||
| references=[ | ||
| Reference( | ||
| title="MSI File Format Documentation", | ||
| url="https://docs.microsoft.com/en-us/windows/win32/msi/overview-of-windows-installer", | ||
| ) | ||
| ], | ||
| limitations=[], | ||
| ) | ||
|
|
||
| def calculate_chunk(self, file: File, start_offset: int) -> Optional[ValidChunk]: | ||
| file.seek(start_offset, io.SEEK_SET) | ||
|
|
||
| try: | ||
| # TODO: pymsi wants a path or BytesIO | ||
| buf = io.BytesIO() | ||
| buf.write(file[:]) | ||
| buf.seek(0) | ||
|
|
||
| package = pymsi.Package(buf) | ||
| msi = pymsi.Msi(package, True) | ||
| except Exception: | ||
| return None | ||
|
|
||
| # MSI moves the file pointer | ||
| msi_end_offset = buf.tell() | ||
|
|
||
| return ValidChunk( | ||
| start_offset = start_offset, | ||
| end_offset = msi_end_offset, | ||
| ) | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is not right. If you look at the output directory when run on the 7z MSI, you'll see that it carves two chunks:
Looking into the
unknownchunk, we see information that belongs to theSummaryfield:You can check that by opening the file in https://pymsi.readthedocs.io/en/latest/msi_viewer.html and looking at the Summary tab.
I know very little about the MSI format, but looks like the end offset could be calculated based on the OLE format that the MSI is made off. Probably some magic involving sector sizes and sector counts.