-
Notifications
You must be signed in to change notification settings - Fork 3
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
Error when scanning JAR files containing AppleDouble metadata #6
Comments
Thanks for the report. I think an easy way to solve this is to listen for this specific error and treat it as "clean". |
As in, ignore any The main concern I have about ignoring errors from class files is that we don't want to provide a way for bad actors do hide or "disguise" malicious class files by naming them in a certain way or by doing some bytecode trickery. |
If the magic value is wrong, the file wouldn't be loaded as a class by the JVM as far as I'm aware. |
Yeah, that seems reasonable to assume. |
The program could of course somehow load this file, modify it in memory, and then read it as a class but detecting that is the job of the signature and out of scope for the detector to do itself. |
Related to MCRcortex/nekodetector#53
I was scanning some JAR files and noticed that one of them resulted in an error from the detector:
Error: Invalid MAGIC value
.Error: Invalid MAGIC value
Error: Invalid MAGIC value
Error: Invalid MAGIC value
Error: Invalid MAGIC value
Error: Invalid MAGIC value
The file in question is this one: https://www.curseforge.com/minecraft/mc-mods/terralith/files/3696607
The
Error: Invalid MAGIC value
seems to come from here: https://github.com/leonardosnt/java-class-tools/blob/4e632bf8fafa89243c3b0e2786a4fe496864f262/src/java-class-reader.js#L36-L39Why does this happen?
Because the Terralith JAR (and many other JARs on CurseForge etc) was created on macOS, and was not properly stripped of AppleDouble metadata. For reference, see:
https://en.wikipedia.org/wiki/AppleSingle_and_AppleDouble_formats
https://en.wikipedia.org/wiki/Resource_fork
So those JARs contain
.class
files which are not real class files, they just contain Apple metadata. Which is why we get an error when trying to scan those class files.Potential solutions
Perhaps the scanning tool could exclude all files in the
__MACOSX
directory. But I think that could provide a place for bad actors to hide infected class files, since__MACOSX
is a valid Java package name, so excluding that directory seems like a bad idea.Another idea could be to exclude the metadata files based on the fact that they start with
._
. To my knowledge, a valid Java class name can't contain the.
character, but I don't want to say that I'm 100% sure what the rules are on a bytecode level.Yet another idea would be to do some error handling and make sure that the scanning tool still continues to scan all other classes even if it runs into some invalid class files. Maybe it already does this (?), I did not look at the code in detail. But even if the scanning tool already does this, I think it would be a good idea to provide some more helpful information to the end user when they scan a JAR file and it contains invalid class files that lead to errors. Like, what does that mean ("is my JAR file infected or not?"), and what action should the user take?
The text was updated successfully, but these errors were encountered: