-
Notifications
You must be signed in to change notification settings - Fork 568
feat: Support Windows PE metadata parsing for Python binaries #5159
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
Closed
alex-cheng-techman
wants to merge
5
commits into
intel:main
from
alex-cheng-techman:extract-pe-version-info
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e43d07e
Add PE metadata extraction for Python version in checker
alex-cheng-techman 515dc77
Remove test and backup files from commit
alex-cheng-techman 79e714a
remove openssl.py from PR. see PR #5174
alex-cheng-techman efaf961
fix: update Python checker and version scanner for PE metadata improv…
alex-cheng-techman 18ad411
fix: set more strict python pattern extracting from pe metadata
alex-cheng-techman 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 |
---|---|---|
|
@@ -19,6 +19,9 @@ class PythonChecker(Checker): | |
] | ||
FILENAME_PATTERNS = [r"python"] | ||
VERSION_PATTERNS = [ | ||
# to match the data from PE file | ||
r"[Pp]ython ([0-9]+\.[0-9]+\.[0-9]+)", | ||
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. This one may also cause false positives. |
||
|
||
r"src\\python[23]\\Python-([23]+\.[0-9]+\.[0-9]+)", | ||
r"python(?:[23]+\.[0-9]+)-([23]+\.[0-9]+\.[0-9]+)", | ||
r"pymalloc_debug\r?\n([23]+\.[0-9]+\.[0-9]+)", | ||
|
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
Oops, something went wrong.
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.
I'm pretty sure this will cause false positives (lots of things mention specific versions of openssl in error messages and stuff) so you'll probably need to add whatever string is before or after in the windows binaries to disambiguate.
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.
Pinging @ffontaine who's spent a lot of time tightening our signatures: any recommendations?
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.
Yes, I confirm that this pattern will raise false positives for example with
OpenSSL 1.1.1 or newer
which is embedded in most binaries linking with openssl (see commit 0f7a834).By the way, I'm a bit unconfortable with the current approach.
I see that
extract_version_from_pe
is constructing a fake line from 3 PE fields:ProductName ProductVersion CompanyName
Then this fake line is passed to binary checkers which are updated to handle this fake line.
This is definitely "hacking" the binary checker logic.
IMHO, making a language parser to extract PE information could be a better approach.
In this PE language parser, specific PE handling could be done such as adding a regex to extract
([0-9]+\.[0-9]+\.[0-9]+)
from ProductVersion.The user could also easily disable this new handling if they are not happy with the results.
An other option would be to just update the python and openssl patterns so that they work with your windows file.
If you can provide the pe windows file that fails to be detected, I could probably help you.