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

Set correct PE checksum for .exe files (helps with virus false-positives) #5579

Closed
The-Compiler opened this issue Feb 22, 2021 · 12 comments · Fixed by #5580
Closed

Set correct PE checksum for .exe files (helps with virus false-positives) #5579

The-Compiler opened this issue Feb 22, 2021 · 12 comments · Fixed by #5580
Assignees
Labels
feature Feature request

Comments

@The-Compiler
Copy link
Contributor

The-Compiler commented Feb 22, 2021

Is your feature request related to a problem? Please describe.
As you've probably all seen before, virus scanner false-positives are a recurring problem for PyInstaller-generated executables, as well as PyInstaller's bootloader (see e.g. #5490, #5474, #5479, ...).

One piece of information virus scanners seem to use is the PE checksum. Quoting from that article:

  • 83% of malware had invalid checksums
  • 90% of legitimate files had valid checksums.

It looks like anything generated from PyInstaller (as well as the Windows bootloader in the release?) seems to have a checksum of 00 00 00 00, which is thus invalid.

Describe the solution you'd like
PyInstaller should set a correct PE checksum. This is possible using pefile, which it already seems to depend on:

import pefile
pe = pefile.PE('filename.exe')
pe.OPTIONAL_HEADER.CheckSum = pe.generate_checksum()
pe.close()
pe.write('filename.exe')

(You can use pe.verify_checksum() to verify that it is correct)

After doing this, e.g. PyInstaller's Windows-64bit/runw.exe (in the 4.2 release) goes down from 12 false-positives to only 5 - most notably, McAfee and Avast (which are the two affected engines I've actually heard of before...) now are happy with the file.

Doing this with my own project (which is built with PyInstaller), @bitraid found that:

the number of false positives for v2.0.2 goes down from 31 to 7. Similarly v2.0.0 goes down to 6 from 29 and v2.0.1 goes down to 8 from 15.

Describe alternatives you've considered
Submitting false-positive reports to antivirus vendors. A pain.

Also, doing this after PyInstaller has generated the exe - that works, but it seems to me like this should be done in PyInstaller itself.

Additional context
See qutebrowser/qutebrowser#6194

@bwoodsend
Copy link
Member

Ah yes! Nice one. How that makes an executable any more trustworthy seeing as anyone could do it is beyond me but if it shuts up the bogus AV software then great.

@bwoodsend
Copy link
Member

@The-Compiler Fancy making the changes or shall I?

@The-Compiler
Copy link
Contributor Author

The-Compiler commented Feb 22, 2021

Feel free! I don't think I've contributed before (looks like I did 😆)

I'm not really sure what the best place for such a change would be - but I also try to avoid working on Windows stuff if I can, so if you don't mind, go ahead. 👍

@bwoodsend
Copy link
Member

Alright then. I'll blow the cobwebs off my own Windows partition and do it...

@bwoodsend bwoodsend self-assigned this Feb 22, 2021
The-Compiler added a commit to qutebrowser/qutebrowser that referenced this issue Feb 22, 2021
This should help with virus scanner false positives.

See pyinstaller/pyinstaller#5579
Fixes #6081
Fixes #6194
The-Compiler added a commit to qutebrowser/qutebrowser that referenced this issue Feb 22, 2021
This should help with virus scanner false positives.

See pyinstaller/pyinstaller#5579
Fixes #6081
Fixes #6194

