Hey, good evening to everyone. Okay. Thank you. Thank you, thank you. Okay, so what do you expect from patches? Security updates. You expect them to be a Fort Knox security update, right? That solves fully the vulnerability, all the control flows. Is it really? In reality, this is what we usually get. Yep. So we've all been there, expecting that one patch solves it all, right? But essentially it's kind of a patch to a bullet, or there's a better phrase for that. We will be sharing insights about what happens when the patch does not quite do the trick. And sometimes you also find new vulnerabilities. So this talk will be sharing new details about vulnerabilities that we discovered. And were patched during June and July. Those are two out of a bigger number of vulnerabilities. Let's not be too harsh with the vendors. There's a reason why this happens many times. Just a couple of weeks ago, we all saw the mega crash from a CrowdStrike update. It's not exactly a security update, nevertheless the impact is obvious, right? Blue screens all over. And this is exactly the reason why many vendors are kind of trying to solve only the specific problem. While doing so, also kind of share with us the investigative researchers on additional vulnerabilities that are within the code. So just very shortly about ourselves. My name is Michael Gorelick, I'm the chief technology officer and founder of Morphisec. I have around 20 years of experience in cyber security. I was the one to discover one of the largest supply chain attacks, the SeaCleaner, in history. I have a lot of experience in reverse engineering, red teaming and blue teaming. Go ahead, Arnold. Hey guys, my name is Arnold. I'm leading the malware research efforts at Morphisec. And for some time now I'm poking with some patch analysis for fan and profit and product, of course. Thanks, Arnold. Okay. So just starting with a disclaimer. With great power comes greater responsibility. Use your powers for the good. So now about the talk itself. A bit about the motivation. Some of our work that we're doing in Morphisec, we are going and reviewing the most critical vulnerabilities that exist, especially those that lead to remote code executions. The latest vulnerabilities that we were reviewing were ones that were discovered by the NetSpy group, done an amazing work on the form injection category, basically a category of vulnerabilities that lead to remote code execution, but do require authentication, prior authentication. Additional category that Arnold will be sharing is about compound monikers, also lead to remote code execution. Checkpoint done a great research and a great work discovering some vulnerabilities during the year. We will also show how the patch doesn't really do the trick, and how we discovered additional vulnerabilities by purely looking at the patch. Okay, so let's start talking about the forms. I mean, every of those categories can go a full lecture, so we'll be kind of covering very quickly on the introduction, but you are welcome to see additional details and documentation again on the internet. So forms, exactly as you would see, you get a message, you're sending a message, it's eventually based on forms. Now, message, email message is not the only thing that is based on forms. Essentially, there is quite a significant mechanism that works behind, and imagine you are sending a recall message on the message that you sent to your boss. What happens behind? What happens when recall being sent? So essentially, it's something there activates and starts to delete the email from the inboxes of your manager. It's a rendering mechanism that is based on, again, the synchronization of forms, and we'll be covering that, and we'll share, basically, how we utilize that to inject malicious forms. We'll get back to recall in the coming slides, but let's first talk a bit about forms and custom forms. So forms, overall, can be of two different types. Now, if you integrate the developer mode in Outlook, you can see that you can modify existing forms into your own kind of purpose. So if you get a nice message, maybe you want to add some button there or some sound, you can definitely do that and even change the structure of the forms by basically opening the built-in Microsoft Form and starting moving stuff. Now, we will not be talking about that because we are looking into injecting full form, but this is one of the ways to create the form. We'll talk about the creation of the form in the next slide. What is outside of the scope of this presentation is talking about visual basic execution within the form. It was well covered by Etienne Stevens. He done a lot of research in 2017, a lot of presentations. You are welcome to check them out. Microsoft introduced a lot of hardening to avoid the default execution of visual basic inside forms. So this is outside of the scope. Okay, so I already mentioned that we have one way to create a custom form. This one way is by modifying existing built-in forms. But what is interesting for us in this category of form injection is the way you can programmatically create new forms. If you look at the documentation of Microsoft, this is actually a snapshot from Microsoft documentation. There is a way to create your own form by basically generating a configuration file called CFG. Within this configuration file, you basically define the different properties of the same form that you see, like a message or appointment or calendar, it's all forms. And you can also specify a form server. In this case, you see the example is helpdesk.exe. That is responsible to render the form. So upon receiving that message in your Outlook, you want to do something about that. This is the executable that eventually spawned and does something about that. And we will share a couple of examples. Now, it doesn't have to be executable. You can use a different DLL or any other ways. We'll share that as well. But again, there is a very nice way to run that form. Now, we'll not get into too much details about the whole mechanism of forms because we don't have enough time. Nevertheless, it's important to understand one of the most interesting things in forms is the synchronization mechanism. So exactly like you would open a draft email and it suddenly exists in all your clients, behind them there is a mechanism that basically synchronizes all those forms across the different clients through the Exchange server. This is not the only thing that obviously synchronizes. But in this case, we will leverage that mechanism to inject and execute the forms on any of the clients that they are a victim basically using. Now, the mechanism involves form libraries that represent properties. It will also include form servers, etc. And there's also important to understand that not all forms are synchronized. If you put your form into a personal library, it will not be synchronized across the different clients. But if you, for example, install it in the inbox, it will definitely be synced by the Microsoft protocol. So shortly, how forms are loading and registered. So if you take, in this example, a simple built-in modified form, this is not a programmatically created form. Nevertheless, it's the same mechanism. So if you look at your registry hive under the class ID, you will find, again, based on whether you have Outlook 32-bit or 64-bit, you have the WOW there. But you will find a lot of those class IDs, and each class ID, many of those class IDs basically represent the different forms. Now, as soon as you find the class ID, you will find also what is the name of the form, and you will find what is the location of that form on your disk. Those forms, when they are synchronized, they are saved in a special folder, many times in the app data, local data, under the forms folder. And the built-in forms are saved within the program files office, also special folder there. Essentially, those form libraries are comb objects, and those can be rendered and instantiated like any other comb. As we said, the original kind of oily form library is a bit outside of the scope of this lecture. Nevertheless, I strongly recommend people here to try and play with it, because you can modify the streams and also lead to malicious behavior by basically modifying the properties of the oily itself. But we will be talking about programmatically created forms through the configuration files. This is a great example of a built-in recall message form that basically exists on any of the computers that are installed with Outlook, whether it's 32-bit or 64-bit. You can go to this specified directory and find those CFG files. Now, you identify that there is a special file called a React CFG. This is an example of the recall message form. You see also that the CFG itself also includes the rendering file, the recall.dll, basically instantiated automatically through the InProc server 32. Now, if you are not using your cloud recall, which is kind of the latest thing through Azure, this is kind of the default built-in. If you are sending a special message, you basically identify the class message, and the recall.dll is loaded within the context of the Outlook. It basically starts to delete from your inbox the message that you want to remove. So we want to achieve the same thing. We want to exploit the same behavior and define our own CFG with our own dll that will be put automatically into the victim environment. But can we do that? Here is an example again from this recall call, which is a column object. But can we do that? Well, not exactly. There is a special mechanism that bypasses Outlook. And by default, it's disabled. Now, if it would be enabled, you can definitely define such a CFG. You can load it, and then you have a form automatically synchronized to your victim environment. And you can send a special message that will trigger the initiation of the form. But if this flag is basically disabled, which is by default, your form goes through a special matching algorithm, which validates that you are not using special keywords like inprox server, local handler, which basically automatically instantiate those com objects or those malicious dlls or executables that are put in this folder. Now, one of the problems with this matching algorithm is... Wow, it's noisy. So one of the problems with this matching algorithm is that it is an exact matching. It checks for an exact words. Not less, not more, but an exact words within the keys that are specified in the configuration file. So somehow we lead basically to the first vulnerability that was discovered by NetSpy, which has done amazing work. They introduced into this registry file an additional relative path. Okay, so basically... One, one, one. Okay. Yeah. I'm sure the line at the end will hear. Yeah, yeah, yeah. That's more. One. Okay. Okay. So it's kind of a temporary solution. So I hope we will finish the presentation until then. But again, it's a great finding. Basically, the NetSpy group added a relative class ID. And it's also documented in Microsoft documentation that they clearly say that you can provide a relative path for your form server rendering. And they added that. And then, surprisingly, because the algorithm that checks for the forbidden words does an exact matching, the algorithm fails and you have automatically instantiated form, malicious form, with a fully controlled class ID of your own. Beside that vulnerability, they also discovered kind of a directory traversal vulnerability in which basically allows to install that form anywhere on the file disk because you can play with one of the properties. But this property is less interesting for us. It was nicely patched by Microsoft. But I will be talking specifically about the bypass algorithm. So now is the interesting part. How Microsoft patched that vulnerability and what led us basically to discover new vulnerabilities following that patch. So as we see in the patch that was introduced by Microsoft, Microsoft said, okay, you have a problem with the relative path. Let's remove relative path. They didn't update the documentation yet. But they basically removed that functionality. You cannot put a backslash anymore in the property of the form. So great. Okay. It solved the problem. But they didn't change the matching algorithm. The algorithm is still the same. So as you would expect, we were looking for additional control flows that allow us to still instantiate the same forms by abusing the failure in the matching algorithm. So I have to commend to Microsoft because they have done it quite quickly. We reported it in April. They patched it in June. So nice work. But, again, before we are diving into how we created additional control flow, we need to understand how a Windows core API function works. Now, when you basically register a form, it goes through a process in which they use recreate XA function. It's also utilized in most of the applications today. It's one of the most popular functions that exist today. One of the properties of this function, which is interesting, you can supply to this function a parameter that composed of multiple keys by separating them through backslashes. Now, I think it's limited to 32 keys. So if you are basically using that function with 31 backslashes, it will create a nested directory structure automatically. And one of the additional properties is that if you provide a register key with a backslash, trailing backslash, it will be removed to maintain consistency. It's correct to any recreate XA. And this will be probably interesting to investigate other applications that may be vulnerable due to the same reason. So as you would probably guess, we just added this backslash at the end. So as soon as you add the backslash at the end, obviously, it goes through the matching algorithm, which does the exact matching. It goes through because, again, we have the backslash. And when the reg X creates the registry, it removes the trailing backslash. And voila, you have a fully executing form written automatically, synchronized by Microsoft to any of the victim environments. And what do we need to basically execute that? Just to send the message, a simple email with the message class of that form. So very quickly, just a demonstration. Let's see. Okay. I hope you see the video. So in this video, we will... no? Okay. It's a problem. Maybe we can push it here. Okay. Ah, solution. So we'll try to do a play like that. Maybe this works. Okay. Remotely. Nice. Okay. So essentially we are working here on outdated outlook. This was recorded in June, just before the patch was introduced by Microsoft. We are using a tool by Etienne Stevens called the ruler, which basically allows us to utilize the MAPI API to synchronize and create a new form. We didn't have to use that. We just could open a client in our environment, use the credentials, and create the same form. Here we are utilizing and creating the property with the backslash. And with the next step, we will be sending right now an authenticated token that allows us basically to upload the form and to synchronize it across the different victims. So in the next step, as soon as it will be sent, we will see that the form suddenly appeared on the victim environment. It takes a bit... a couple of seconds. Okay. Good. Okay. So here we receive the message. We're still not opening that message. The opening of the message will instantiate the execution of the form, but the form was already written, synchronized into the folder. So this is a way in which you can also use the advanced button. You can check out the forms, or you can simply go to the folder of the forms and identify it was written. As soon as I open that, the form server is executed. As you see, it's executed within the context of the Outlook process. Now, the same if you would use not inprox server 32, but let's say local handler, it would execute an external application executable the same way. Now we need to pull it back somehow. Huh? No, maybe I just closed it. Oh, okay. Okay. Okay, good. So this was a very nice demonstration for a form, but again, it's assumed that we have authentication beforehand. We will show later on how easy we can get the authentication, the tokens from the environment and have a full RC, non-authenticated. But again, in this case, we do require the credentials of the victim. Let's continue. Okay, so what do we have here? We have a patch to this vulnerability. Now, it's interesting because we just bypassed one patch, and this patch was introduced to solve the vulnerability that we discovered. Now, if you look at the patch, again, for those that are reversing here, it's probably more clear. But essentially, they didn't change the function that checks for the exact strings. They just decided to remove the trailing backslashes. So basically, they introduced additional loop that goes over the key and removes all the trailing backslashes, and then continue with the same exact matching algorithm instead of looking for a contain, et cetera. So I definitely welcome you guys to check out what additional control flows you can find out. And maybe you will. But it's not all. When they introduced that patch, they also introduced additional extension for the blocking list. Now, it's also interesting, those that identify those special key attributes, those key allows hijacking and execution of additional comments or com hijacking, et cetera. So definitely an interesting additional path to investigate. This just shows that there were additional vulnerabilities in place that could be utilized by an adversary. Okay, so just to put things in the right order, there are more vulnerabilities that were discovered. Next week, there will be a patch for additional vulnerabilities. I suppose we will share the details somewhere a month or two months after, but we do recommend you to patch your Outlook clients because it's not very difficult. The exploit is very trivial. Now, again, form injection is nice for remote code execution, but it's not the only way to utilize that type of vulnerabilities. Now, we can obviously do a persistency with that. We can also escalate privileges. If you, for example, hijack the credentials of an Exchange admin, we can propagate the same forms across all the inboxes and do much more damage than just a simple victim. So let's talk for a second about the other part which is missing, the authentication. Now, I'm talking about authentication only in two slides, but there is a nice presentation tomorrow by someone else that is only talking about NTLM, and I trust that it will be a great presentation. But NTLM is essentially, or anti-hash if you would say, if you would, for example, send an email and send a link to a file, and the victim will double-click on those links. Behind that, there will be an SMB protocol that will require basically a challenge response algorithm that will require authentication. And if you are by default not doing a Kerberos authentication, a rogue server will take your anti-hash automatically, and the file doesn't have to exist there, just you pressing the link. But aside of that, there were a lot of vulnerabilities that were discovered in 2023 and 2024. It was, I think, one of the significant years for NTLM leaks all across with zero clicks. So you didn't need to press or get a warning that there is an SMB file, you just needed to have an appointment reminder that is sent with a nice kind of link to a sound that will be sound when the appointment is being sent, or some kind of Windows performance analyzer that is being directed, and all kinds of additional exploits that lead to the same NTLM leak. So it's not very difficult to get NTLM leaks. We'll get into a recommendation how it can be blocked going forward. But one of them is interesting. The last one, especially NTLM leaks that are led through execution of monikers, so compound monikers. And this is a great time to move to Arnold, which will be talking about compound monikers that lead to remote code executions and NTLM. Okay, then. Thank you, Michael. So before we dive into the next RCE vulnerability we discovered in Outlook, we first need to get at least some high-level understanding of what monikers are. And I highly encourage you to dig deeper into the subject, as multiple vulnerabilities in Outlook involve monikers in Office applications, involve monikers in some way or another. Now, actually we are all using monikers with our daily work with Office applications. One example is when you try to send an email, and in the body of that email you attach an Excel chart as a link. Well, a moniker is used to point to that specific Excel chart using a string understood by the moniker mechanism and the monikers involved. Now, the general idea of a moniker is to provide you with some way to locate and identify this specific com object using strings or instead of writing a custom mechanism to do that. And in order to achieve it, all monikers must implement the IMoniker interface. Well, Microsoft actually provides several implementations of monikers, some of them related to the OLE objects and most notably used in Office applications. Some of these monikers include the FileMoniker, ItemMoniker, URLMoniker and a few more. One additional example is using the getObject method within the Visual Basic Programming Language or its Windows API equivalent, the call getObject. This is basically a helper function that simplifies the way of converting the moniker string, the display name, into a moniker and then binding to that named object. Now, it does that by encapsulating calls to the com library functions, the createBind, mkParseDisplayName and bindToObject. Okay, so moving back to Outlook. Imagine receiving an email with hyperlink points to a file located on an SMB share. If you would click on that file or on that link, you won't get a pop-up notification asking whether you are sure you want to click on that link. Clicking on links from untrusted sources can do this and that. Instead, a warning message is displayed in the Windows Notification Center stating that something unexpected went wrong with the URL and the file on that SMB share would never be accessed. We would expect that to be good, right? So, if the file would have been accessed, at least the local NTLM credentials would have been leaked as accessing the file would go through the SMB protocol which relies on the local NTLM credentials to authenticate. Well, earlier this year, Checkpoint Researcher found a vulnerability in Outlook that bypasses that warning message by simply adding an exclamation mark at the end of that link. Apparently, this turns the hyperlink from a simple hyperlink that points to a file moniker into a generic composite moniker that is composed from a file moniker and an item moniker. Clicking on such a link results in accessing the file, leaking the local NTLM credentials, and potentially allow for remote code execution. So, let's dive in and understand how this is happening. Most Microsoft Office applications load the MSO DLL, which is a core component used by multiple Office applications. The DLL contains essential functionalities that is split between multiple DLLs. Some of them are presented. The one we are interested with the vulnerability discovered by Checkpoint is the MSO-30 DLL, which handles things related to links and links parsing. And to be more specific, the MSO HRLinkCreateFromString function that is a wrapper for HLinkCreateFromString that basically creates hyperlink objects from strings that represent the hyperlink target. If you would look at the documentation for HLinkCreateFromString, we see that it starts with a security warning that states, never parse strings from a non-trusted source when creating hyperlinks with HLinkCreateFromString. The target parameter is passed to MKParseDisplayName. Now, you might be wondering what is wrong with MKParseDisplayName. We'll get it in a second. But before that, take a look at the second paragraph. You can see that it is mentioned that if a string of the form suggested in the checkpoints vulnerability at composite moniker is passed, it will instantiate the object registered with the specific prog ID. And if it implements the iMoniker interface, it can in turn run unexpected code. And it doesn't stop just there. Looking at the documentation for MKParseDisplayName, we see that it states that calling MKParseDisplayName with a display name parameter from an untrusted source is unsafe. And it can lead to some moniker implementations to act on the string during the parsing of it. Well, if you take a closer look at how it happens in the code, we see that when there is a character indicated that the string is a composite moniker, and by the way, not only by the exclamation mark, but also the opening square bracket and colon, the parsing of that composite moniker would go through the MKParseDisplayName for handling with, of course, composite monikers instead of creating a file moniker. Now, when MKParseDisplayName is called, it will call the bindToObject method, which eventually involves the relevant com object, responsible for handling with the specific file type pointed to by the file moniker. For instance, if the file pointed to by the file moniker is an RTF, WinWord will be spawned in the background without displaying the UI. It will access the file pointed to by the file moniker, and will try to access the object pointed to by the item moniker. Now, this behavior leads to two significant issues. First, the file is being accessed, so we have an NTLM credential leak, and second, the file is being parsed, so any RCE involved in the parsing routine can be chained to gain full RCE. Now, one important note I want to point is that characters other than the exclamation mark can trigger this vulnerability, and it's important from a detection and prevention standpoint, as it wasn't mentioned anywhere else. Now, before we dive into the patch analysis and how we bypassed it, we first need to understand how Microsoft patches some vulnerabilities in Office applications. Surprisingly or not, they use hooks which are installed from the ineditors function within the MSODLL. Apparently, each Office application has its own application ID, and before the hook is installed, the ineditors function checks that the current process has a valid application ID. Well, this technique kind of reminds us hot-patching, right? Pinpointing a specific API in a specific location only by specific processes, as well, these APIs are being used system-wide across many other applications. Now, moving on to the patch itself, as you can see, Microsoft updated the ineditors function to add hooks for the MKParsDisplayName APIs. The hook simply checks if a flag named block MKParsDisplayName on current thread is set to true, and if that's the case, as the name suggests, MKParsDisplayName would not be invoked, and it will return an error instead. Now you might be wondering where that flag is being set. If you recall, the MSOHRLink createFromString. responsible for creating hyperlink objects from strings, sets the flag to true at the beginning of the function, and it only does that if the application ID equals outlook. Looking at the patch analysis, a few questions come to mind. Well, I'm sure that some of you are already asking yourselves these questions. Well, the whole hyperlink creation goes through the MSOHRLink createFromString, where that flag was being set to true. What about other code flows that may reach the unsafe API, the MKParsDisplayName? What about the application ID? We've seen comparison to outlook only. What about other apps? To answer these questions, I want to do a quick recap. The following diagram demonstrates the interesting API calls when clicking on a composite moniker hyperlink within an email, before the patch was employed. And this is how it looks after the patch. We have the addition of the block MKParsDisplayName flag that is being set to true at the beginning, as we said, and the detoured function checks that flag and acts accordingly. We were looking for ways to get to the unsafe API, the MKParsDisplayName, without going through the function that sets that flag to true, and we found a candidate, the hrpmon from URL. We found that doing some cross-referencing through the relevant API calls, and we've seen that this one may reach the unsafe API. And as a matter of fact, this is how we got to discover the RC vulnerability in Outlook. When you pass a composite moniker within an image tag, the parsing of that composite moniker won't go through the mso-hrlink-reform string that was patched. Instead, it will invoke the hrpmon from URL that handles the parsing of the URLs from image tags, and it will directly call the hlink-parsDisplayName that will eventually get the same code flow that reaches to the unsafe API, MKParsDisplayName. Now that we are familiar with how Microsoft patches some vulnerabilities in Office applications, the patch is quite obvious, right? Setting the infamous flag to true, but this time from hrpmon from URL, and again, only if the application ID equals Outlook. Now, to sum up these two patches, we saw that Microsoft only addresses specific code flows and specific scenarios that leads to the unsafe API, the MKParsDisplayName, and we left some questions open for you to investigate, and we are certain that there are more applications and more code flows that leads to that unsafe API. Okay, just some additional notes. As Arnold shared, and thank you, Arnold, Microsoft patched the remote code execution by introducing this additional hook and turning on the flag through this control flow. It didn't solve the NTLM leak. Now, we obviously didn't want to publish it, but we got a response from Microsoft that there is a medium risk, and for Microsoft it's not an urgency, and the fact that the image cannot be automatically downloaded because you have kind of a preview mode, if the sender is not trusted, and they are right. If the sender is not trusted, the image will not be automatically downloaded, and the compound moniker will not be automatically executed, but if the sender is trusted, again, someone in the organization, let's say, was compromised, and you're utilizing his credential to send to the other victim within the same organization, the same link, the image will be automatically downloaded or previewed, and the NTLM will happen, and this unfortunately wasn't patched. So let's just finalize. We have a couple of minutes left. Some recommendations. Some of them are obvious. Microsoft basically writes a lot about some of the recommendations. Obviously, in four scare bureaus, Windows 11 introduces, I think, an update, already introduced update, in which by default NTLM authentication will not be possible. I suppose it will not hold for long due to backward compatibilities, etc. Definitely enable SMB signing and manage your outbound SMB. You don't want that kind of, let's say, network communication going outside of your organization. And there are definitely additional recommendations that can follow. Now, just before we kind of end the presentation, some credit references. Again, as we mentioned, NetSpy is doing great work discovering new stuff. Checkpoint also, as well. And so is Etienne Stevens. I'm sure I'm missing a lot of other folks because a lot of work is being invested. You guys are welcome to ask our questions. We will be waiting here behind the entry door for like 10 minutes. But overall, we are done. It's an honor to present at the DEF CON. We are thanking you to come here to see our presentation. Thank you very much.