-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
PE signature validation doesn't detect malware signed with sigthief #1071
Comments
Do you have a hash of a sample which triggers this? |
Here's a Mimikatz sample where a Microsoft signature has been applied using Sigthief: |
This may be of interest to you too:
|
Thanks! I’ll take a look in a couple of hours. |
Unless I'm not understanding this properly, there is no bug here. The timestamp on the file is Is your issue that the signature doesn't match the binary? If so, that is entirely out of the scope of YARA signature parsing. YARA is currently extracting signature data and exposing it so you can write more precise and expressive rules. At no point has YARA claimed to validate any signatures, which might be where your confusion is coming from. The You're not the first to bring up the point of validation of signatures though. It's something that could be added but I've not done it yet because if YARA tells you the signature is valid I'm concerned people will take it to mean "this is trustworthy", which is clearly not the case. The question of trustworthiness is up to the user and their OS, or whatever is providing the trusted certificate store and it also changes over time as certificates are added or removed from the trusted certificate store. There is an argument to be made that we could maybe have a |
Hi wxsBSD! First and foremost, thank you for looking into this quickly and being opened to the discussion. Based on your response, it seems that we are on the same page :) I'll summarise my position in case that helps in any way: (a) YARA would do well to update the documentation to clearly inform the reader that I've come across several 3rd party YARA rules that seem to have misunderstood this method. It's obviously not YARA's fault, but it's still something where you guys can make a positive difference with very little effort and there seems to be a case for taking action. (b) There's an opportunity for YARA to help the community by offering a way to validate whether a file is properly signed or not, in a similar manner that Numerous security analysts and security products use digital signatures to inform whether a file can be more trusted or not, hence this feature could prove very helpful and popular with the community. Also, it would allow analysts to run searches such as "I'm looking for binaries that are signed with a certificate that looks like it comes from Microsoft, but the signature doesn't match the file". If you think that you could benefit from an additional engineer to help with this task, or other tasks, please ping me privately as we may be able to provide somebody pro-bono later in the year. |
The actual verification of PE signatures, going up the signing chain up to a root certificate trusted by the operating system is a major undertake. In Windows you can simply use the Having said that, we still can consider the |
That’s a good point about it being a glorified checksum that I had not considered. Thanks for pointing it out! |
@plusvic I saw #1623 and hope that it gets merged. It would also address this issue.
Ignoring the terminology (hash vs. checksum) for the moment, it's about making sure that the signed message has not been tampered with, no? The signature certifies that the signed hash (etc.) describes content provided by the signer (as far as the collision resistance of the used hash algo goes, that is). The signer requires a secret key to sign the content and the certificate details are "just" embedded to tie it to some external trusted entity (usually a CA that has verified that the signer is who s/he claims to be). For example there is no technical difference between a "standard" class 3 certificate and an EV certificate. The differences arise from the certificate chain, EKUs set and the OIDs. In a sense these are "logical" differences (just like the judgment whether a particular certificate chain terminates validly).
How? Maybe you could explain this a little further, I don't quite get it. Are you suggesting that collision attacks have become feasible with SHA-256? There should be only two ways to create a valid signature:
Clearly 1. is out (or irrelevant, as we're talking forged signatures). So your claim seems to be that someone is able to take the PE file and replace it by another PE file (minus PE checksum and minus the security directory size and RVA/offset) that will give the exact same hash, right? But a signature can be validated without taking the certificate chain into account. If the hash was tampered with, it won't validate. So the only loophole here is for an attacker to forge a PE file that will give the exact same hash that is already imbued in the signature. So if I use SigThief I can only ever fool very superficial checks like "is there a security directory in this PE image?" or "is the signature of this hash valid?". Neither is sufficient on their own. Code that validates the signature on a given PE would have to (i) compute the hash over the PE image, then (ii) validate the signature on its own and then (iii) tie it together by checking that the computed hash matches the one contained in the signature (i.e. of what has been signed). And only then it's more than a "glorified checksum". But none of this needs to involve the certificate chain. I agree that checking against a certificate chain is probably outside of what Yara could ever hope to offer across all supported target systems, but that would only be the cherry on the top. As a side-note: ELAM drivers can be additionally signed by self-signed certificates which are then later taken into account when protecting user mode processes. In these cases the signatures need to be valid, too, but there isn't even a certificate chain available to check against. |
Ad questions about
In the previous comment. I think it meant, that anyone can compute the correct hashes and make a ''valid'' signature out of them. Now how do you know the signature is trustworthy? You validate the certificate chain up to a point where you reach a point that is already trusted, some root certificate on your system. Now because this is unfeasible to implement within YARA, anyone can create their own fake chain (that they have keys for), bypassing the checks, as the hashes - signature match. And you can't prove that the chain is not trustworthy. |
The previous comment went unnoticed to me, so I didn't respond earlier, but the answer from @HoundThe is exactly what I meant. |
What, how? A different hash invalidates the signature. And to create a new signature you need the private key matching your certificate. So catch 22, right? Please enlighten me. I must be missing some revolutionary new method here how this can be faked. You claim to be able to make valid (or "valid" ... not sure what the distinction is) signatures out of them. I wonder how, in absence of a private key!? If you switch out the hash for another (because you modified the PE file), the signature will no longer validate. And that can indeed be done without any knowledge about the certificate chain. Just by knowing the public key to validate the signature (well, technically it's a little more involved). Now, let's take the quoted statement from @plusvic into account:
If you manage to create a PE file whose contents will yield the exact same hash we all are indeed in trouble. Actually cryptography as a whole and large parts of contemporary digital infrastructure are in big trouble then. It either requires a successful preimage attack or a successful collision attack on SHA-2 with 256 bit digests. You'd be sure to get some attention if you successfully mounted one of those. That's a huge honking if, though. In fact that if is so big (and the chances of it happening soooo tiny) that we are betting on it practically never happening, which is why we decided SHA-2 with 256 bit digests is secure enough for the time being. If you don't get the exact same hash, though? Sorry: that makes the signature invalid. So no fake signatures today.
You seem to be conflating two concepts. One is the validity of the signature, the other is trust. And the validity can be checked by purely technical means and cannot be easily faked (again, unless I am missing something crucial and/or revolutionary here).
... before you haven't done all of these three things, you needn't worry about any details of the certificate or trust chains. And we're talking about point 3 which is currently missing.
No, trust can equally be gained from knowing the public key of the signer. Or really whatever trait (or better yet: traits) you decide. There is no need to involve any CA, even. Just because I can very much decide to trust my own self-signed certificate and happily use that to code-sign software not made by myself. But it makes a whole lot of a difference if the signature is valid or not prior to attempting to establish trust with some CAs.
@plusvic but the argument so far makes no real sense as long as we are talking about Authenticode signatures.
Please explain to me in steps how you can fake valid signatures? Show me a paper describing it or an actual attack that does it. Sure, I could create my own self-signed CA, then issue a certificate that names Microsoft or whatever. However signatures made with that certificate will still require a.) a private key and matching certificate to be created and b.) can still be valid or invalid in the sense described by the initial post. Essentially your claim seems to be that you can transplant a signature from a Microsoft-signed file to another file, re-compute the hash ... switch it out in the signature and be done with it. Well, I claim that the signature will not validate after such tampering. valid != trustedI think that's the core misconception here. But there is very much value in knowing if a signature is at least valid as long as I have access to the thumbprint of the certificate or the public key value of the signer's key pair. You can leave the decision about trust to the users. That's exactly why I brought up the example of the ELAM drivers. The respective signatures are made with self-signed certificates. No CA (or if, then a self-signed not publicly recognized one) involved. However, the binaries are typically also validly signed as far as |
The point was, that without validating the chain, you don't have any trust in the owner of the keys, meaning that you can modify the file, compute a new signature and sign it yourself with your made-up certificates. Of course, I agree that checking for signature validity - if everything matches - is a good thing, that is why the PR exists. But I think the original point was, that a valid signature doesn't mean anything without a trust anchor. But it is of course better than being invalid in the first place. So as you mentioned in the end - valid != trusted. That's why I said you can create a valid signature because you can create corresponding key pairs and certificates such that the certificate is valid, but not trustworthy.
Yes, the root certificate was just an example, you can obviously have different points of trust if you want.
No, I claim I can switch out the Authenticode, and modify the hashes, the signatures, and the corresponding certificate chain. Then it would validate as the signatures are verified with the public key of the signer and its trust is determined with a chain of trust. But again, manipulating the chain would probably result in not a very trustworthy signature, but a valid one. |
Indeed. And I think this data point of being a valid or invalid signature alone is a valuable piece of information. And without validating the signature, any further details about the certificate can't be taken serious. I agree in all other points. Does |
I am not familiar with the PR you linked, maybe you meant #1623? That would offer this kind of validation. |
Thanks, yes I meant #1623. Sorry. Great to hear. |
Closing because this was implemented long ago. |
PE signature validation doesn't detect malware signed with Sigthief.
YARA Rule:
How to reproduce:
1 - Sign Mimikatz using Sigthief
2 - Run the rule provided above against the binary
Expected Results:
YARA reports the binary to be improperly signed.
Current Results:
YARA reports the signature as valid. Probably because the timestamp is valid.
Risk:
It's very likely that dozens of security professionals are using the valid_on() function to try and validate whether a PE is properly signed or not.
Recommendations:
We recommend that the documentation should specify any of the limitations for valid_on(). Also, if YARA could have a way to formally validate whether a binary is properly signed or not, that would be very handy.
The text was updated successfully, but these errors were encountered: