1 00:00:04,760 --> 00:00:11,020 All right, everyone. Thanks for coming out. I really appreciate everyone being here. Let's get started. 2 00:00:16,020 --> 00:00:23,240 Hey, everyone. Thanks for coming out. Although this is not my first Black Hat talk, it is the first time I'm speaking in person. 3 00:00:23,800 --> 00:00:28,820 I'm really, really, really excited to be here. Let's get started. 4 00:00:37,840 --> 00:00:48,820 One second. Wardrobe malfunction. Hold on. All right. Just kidding, of course. I'm really honored to be here. 5 00:00:48,980 --> 00:00:59,520 It's my third time at DEF CON. Unfortunately, I was under the age of 21, so I wasn't able to partake in the shot celebration for speakers. 6 00:01:00,000 --> 00:01:10,760 But I was this year. So a bit of background. My name is Bill Demerkoppa, and I'm a researcher for the Microsoft Security Response Center. 7 00:01:11,200 --> 00:01:16,460 While working full-time, I'm also a full-time student at the Rochester Institute of Technology. 8 00:01:17,100 --> 00:01:26,400 I have a relatively diverse background in offensive and defensive security, but my specialization is low-level operating system internals with a focus on Windows. 9 00:01:30,000 --> 00:01:37,940 In this talk, we'll be exploring my work into digital signatures, specifically the implementation issues I found with them. 10 00:01:38,260 --> 00:01:49,740 We'll start with some background on how digital signatures are validated, approaches for attacking them, which will tie into the systemic flaw I found, and its impact on the broader ecosystem. 11 00:01:50,740 --> 00:01:59,380 A quick disclaimer. We'll be discussing several first and third-party vulnerabilities in this talk. Everything you see here today is patched. 12 00:01:59,380 --> 00:02:02,020 We will not be dropping zero days, unfortunately. 13 00:02:05,000 --> 00:02:09,200 All right. So how are digital signatures validated in the real world? 14 00:02:12,000 --> 00:02:22,100 A digital signature is used to verify that a message, document, or software comes from a specific sender and hasn't been altered during transmission. 15 00:02:23,040 --> 00:02:28,980 This is done by creating a hash of the message and then encrypting that hash with the sender's private key. 16 00:02:29,680 --> 00:02:38,520 A digital certificate, on the other hand, is a digital document issued by a trusted third party, known as a certificate authority or CA. 17 00:02:39,160 --> 00:02:47,100 It contains the public key corresponding to the sender's private key as well as information about the identity of the sender. 18 00:02:48,080 --> 00:02:53,640 In order to validate a digital signature, the recipient needs to have the sender's public key. 19 00:02:54,140 --> 00:02:59,360 The problem is if the sender simply sent their public key along with their message, the sender will not be able to verify it. 20 00:02:59,380 --> 00:03:05,360 there's no way for the recipient to know for sure that the public key really belongs to the 21 00:03:05,360 --> 00:03:12,440 sender. By containing the sender's public key and being digitally signed by a trusted third 22 00:03:12,440 --> 00:03:18,560 party CA, a digital certificate confirms that the public key really does belong to that sender. 23 00:03:22,780 --> 00:03:29,100 Root certificate authorities are responsible for identity verification of individuals and 24 00:03:29,100 --> 00:03:36,440 organizations requesting a certificate. For digital signatures to work in practice, we need 25 00:03:36,440 --> 00:03:42,000 these organizations that we can rely on in order to establish a chain of trust for digital 26 00:03:42,000 --> 00:03:51,240 certificates. Who verifies the root CAs? They come preinstalled. They're responsible for identity 27 00:03:51,240 --> 00:03:56,600 verification but, for example, in the screenshot below, you can see the Windows trusted 28 00:03:56,600 --> 00:03:59,080 root store. These are the authorities that are responsible for identity verification. The 29 00:03:59,100 --> 00:04:02,940 authorities that come with the operating system and provide a reference point for digital 30 00:04:02,940 --> 00:04:15,440 signature validation. So how is a digital certificate verified? Through the chain of trust. 31 00:04:16,180 --> 00:04:21,980 Remember the trusted root CAs that come with your machine? We can verify if a digital 32 00:04:21,980 --> 00:04:28,960 certificate is legitimate by checking if it chains up to one of these trusted CAs. In practice, 33 00:04:29,100 --> 00:04:37,340 the root CAs verify the intermediate CAs, which then verify your end entity or server certificate and 34 00:04:37,340 --> 00:04:49,640 allow us to determine the legitimacy of a signed digital message. So let's go through a simplified 35 00:04:49,640 --> 00:04:55,580 example of what verifying an executable looks like on Windows under the Authenticode specification. 36 00:04:56,700 --> 00:04:59,080 First, we need to generate an authentication code for the root CAs. The root CAs verify the 37 00:04:59,080 --> 00:04:59,420 code you have. The root CAs will be provided by the process editor, and you can find the 38 00:04:59,420 --> 00:05:03,960 Turkish language, also known as an authentic code hash, or a digest. We start by hashing the 39 00:05:03,960 --> 00:05:10,860 PE headers of the executable. Note that some fields, like the security directory entry and 40 00:05:10,860 --> 00:05:18,840 checksum, are intentionally excluded. Next, we sort every PE section by their file offset in the 41 00:05:18,840 --> 00:05:26,300 sending order and hash their contents. If there is any extra data after the PE sections and before 42 00:05:26,300 --> 00:05:29,060 the security directory, this is added to the hash. We use the default HTTP code we have in the 43 00:05:29,060 --> 00:05:36,640 hash as well. Once we calculate the hash we can extract the encrypted digest from the security 44 00:05:36,640 --> 00:05:43,360 directory which contains the authentic code signature. We decrypt and compare this hash with 45 00:05:43,360 --> 00:05:48,740 the one we calculated and at this point we validated that the authentic code signature is 46 00:05:48,740 --> 00:05:55,440 valid and the last thing we need to do is verify the certificate and the chain of trust. Does 47 00:05:55,440 --> 00:06:01,440 the certificate link to a certificate authority we know about? And that's about it. At least 48 00:06:01,440 --> 00:06:09,460 from a high level. Let's talk a little bit about how one can go about attacking digital 49 00:06:09,460 --> 00:06:19,900 signatures. So a quick history recap. Since 1996 MD5, the use of the MD5 algorithm has been 50 00:06:19,900 --> 00:06:25,420 discouraged due to its inherent weaknesses. For example in 2004 we saw the five year 51 00:06:25,440 --> 00:06:32,080 first publication of an MD5 collision. Researchers were able to generate two distinct files 52 00:06:32,080 --> 00:06:41,140 that resulted in the same MD5 hash. In 2008 the researchers abused known MD5 weaknesses to 53 00:06:41,140 --> 00:06:47,580 generate a malicious certificate authority with a valid chain of trust. And using a chosen 54 00:06:47,580 --> 00:06:55,420 prefix collision they were able to create a rogue intermediate CA with the same MD5 hash as a 55 00:06:55,440 --> 00:07:03,320 an end entity certificate. In other words something like an SSL certificate. In 2011 we saw a 56 00:07:03,320 --> 00:07:11,540 breach of the digital noter CA and in 2012 the flame malware abused chosen prefixes like the 57 00:07:11,540 --> 00:07:24,100 2008 rogue CA attack that let them generate a fake Microsoft CA. So what type of attacks are 58 00:07:24,100 --> 00:07:29,760 relevant for digital signatures? Well we have three broad categories that are generally 59 00:07:29,760 --> 00:07:35,860 applicable to a lot more than just signatures. Let's break these down. First we have memory 60 00:07:35,860 --> 00:07:40,740 corruption issues. These are your classic out of bounds read write or stack overflow 61 00:07:40,740 --> 00:07:47,260 vulnerabilities that can often arise from the mishandling of untrusted data. How do we find 62 00:07:47,260 --> 00:07:53,900 them? Typically manual or guided analysis as well as fuzzing are good strategies. How do we 63 00:07:53,900 --> 00:08:00,640 fix them? Well one of the best advice I can give is to minimize your attack surface. Limit the 64 00:08:00,640 --> 00:08:07,060 code that processes untrusted data. You can also use various mitigations or memory safe 65 00:08:07,720 --> 00:08:16,000 programming languages like rust to substantially reduce your risk to these issues. Next we have 66 00:08:16,000 --> 00:08:23,880 logic flaws. These are highly context specific issues that vary by application. How do we fix 67 00:08:23,900 --> 00:08:29,160 them? Manual or guided analysis. These issues require a decent understanding of the 68 00:08:29,160 --> 00:08:38,480 application's design and intended usage. For example, look for differences in logic and between a 69 00:08:38,480 --> 00:08:45,420 design document and the actual implementation. How do we prevent them? Well again, minimizing the 70 00:08:45,420 --> 00:08:51,900 code that processes the untrusted data is a good place to start. Having a test suite of expected 71 00:08:51,900 --> 00:08:53,880 outcomes are another good way to minimize the code that processes the untrusted data. This is a good 72 00:08:53,900 --> 00:09:00,080 way to prevent regressions and validate design assumptions. We also have cryptographic flaws. 73 00:09:00,400 --> 00:09:05,480 These are different than the implementation issues we just discussed in that they exist in a 74 00:09:05,480 --> 00:09:11,420 cryptographic algorithm. How do we find them? Typically this involves mathematical analysis of 75 00:09:11,420 --> 00:09:16,560 algorithms to ensure things like preimage resistance, second preimage resistance, and strong 76 00:09:16,560 --> 00:09:23,500 collision resistance. How do we prevent them? Well for most the golden rule is just don't rule your own crypto. 77 00:09:23,900 --> 00:09:36,000 don't deviate from the specification that you're implementing. So writing cryptographic 78 00:09:36,000 --> 00:09:41,740 systems is challenging due to their inherent complexity. Cryptographic implementations 79 00:09:41,740 --> 00:09:47,260 aren't isolated. They interact with a multitude of other systems, protocols and software. 80 00:09:48,460 --> 00:09:54,080 Patching implementation issues can get complicated as well. For example, like one reason 81 00:09:54,080 --> 00:10:00,860 why XYZ insecure future, let's say MD5, is difficult to get rid of is because if you simply 82 00:10:00,860 --> 00:10:08,120 prevented its use entirely, you may break legacy systems and applications. Memory corruption is 83 00:10:08,120 --> 00:10:13,980 better understood. Logic flaws are much harder to prevent as they are context specific. 84 00:10:20,160 --> 00:10:24,220 Let's review the different types of signing certificates and the minimum requirements for 85 00:10:24,220 --> 00:10:30,540 obtaining them. First, we have regular SSL certificates used to secure your connection with 86 00:10:30,540 --> 00:10:37,860 a web server. At a minimum, you need to prove that you own the domain that you're requesting the 87 00:10:37,860 --> 00:10:44,100 certificate for. This can involve adding a DNS record or serving a provided file over HTTP. 88 00:10:45,220 --> 00:10:47,240 S-MIME certificates are used to secure your connection with a web server. S-MIME certificates 89 00:10:47,240 --> 00:10:51,960 are used for securing e-mail communications, like SSL certificates. You need to prove that you 90 00:10:51,960 --> 00:10:56,800 own the e-mail address that you're requesting a certificate for, which can include the identity 91 00:10:56,800 --> 00:11:08,320 of yourself or your organization. We also have code signing certificates. These are used to 92 00:11:08,320 --> 00:11:15,060 maintain the integrity of your software. Unlike S-MIME certificates, the bar for obtaining one is 93 00:11:15,060 --> 00:11:17,220 substantially higher. S-MIME certificates are used to maintain the integrity of your software. 94 00:11:17,220 --> 00:11:24,020 As we'll soon discuss, you will almost always need to verify your identity or the legitimacy of 95 00:11:24,020 --> 00:11:30,780 your organization. Finally, we also have document signing certificates. These are in a bit of a gray 96 00:11:30,780 --> 00:11:35,780 area as they're frequently interchangeable with S-MIME or SSL certificates and have similar 97 00:11:35,780 --> 00:11:45,280 requirements. The requirements for different types of certificates can greatly vary. Let's break 98 00:11:45,280 --> 00:11:47,200 down the different types of validation that S-MIME and SSL certificates have. First, we have the 99 00:11:47,200 --> 00:11:48,260 certificate of authority. The certificate of authority is a standard type of validation that 100 00:11:48,260 --> 00:11:53,620 certificate authorities can perform. With domain validation or DV, you need to prove that you 101 00:11:53,620 --> 00:12:00,100 control a given domain. This is a pretty low bar for verification because there's a high risk of 102 00:12:00,100 --> 00:12:06,600 abuse. All you need to do is put up a file on your web server. Organization validation is where 103 00:12:06,600 --> 00:12:12,440 we get into the moderate level of verification. During this process, you need to prove the legal 104 00:12:12,440 --> 00:12:17,180 and physical existence of your organization. This is the bare minimum for a certificate of authority. 105 00:12:17,180 --> 00:12:23,620 For code signing certificates and other sensitive digital use cases. Extended validation is one of 106 00:12:23,620 --> 00:12:29,380 the highest levels of validation that a CA can perform. It's everything you need for organization 107 00:12:29,380 --> 00:12:35,940 validation, but more. For example, you often need to show that your business is legitimate and not a 108 00:12:35,940 --> 00:12:46,680 shell company. This can include face-to-face verification. When I started my research into digital 109 00:12:46,680 --> 00:12:47,160 signature validation, I realized that there was a lot more to it than I thought it would be. It's not 110 00:12:47,180 --> 00:12:51,180 just about signature implementations. The differences between certificate requirements caught my 111 00:12:51,180 --> 00:12:58,480 eye. For example, in our context, having a digital signature alone is not sufficient. We not only 112 00:12:58,480 --> 00:13:03,620 need to be able to verify that a signature is cryptographically valid, but also that it 113 00:13:03,620 --> 00:13:10,600 originates from a trusted source. These two diagrams overview the extended validation versus 114 00:13:10,600 --> 00:13:17,160 domain validation process. The question I had was, what provides the most value to the 115 00:13:17,180 --> 00:13:22,100 certificate? What prevents an attacker from abusing a certificate that has only proven domain 116 00:13:22,100 --> 00:13:32,860 ownership for purposes that require a higher level of verification, like code signing? Now, let's 117 00:13:32,860 --> 00:13:42,380 get into the fun stuff. What defines a certificate's purpose? What distinguishes an SSL 118 00:13:42,380 --> 00:13:47,160 certificate from a code signing certificate? Often, it's the extended key of the certificate. 119 00:13:47,160 --> 00:13:54,020 The key usage field present in most end-entity certificates. EKUs can specify what a certificate 120 00:13:54,020 --> 00:14:00,340 is allowed to be used for. As an example, the image on the right shows this field from an SSL 121 00:14:00,340 --> 00:14:06,880 certificate. The server and client authentication usages mean that the certificate is allowed to 122 00:14:06,880 --> 00:14:17,140 authenticate to a remote server or client. But what actually validates a certificate? The key 123 00:14:17,160 --> 00:14:24,280 usage field verifies these EKUs in practice. When you sign digital data, the utility you use can 124 00:14:24,280 --> 00:14:29,400 impose restrictions. For example, if you're signing an executable, you may receive an error if 125 00:14:29,400 --> 00:14:34,820 you try to sign an executable without the code signing EKU present on the certificate you're 126 00:14:34,820 --> 00:14:41,600 using. But the restrictions these tools impose are not what matters, because they run before the 127 00:14:41,600 --> 00:14:47,140 attack is actually performed. As we'll soon see, if I, as an attacker, were to use a certificate, I'd 128 00:14:47,140 --> 00:14:52,660 got an error related to the intended purpose of my certificate. There's nothing stopping me from 129 00:14:52,660 --> 00:15:02,200 modifying the tool to bypass this check. So how do we identify vulnerable implementations that 130 00:15:02,200 --> 00:15:11,200 fail to validate a certificate's intended purpose? First, we started by identifying some basic 131 00:15:11,200 --> 00:15:16,880 criteria. The Microsoft Security Response Center is interested in protecting the entire 132 00:15:17,140 --> 00:15:23,020 ecosystem, not just first party implementations. We ended up looking at a variety of file 133 00:15:23,020 --> 00:15:29,640 formats that leverage digital signatures. Most frequently, this included code signing because of 134 00:15:29,640 --> 00:15:39,600 the bare minimum organization validation requirement. For testing, we also generated an SSL 135 00:15:39,600 --> 00:15:47,120 certificate, which only required proof of domain control. In the next few slides, we'll review a few 136 00:15:47,140 --> 00:15:52,320 of the signing tools relevant to the file formats we're interested in, and modify them to remove 137 00:15:52,320 --> 00:15:59,000 any client-side checks. Remember, modifying our signing tools comes before any attack on our 138 00:15:59,000 --> 00:16:09,060 environment. What matters is the receiving end and how it handles EKUs. To start with, I looked at 139 00:16:09,060 --> 00:16:17,120 Microsoft's sign tool, which lets you sign over 25 unique file extensions. This utility is most often used for authentic code, and is included with the file format. This is a tool that is used for 140 00:16:17,140 --> 00:16:27,720 the Windows SDK. First, I performed a sanity check, and tried to sign an SSL certificate, sorry, tried to sign an executable with an SSL 141 00:16:27,720 --> 00:16:36,740 certificate. As you can see, sign tool by default does validate the EKUs of your code signing certificate. We need to get around this. 142 00:16:38,700 --> 00:16:47,120 Using IDA Pro, I was able to quickly find the function responsible for the check by looking for the EKU filter error string. The 143 00:16:47,140 --> 00:17:00,000 function was conveniently named filter certificates. I patched the function to immediately return and avoid filtering entirely. Next time I tried 144 00:17:00,000 --> 00:17:17,120 signing my executable, it worked without a problem. Sign tool isn't the only utility relevant to this project. The manifest generation and editing tool is used to create and modify application and 145 00:17:17,140 --> 00:17:23,700 deploy manifest. Part of this tool includes the ability to sign manifest. We'll discuss how these 146 00:17:23,700 --> 00:17:33,980 manifest are used in a later slide. Like sign tool, mage performs EKU verification when signing a 147 00:17:33,980 --> 00:17:47,120 manifest. Unlike sign tool, mage is written in C sharp. How can we patch this EKU check? I use DNspot, an older .net assembly editor that allows you to both decompile and 148 00:17:47,120 --> 00:17:57,080 and modify C sharp applications. I found a responsible method can 149 00:17:57,080 --> 00:18:01,500 sign with by looking for the relevant error message. Using 150 00:18:01,500 --> 00:18:07,120 DN spy I modified this method to always return to bypassing the 151 00:18:07,120 --> 00:18:17,060 EKU check. And as expected this modification allows you to sign 152 00:18:17,120 --> 00:18:23,420 manifest with an unrelated certificate. Now that we've 153 00:18:23,420 --> 00:18:27,200 prepared our test data, signed with our SSL certificate, let's 154 00:18:27,200 --> 00:18:29,480 try it against real world authentic code implementations. 155 00:18:32,540 --> 00:18:37,140 All right. Some background. On Windows the primary API commonly 156 00:18:37,140 --> 00:18:40,900 used to verify the trust of supported objects is win verify 157 00:18:40,900 --> 00:18:45,260 trust. This function abstracts the job of signature validation 158 00:18:45,740 --> 00:18:46,540 to subject. 159 00:18:46,640 --> 00:18:47,040 . 160 00:18:50,420 --> 00:18:54,540 SIPs are responsible for the format specific verification of 161 00:18:54,540 --> 00:18:59,040 digital signatures. For example, a portable executable will store 162 00:18:59,040 --> 00:19:02,040 digital signatures in a different format compared to a 163 00:19:02,040 --> 00:19:06,960 PowerShell script. The key is that there's a SIP for both to 164 00:19:06,960 --> 00:19:11,560 handle both formats. In this talk we'll briefly review this 165 00:19:11,560 --> 00:19:14,440 architecture, but if you're interested in understanding this 166 00:19:14,440 --> 00:19:17,100 design in detail, I would strongly recommend that you 167 00:19:17,120 --> 00:19:28,960 read subverting trust in Windows by Matt Graber. Trust providers don't care about the 168 00:19:28,960 --> 00:19:35,220 SIP you use. They are designed to perform format agnostic trust verification actions. 169 00:19:35,800 --> 00:19:42,480 Common providers include generic cert verify which will verify a certificate. Generic chain 170 00:19:42,480 --> 00:19:46,050 verify which will verify a certificate's chain of trust.查 171 00:19:47,120 --> 00:19:52,540 and generic verify alone will verify a file or object according to the authentic code 172 00:19:52,540 --> 00:19:59,500 specification. The generic verify provider is most commonly used for verifying authentic code 173 00:19:59,500 --> 00:20:08,920 formats. As a simple test, I wrote a small test application to verify an executable signature 174 00:20:09,480 --> 00:20:16,060 using win verify trust. Unfortunately or fortunately, depending on how you look at it, it 175 00:20:16,060 --> 00:20:21,100 didn't work. I received an error stating this certificate is not valid for the requested 176 00:20:21,100 --> 00:20:30,180 usage. Remember the generic verify trust provider? Unfortunately, it turns out that one of the 177 00:20:30,180 --> 00:20:35,780 basic requirements for this provider, which is used in almost all authentic code formats, is 178 00:20:35,780 --> 00:20:44,160 that the code signing EKU is present. This meant that most of these formats that are verified 179 00:20:44,840 --> 00:20:46,040 through this architecture are not valid for the requested usage. The generic verify trust 180 00:20:46,060 --> 00:20:53,600 provider, which is ORD, set the signature by default, are protected. Although Windows 181 00:20:53,600 --> 00:20:59,220 may have gotten it right, I was curious about other libraries that validated the authenticity of 182 00:20:59,220 --> 00:21:04,580 authentic code applications. What about workloads that needed to verify these signatures on other 183 00:21:04,580 --> 00:21:10,520 operating systems? Unfortunately, as we'll soon see, several authentic code implementations 184 00:21:10,520 --> 00:21:16,040 outside of Windows itself were vulnerable to this attack. The standard for the generic verify 185 00:21:18,680 --> 00:21:23,100 project is an open source equivalent to Microsoft's .NET 186 00:21:23,100 --> 00:21:27,540 framework. Microsoft sponsors the project and Mono is 187 00:21:27,540 --> 00:21:31,000 frequently used in cross-platform applications that 188 00:21:31,000 --> 00:21:39,020 want to use .NET. Mono supports Authenticode signing and 189 00:21:39,020 --> 00:21:42,460 verification with its Authenticode deformatter and 190 00:21:42,460 --> 00:21:46,700 Authenticode formatter classes. How can we test Mono's 191 00:21:46,700 --> 00:21:49,680 Authenticode implementation? Well, fortunately, it comes with 192 00:21:49,680 --> 00:21:53,300 a check trust tool that allows us to verify the signature of an 193 00:21:53,300 --> 00:21:59,800 executable. Unfortunately, due to a lack of EKU validation, 194 00:22:00,800 --> 00:22:04,160 Mono's Authenticode deformatter class is vulnerable to the 195 00:22:04,160 --> 00:22:08,400 attack. This issue isn't specific to Mono's simple check 196 00:22:08,400 --> 00:22:12,440 trust testing utility. Any Mono application that you 197 00:22:12,460 --> 00:22:16,640 uses this class for verifying untrusted executables is 198 00:22:16,640 --> 00:22:24,300 potentially vulnerable. Trail of Bits is a security consulting 199 00:22:24,300 --> 00:22:27,580 firm that helps organizations engineer secure applications. 200 00:22:28,510 --> 00:22:32,120 They have quite a few open source tools and one of those 201 00:22:32,120 --> 00:22:37,540 projects includes Authenticode. Authenticode is a cross-platform 202 00:22:37,540 --> 00:22:41,680 library that allows you to verify a digital signature of a 203 00:22:41,680 --> 00:22:42,440 portable executable. This is a tool that allows you to verify a 204 00:22:42,460 --> 00:22:44,720 digital signature of a portable executable. The intent is to 205 00:22:44,720 --> 00:22:49,980 provide similar functionality to API like WinVerify Trust on 206 00:22:49,980 --> 00:22:54,160 non-Windows platforms. Unlike WinVerify Trust, however, 207 00:22:54,960 --> 00:22:58,480 Authenticode only verifies an Authenticode signature. It 208 00:22:58,480 --> 00:23:02,360 doesn't verify a certificate's chain of trust. The chain of 209 00:23:02,360 --> 00:23:06,760 trust isn't relevant to EKUs. You can verify that a leaf 210 00:23:06,760 --> 00:23:09,880 certificate is allowed to be used for code signing without 211 00:23:09,880 --> 00:23:12,060 verifying that it was issued by a trusted, 212 00:23:12,060 --> 00:23:21,140 root certificate authority. Unfortunately, Authenticode was 213 00:23:21,140 --> 00:23:24,860 vulnerable to the EKU attack, allowing attackers to sign code 214 00:23:24,860 --> 00:23:29,700 with an unrelated certificate. Fair disclaimer, the real, real 215 00:23:29,700 --> 00:23:34,600 world implement, implications of the EKU attack with Authenticode 216 00:23:34,600 --> 00:23:37,700 are limited. For example, according to the authors I spoke 217 00:23:37,700 --> 00:23:41,640 with, Authenticode is frequently used in CI CD stacks for basic 218 00:23:41,640 --> 00:23:45,560 Authenticode validation. Of course, given its open source 219 00:23:45,980 --> 00:23:53,740 nature, it's hard to quantify its use with certainty. When I 220 00:23:53,740 --> 00:23:57,300 was, I also wanted to review a bonus example. When I was 221 00:23:57,300 --> 00:24:00,040 reviewing Authenticode's implementation of signature 222 00:24:00,040 --> 00:24:04,220 verification, I noticed that it deviated from the Authenticode 223 00:24:04,220 --> 00:24:09,540 specification. On the left, we have the same diagram from the 224 00:24:09,540 --> 00:24:11,620 earlier slide, showing a high level of authentication. This is 225 00:24:11,640 --> 00:24:14,160 a high level overview of how portable executables are 226 00:24:14,160 --> 00:24:18,760 verified under Authenticode. On the right, I've modified the 227 00:24:18,760 --> 00:24:22,260 diagram to reflect Authenticode's implementation of this 228 00:24:22,260 --> 00:24:26,520 specification. So, according to the Authenticode specification, 229 00:24:27,230 --> 00:24:30,620 you're supposed to hash the contents of an executable by 230 00:24:30,620 --> 00:24:35,400 concatenating the hashes of the PE header, sorted sections, and 231 00:24:35,400 --> 00:24:41,260 any extra data. Authenticode ignored these PE sections. Instead, 232 00:24:41,640 --> 00:24:46,320 they'd hash the PE header and the rest of the file, excluding the 233 00:24:46,320 --> 00:24:50,720 security directory. From a practical stance, what this meant 234 00:24:50,720 --> 00:24:53,480 was that it would take everything before the security 235 00:24:53,480 --> 00:24:57,280 directory and everything after the security directory and then 236 00:24:57,280 --> 00:25:03,360 combine the two and calculate a hash on that result. On the 237 00:25:03,360 --> 00:25:07,040 earlier slide about attacking digital signatures, I mentioned 238 00:25:07,040 --> 00:25:11,160 how you shouldn't ever roll your own crypto or deviate from the 239 00:25:11,160 --> 00:25:11,620 specification. So, I'm going to show you how to do that. So, 240 00:25:11,640 --> 00:25:15,760 I was curious, what are the implications of this deviation? 241 00:25:20,020 --> 00:25:24,400 Unfortunately, this deviation led to a pretty big flaw. I found 242 00:25:24,400 --> 00:25:29,360 that by embedding the security directory within a PE section, I 243 00:25:29,360 --> 00:25:34,080 could modify the code of an executable without changing its 244 00:25:34,080 --> 00:25:37,880 Authenticode hash according to Authenticode. The problem was 245 00:25:38,300 --> 00:25:41,400 that since Authenticode skips over the security directory, 246 00:25:41,640 --> 00:25:46,420 it would hash everything up to the modified PE section, ignore the 247 00:25:46,820 --> 00:25:50,200 security directory with malicious code, and hash everything after. 248 00:25:51,300 --> 00:25:54,420 You could move around the security directory and the 249 00:25:54,420 --> 00:25:58,900 Authenticode hash as calculated by Authenticode would remain 250 00:25:58,900 --> 00:26:07,600 unmodified. I was able to leverage this attack to replace 251 00:26:07,600 --> 00:26:11,260 the entry point of a legitimate Microsoft executable with 252 00:26:11,260 --> 00:26:16,980 malicious shellcode. This issue is not related to EKUs. It was 253 00:26:16,980 --> 00:26:21,120 simply an extra implementation flaw that I stumbled upon. But 254 00:26:21,120 --> 00:26:24,800 it highlights the importance of sticking with the specification 255 00:26:25,440 --> 00:26:28,340 and how one small mistake when implementing digital 256 00:26:28,340 --> 00:26:35,620 signatures can have a devastating impact. Let's 257 00:26:35,620 --> 00:26:42,280 discuss ClickOnce. ClickOnce is a deployment technology that 258 00:26:42,280 --> 00:26:45,920 allows developers to create self-updating applications that 259 00:26:45,920 --> 00:26:54,580 can be installed or run with minimal user interaction. Under 260 00:26:54,580 --> 00:26:58,000 the hood, ClickOnce deployments are made up of application 261 00:26:58,000 --> 00:27:02,620 files, a deployment manifest, and an optional application 262 00:27:02,620 --> 00:27:05,600 manifest. The cool part of ClickOnce is that it's a 263 00:27:05,620 --> 00:27:09,180 platform where you can install or run applications from a 264 00:27:09,180 --> 00:27:13,560 website. The picture shows what a ClickOnce prompt can look like, 265 00:27:13,620 --> 00:27:17,340 which can be triggered by a link in a browser that supports 266 00:27:17,340 --> 00:27:27,860 ClickOnce. ClickOnce applications can be signed 267 00:27:27,860 --> 00:27:32,140 automatically with Visual Studio or manually with Mage. The 268 00:27:32,140 --> 00:27:35,500 diagram below demonstrates this. First, we take an 269 00:27:35,500 --> 00:27:35,600 application, and we take it to the application. Then we take 270 00:27:35,620 --> 00:27:36,660 an application to a web server to test it. We take the application 271 00:27:36,660 --> 00:27:38,520 and we put it in the root directory. We sign the application 272 00:27:38,520 --> 00:27:42,900 manifest in the application files directory. We sign the 273 00:27:42,900 --> 00:27:46,520 deployment manifest in the application files directory, and 274 00:27:46,520 --> 00:27:49,640 then we optionally sign the application manifest into the 275 00:27:49,640 --> 00:27:52,560 root directory. This gives us a signed ClickOnce deployment. 276 00:27:56,020 --> 00:28:00,220 Once the deployment was signed, it was uploaded to a web server 277 00:28:00,220 --> 00:28:04,720 for testing. The picture below shows you what this ClickOnce 278 00:28:04,720 --> 00:28:09,460 once prompt can look like in Microsoft Edge. It asks do you 279 00:28:09,460 --> 00:28:13,860 want to open test click once application from the domain 280 00:28:13,860 --> 00:28:17,520 that you're visiting? The page itself can have any content you 281 00:28:17,520 --> 00:28:24,900 want. Unfortunately, click once was impacted by this attack. As 282 00:28:24,900 --> 00:28:28,420 you can see in the picture below, the publisher shows as 283 00:28:28,420 --> 00:28:32,940 the domain that I had registered an SSL certificate for. If you 284 00:28:32,940 --> 00:28:36,460 had tried to use a certificate that was not issued by a trusted 285 00:28:36,460 --> 00:28:40,220 authority, well, it would show that error in saying that the 286 00:28:40,220 --> 00:28:43,560 certificate is not trusted. But unfortunately, because click 287 00:28:43,560 --> 00:28:47,560 once didn't actually validate EKUs, it considers the 288 00:28:47,560 --> 00:28:50,740 certificate that I signed my deployment with as legitimate. 289 00:28:54,900 --> 00:28:58,480 What about other uses of digital signatures that we didn't cover? 290 00:28:59,640 --> 00:29:02,600 I want to talk a little bit about some related work. In 291 00:29:02,600 --> 00:29:02,920 2015, I signed a certificate that was not issued by a trusted 292 00:29:02,940 --> 00:29:05,860 authority. In 2014, researchers from the University of Texas and 293 00:29:05,860 --> 00:29:10,140 California released Using Frank Inserts for automated 294 00:29:10,140 --> 00:29:14,300 adversarial testing of certificate validation and SSL 295 00:29:14,300 --> 00:29:18,760 slash TLS implementations. As the name suggests, the 296 00:29:18,760 --> 00:29:22,220 researchers generated mutated certificates with different 297 00:29:22,220 --> 00:29:27,120 combinations of extensions and constraints. The idea was to look 298 00:29:27,120 --> 00:29:31,580 for inconsistencies between implementations. Now, this paper 299 00:29:31,580 --> 00:29:32,920 exclusively focuses on the fact that the certificate is not 300 00:29:32,920 --> 00:29:35,420 blocking the use of an SSL and TLS. It's the only way to use an 301 00:29:35,420 --> 00:29:43,580 open SSL and TLS implementation in open SSL, NSS, etc. Of relevance to 302 00:29:43,580 --> 00:29:48,800 this talk, the researchers found several libraries that failed to 303 00:29:48,800 --> 00:29:54,220 validate the appropriate EKU. Instead of malformed certificates 304 00:29:54,650 --> 00:29:58,440 for digital signatures and executables, they looked at abusing 305 00:29:58,440 --> 00:30:02,600 them in the browser. If you're interested in reading more, I'd 306 00:30:02,600 --> 00:30:11,280 recommend that you check out the link below. We additionally 307 00:30:11,280 --> 00:30:15,520 verified that common libraries like OpenSSL validated these 308 00:30:15,520 --> 00:30:19,700 EKUs appropriately. Now if you use these libraries for solely 309 00:30:19,700 --> 00:30:24,640 verifying the authenticity of a certificate without specifying a 310 00:30:24,640 --> 00:30:28,500 purpose or there's no default, you can still be exposed to an 311 00:30:28,500 --> 00:30:33,480 EKU attack. For example, in OpenSSL you can specify context 312 00:30:33,480 --> 00:30:37,980 for X509 verification as seen in the picture below, which can 313 00:30:37,980 --> 00:30:42,260 include these EKU defaults. For example, if I set the context 314 00:30:42,260 --> 00:30:46,340 that I'm an SSL client, OpenSSL has the correct defaults to 315 00:30:46,340 --> 00:30:49,980 validate that the client authenticate, excuse me, server 316 00:30:49,980 --> 00:30:54,320 authentication EKU is present on the server certificate and vice 317 00:30:54,320 --> 00:30:56,300 versa if you say that you're an SSL server. 318 00:31:00,460 --> 00:31:05,080 Let's review some of the takeaways and techniques. In this 319 00:31:05,080 --> 00:31:08,400 project, we discovered numerous implementations of digital 320 00:31:08,400 --> 00:31:12,020 signatures that failed to validate the extended key usage 321 00:31:12,020 --> 00:31:16,020 field. This would allow an attacker to abuse certificates 322 00:31:16,660 --> 00:31:21,300 with a substantially lower bar for identity verification in 323 00:31:21,300 --> 00:31:25,140 important context, like code signing. The diagram below 324 00:31:25,140 --> 00:31:28,300 demonstrates this attack. First, an attack 325 00:31:28,500 --> 00:31:32,320 attacker buys or generates a low-cost certificate, whether 326 00:31:32,320 --> 00:31:36,940 this be SSL, S-MIME, et cetera, is up to them. Next, they sign 327 00:31:36,940 --> 00:31:40,460 unrelated data with the mismatched certificate. This 328 00:31:40,460 --> 00:31:43,460 could include modifying the signing tools to allow this in 329 00:31:43,460 --> 00:31:47,440 the first place. Then, vulnerable apps fail to 330 00:31:47,440 --> 00:31:52,840 validate and detect the invalid certificate. As a result, users 331 00:31:52,840 --> 00:31:56,780 can receive a false sense of trust. It can bypass important 332 00:31:56,780 --> 00:31:58,480 access controls. It can also be used as a tool to manipulate a 333 00:31:58,500 --> 00:32:04,380 system. And more, depending on the context. So, how do you 334 00:32:04,380 --> 00:32:08,680 protect your implementation? Well, number one, always fix, 335 00:32:08,880 --> 00:32:13,700 excuse me, always validate EKUs in your application to ensure 336 00:32:13,700 --> 00:32:17,040 that certificates are used for their intended purposes. Use 337 00:32:17,040 --> 00:32:21,920 libraries that properly implement EKU checks. Trust, but 338 00:32:21,920 --> 00:32:26,420 verify key principles in your application's design. Every 339 00:32:26,420 --> 00:32:28,480 single implementation that was vulnerable to this, it was 340 00:32:28,500 --> 00:32:30,760 a failure. So, what do you do? Well, first of all, you have to 341 00:32:30,760 --> 00:32:36,920 check for EKUs. No one verified that they did. Implement regular 342 00:32:36,920 --> 00:32:41,920 security testing, especially in components using cryptography for 343 00:32:41,920 --> 00:32:46,080 crucial features. Your implementation is much more 344 00:32:46,080 --> 00:32:53,640 likely to be vulnerable than a cryptographic algorithm. What is 345 00:32:53,640 --> 00:32:56,700 Microsoft doing to protect customers? Well, number one, 346 00:32:56,720 --> 00:32:58,480 we've released patches for all of our customers. We've released 347 00:32:58,500 --> 00:33:01,760 patches for all first-party issues. The third-party 348 00:33:01,760 --> 00:33:05,540 vulnerabilities we've discussed were also fixed. We're continuing 349 00:33:05,540 --> 00:33:09,480 to work with impacted third-party vendors to address their 350 00:33:09,480 --> 00:33:13,400 implementations. And we also continue to explore issues in 351 00:33:13,400 --> 00:33:16,740 digital signature implementations. Below is a list 352 00:33:16,740 --> 00:33:20,080 of relevant CVEs that were issued as a result of this work. 353 00:33:25,080 --> 00:33:27,840 Thanks for coming to my talk. And now is the time for 354 00:33:27,840 --> 00:33:28,480 questions. I'm going to hand it over to my colleague, Dr. 355 00:33:28,480 --> 00:33:29,140 John, who is going to answer the questions as time permits. 356 00:33:41,320 --> 00:33:54,140 Sure. So, the question was, would CERC pinning help in this 357 00:33:54,140 --> 00:33:58,440 context? So, it can help in the sense that if there's only a 358 00:33:58,440 --> 00:34:01,220 certain subset of trusted authorities that can issue 359 00:34:01,220 --> 00:34:04,740 certificates that your application accepts, well, then 360 00:34:04,740 --> 00:34:07,880 it becomes much harder for an attacker to generate a 361 00:34:07,880 --> 00:34:10,900 certificate, like an SSL certificate, under that 362 00:34:10,900 --> 00:34:14,020 authority, right? So, it would have to be, let's say you're 363 00:34:14,020 --> 00:34:17,100 using your own CA. Yes, that can definitely protect it as long as 364 00:34:17,100 --> 00:34:20,940 an attacker can't generate a certificate under that CA. But 365 00:34:20,940 --> 00:34:23,900 if it's something like you use DigiCert or something, some 366 00:34:23,900 --> 00:34:27,340 specific trusted authority that an attacker could be able to 367 00:34:27,340 --> 00:34:28,420 access or generate certificates, then it's much harder for an 368 00:34:28,440 --> 00:34:29,760 attacker to generate certificates under, then it 369 00:34:29,760 --> 00:34:36,940 doesn't help much in that context. If there's any other 370 00:34:36,940 --> 00:34:39,260 questions, feel free to come up to the stage and I'd love to 371 00:34:39,260 --> 00:34:40,780 discuss the issues with you.