(cherry picked from commit 2b91081)
bwoodsend added a commit to bwoodsend/pyinstaller that referenced this issue Feb 22, 2021
Windows executables contain an optional checksum to protect
against corruption. It turns out that several of antiviral programs
raise false positives if this checksum is missing or wrong.
Setting this checksum appeases McAfee and inconsistently fixes
MS Defender which are probably the most common (and also dumbest)
AVs for Windows.
bwoodsend added a commit to bwoodsend/pyinstaller that referenced this issue Feb 22, 2021
Windows executables contain an optional checksum to protect
against corruption. It turns out that several of antiviral programs
raise false positives if this checksum is missing or wrong.
Setting this checksum appeases McAfee and inconsistently fixes
MS Defender which are probably the most common (and also dumbest)
AVs for Windows.
bwoodsend added a commit to bwoodsend/pyinstaller that referenced this issue Feb 22, 2021
Windows executables contain an optional checksum to protect
against corruption. It turns out that several of antiviral programs
raise false positives if this checksum is missing or wrong.
Setting this checksum appeases McAfee and inconsistently fixes
MS Defender which are probably the most common (and also dumbest)
AVs for Windows.
bwoodsend added a commit to bwoodsend/pyinstaller that referenced this issue Feb 22, 2021
Windows executables contain an optional checksum to protect
against corruption. It turns out that several of antiviral programs
raise false positives if this checksum is missing or wrong.
Setting this checksum appeases McAfee and inconsistently fixes
MS Defender which are probably the most common (and also dumbest)
AVs for Windows.
bwoodsend added a commit to bwoodsend/pyinstaller that referenced this issue Feb 22, 2021
Windows executables contain an optional checksum to protect
against corruption. It turns out that several of antiviral programs
raise false positives if this checksum is missing or wrong.
Setting this checksum appeases McAfee and inconsistently fixes
MS Defender which are probably the most common (and also dumbest)
AVs for Windows.
Legorooj pushed a commit that referenced this issue Feb 23, 2021
Windows executables contain an optional checksum to protect
against corruption. It turns out that several of antiviral programs
raise false positives if this checksum is missing or wrong.
Setting this checksum appeases McAfee and inconsistently fixes
MS Defender which are probably the most common (and also dumbest)
AVs for Windows.
@bwoodsend
Copy link
Member

I've done it (#5580). EXEs built by PyInstaller will now have the checksum set. The bootloaders won't until we rebuild them so unless you rebuild the bootloaders yourself, there is no point submitting those to virustotal yet. Instead submit your built applications. I have tried rebuilding a bootloader then submitting it and it came back all green.

bwoodsend pushed a commit to bwoodsend/pyinstaller that referenced this issue Feb 23, 2021
   
Switched the CLI to improve the user experience.
Fixes issue pyinstaller#5579
@andyshinn
Copy link

andyshinn commented Feb 27, 2021

I tried with the new PE changes and it's still blocked in Defender and flagged by a bunch in Virus Total, unfortunately.

https://www.virustotal.com/gui/file/a70a7c7b5682abe70dfe7bd186e6f48b636e2a59908bcbdfc0184a4e52cc1635/detection

@Legorooj
Copy link
Member

Interesting, using commit f078351, I get the following result:

https://www.virustotal.com/gui/file/f5587397e6ce11d659e3b4cfe1637991b9b5547a3f280873ef48948e606f7434/detection

Just a build of print('Hello world!') as a onefile was what I used.

@Legorooj
Copy link
Member

Legorooj commented Feb 27, 2021

@sjackman that's Internet Archive flag is on version 3.6... a little out of date.

@srkn
Copy link

srkn commented Mar 23, 2021

I've done it (#5580). EXEs built by PyInstaller will now have the checksum set. The bootloaders won't until we rebuild them so unless you rebuild the bootloaders yourself, there is no point submitting those to virustotal yet. Instead submit your built applications. I have tried rebuilding a bootloader then submitting it and it came back all green.

Would you please give a little more detail regarding this? How should we rebuild bootloader to prevent being flagged as malware?

@bwoodsend
Copy link
Member

Rebuilding the bootloader only affects people who can't install pyinstaller. If that includes you then the docs are here.

wlach added a commit to mozilla/mozregression that referenced this issue May 6, 2021
Has a change that should help with anti-virus false-postiives on
Windows: pyinstaller/pyinstaller#5579
wlach added a commit to mozilla/mozregression that referenced this issue May 7, 2021
Has a change that should help with anti-virus false-postiives on
Windows: pyinstaller/pyinstaller#5579
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants