by cpgxiii · 6y ago · 0 comments
1) Take signed .MSI
2) Add my JAR of malware to the end of it
3) Send file to target
4) Target's computer recognizes the file as a signed MSI, ignoring the extra stuff at the end that's not part of the MSI
5) Target computer calls the JRE to launch the JAR
6) JRE ignores the MSI parts at the beginning of the file because compressed JAR files are loaded back-to-front
Obviously a major bug that signature validation ignores "extra" parts of the file, but a signature validation bug that (1) only affects specific types of files executed by a third-party runtime and (2) doesn't threaten system files (or any native executables at all) isn't an obviously critical vulnerability like an arbitrary "signature validation is totally broken" bug.
e: or any signed MSI from a compromised system, like happened to Palemoon last year: https://news.ycombinator.com/item?id=20435699
Endless rabbit-hole of course but that's already a lot of low-hanging fruit
Think of the legitimate MSI and malicious JAR files as separate short stories in the same book. The 'book' comes to your computer claiming to be one thing (the legitimately signed MSI) but the second chapter is something completely different (the malicious jar file). When your computer reads the book (calculates and verifies the signature) it only does it off the first chapter. That lets the second part slide under the additional scrutiny Windows applies to files downloaded from the Internet.
However, this blog post mentions that various security solutions trust the windows code signing, but it does not mention which ones - https://blog.virustotal.com/2019/01/distribution-of-maliciou...
- Headers describing a section, including the length of a section.
- Prefixing each section with a size.
- Using a marker pattern (such as a null byte) to mark the end of a section of data.
(there are more than these three, but these are the most common)
That last one isn't used very often, and when it is, it's mostly for textual data.The consequence of using the first two techniques is that it's entirely possible to add data to the end of the format, since a parser would just read the last section and stop (assuming the format supports knowing what the last section is).
1) Take MicrosoftSigned.Msi
2) Append Malway.jar to it
3) Take file and rename it as RunMe.Jar
# Now you have a jar file that appears to be signed by Microsoft but contains malways.
4. Give target RunMe.jar and ask then to dbl-click it.
# Usually this file would prompt the user with a "You shouldn't trust this arbitrary file from the internet" prompt, but it doesn't because Windows thinks this file is correctly signed
5. Target is now infected
Or, even better, simultaneously put a silent drive-by browser zero-day in a website they visit regularly, like https://googleprojectzero.blogspot.com/2019/08/a-very-deep-d...
The attacker can drop/ exec files as they please, regardless of whether they're signed.
Anyone can feel free to correct me.
I know this can be done w/ Cat.
--Wow, so JAR files are read from bottom top so it literally masquerades.
That's interesting.
Zips can also be read from front to back, reading the header of each entry and skipping the compressed data to the next header, which is most of what zip repair utilities do (or did, not sure anyone repairs zips any more). But it's faster to read the index.
And to be clear, jars are zip files.
If they do claim it then they should properly verify signatures
Either way is wrong.
That's crazy the signature check wouldn't verify the file length.
Windows still sees it as a MSI file while doing signature checking. But because it has a .jar extension, the JRE runs it when you double click.
Signature verification is done as a independent check, completely separate from execution. Because windows needs to know the signature is valid before even allowing the file to be executed. It also needs to show the signature check in the right-click -> properties dialog.
'Quintero said this weakness would particularly acute if an attacker were to use it to hide a malicious Java file (.jar). And, he said, this exact attack vector was indeed detected in a malware sample sent to VirusTotal.
“In short, an attacker can append a malicious JAR to a MSI file signed by a trusted software developer (like Microsoft Corporation, Google Inc. or any other well-known developer), and the resulting file can be renamed with the .jar extension and will have a valid signature according Microsoft Windows,” Quintero wrote.'
In terms of practical impact, it sounds like you need a target where the JAR file will be run, but also where you'd expect Windows signatures validation alone to protect against malicious Jars.
Here are twenty-three of them to get you started: https://github.com/arntsonl/calc_security_poc
One of the top ranking hackthebox players summarized PlayerTwo quite neatly [1].
[1] https://www.youtube.com/watch?v=u_GkIzCmU90 (13 min.)
Funnily enough this is exactly how real attacks tend to work https://googleprojectzero.blogspot.com/2019/08/a-very-deep-d...