I have a custom enterprise antivirus software on Windows (Symantec Endpoint Protection) that just decided to quarantine my ocaml.exe (apparently a somewhat old 4.x version, in case that’s relevant).
I remember reading somewhere about the OCaml Windows team proactively trying to avoid such issues, but I don’t remember if it was related to Windows Defender only, and if that is still being done.
Some colleagues suggested that I submit the quarantined ocaml.exe to https://symsubmit.symantec.com as a false positive.
I’d like to know if:
Is this already being done by someone?
Do you know if that’s not a waste of time? For instance, if the executable is freshly compiled and with a unique hash, that’s going to be less helpful for the antivirus database.
It could also be that my computer’s signature database is out-of-date, and this does not happen for others.
It could be. Nim has been dealing with this issue in both their toolchain and binaries generated with it, since it got slightly popular among malware writers, and years later they keep getting falsely flagged by AV vendors. They even automated a VirusTotal scan during CI to catch false positives sooner.
However, there’s not much else one can do. Programs using unpopular toolchains are less represented in the datasets used to train classifiers, so one either submits them to improve their datasets or tweaks the codegen until it stops getting falsely flagged.
The irony of this is that malware writers could just as well do that… In fact, they’d be even more more motivated to do so to tweak their true positive into a false negative.
non-relocatable OCaml (ie. hardcoded paths in executables)
means varying hashes; submitting your ocaml.exe will be fairly useless.
On the other hand, you can use relocatable OCaml (generally available in 5.5+) and fetch prebuilt OCaml distributions. I believe dune pkg does both, but unfortunately I don’t think it is available for Windows. But Announcing the first release of Alice, a radical OCaml build system should work on Windows and I suspect it has stable hashes even if I haven’t used it.
I also mentioned another solution last month at Dk builds with relocatable OCaml. Since that was addressed to package maintainers, here is how you would get OCaml binaries with stable hashes:
Click here if trying inside Windows Sandbox (recommended!)
# Mitigate https://github.com/diskuv/dk/issues/106
curl.exe -L -o "vc_redist.x64.exe" "https://aka.ms/vs/17/release/vc_redist.x64.exe"
Start-Process -FilePath ".\\vc_redist.x64.exe" -ArgumentList "/install", "/passive", "/norestart" -Wait
# Mitigate: Program 'ocaml.exe' failed to run: An Application Control policy has blocked this file
reg add "HKLM\System\CurrentControlSet\Control\CI\Policy" /v VerifiedAndReputablePolicyState /t REG_DWORD /d 0 /f
CiTool.exe -r
I haven’t had time to fix my OpamVenv tool which creates a binary-backed opam switch for normal development (ex. dune build --watch on your packages). More importantly, few people seem interested in binary builds. +1 to OpamVenv@1.1.22 broken · Issue #107 · diskuv/dk · GitHub if anyone is interested.
Have you considered signing the OPAM build? A file downloaded from the internet, without a code signature is likely to be treated as more suspicious than one that has a code signature that chains back to one of the CAs that Windows trusts for code signing.
There are open source tools for code signing, although you’ll need to get a certificate.
There is a Linux Foundation project with an apparently free to use CA Sigstore , but I don’t know whether it’ll chain back to (or is cross-signed by) a CA trusted by Windows (according to the above blogpost there are only 4 roots: 2 Microsoft, 1 Thawte, and 1 Verisign).
Although this approach won’t help for the ocaml.exe built by opam, that is built locally, and will have different contents each time, so can’t be signed ahead of time.
That can be useful if the result is clean. However if any of scanners finds a malware (in an otherwise clean sample, so a false positive), then virustotal will automatically submit the sample as malicious to the other AV vendors that didn’t catch it, and fairly soon more and more will start detecting it.
If most of the submissions are clean then maybe it’ll help, although if most of them turn up as malicious that’ll make it more likely that one AV vendor will begin recognizing (an otherwise non-malicious, but probably unique to your language) a pattern. So I wouldn’t fully automate VirusTotal submissions, or if you do, keep a close eye on the results.
I don’t know what other AV vendors would do, but if this happens on ClamAV, it might help there.
I think I added long ago some version of OCaml to its “known-clean” set that is used to test every new signature/pattern update before it is being pushed to users.
Even if your ocaml.exe is not identical, having it in the “false positive / known clean set” can help avoid matches from new heuristic signatures, and new generic pattern signatures (for ClamAV the publication process would automatically reject signatures that match the clean set).
Although you’ll first need the AV vendor(s) to trust that your FP submission is genuine, and if it is an executable you’ve built yourself in a non-reproducible way, and is not publicly downloadable from a reputable source then that’ll be difficult.
We have our own signing infrastructure (gpg, see our github release notes). I didn’t know how code signing work on Windows but reading your description i’m not exactly excited about it. I’m not sure it’s worth the hassle
On Windows (and I think Mac OS) code signing is built into the OS, so although GPG signatures can be useful for end users wanting to verify the code, the OS will still consider these unsigned, and not trust them.
We reserve the right to enforce the implementation of additional best practices in the future, such as the generation of SBOM files, as the industry adoption progresses
and they can
pause or terminate the subscription without prior notice
Still, it might be a solution in the short term.
I’m not a Windows developer or user, so I’d suggest to gather feedback on how important this would be from those who use it. Meanwhile maybe we could move the above list of “how to do code signing on Windows for an open source project for free” into an issue on opam, so that you’d have it easily available should you decide that you need it in the future.