Good afternoon everyone. It is 3 p.m. at DEF CON 31. Welcome to Village Talks. This next talk is presented by the Packet Hacking Village. The Packet Hacking Village talk, the whole premise is, is to give information and content that people can grasp and use immediately. This next talk that we're going to present, remember when we did the CFP for this, and it caught our attention right away. And Riverside said, we have to accept this talk. This talk looks really, really good. And it is my pleasure to introduce to you someone who I've gotten to know pretty well within the last, what, 24, 48 hours. Jared Stroud, who is a security lead at the MITRE Corporation. And one of the things is, is that I will want to let everyone know here, who here is this is your first DEF CON? Is this is your first DEF CON? Welcome. And please take advantage of your learning opportunities. But I also warn each and every one of you as well too. And Jared is, sir, gave, served as a really, really good warning. I don't know if you all know, but the tech and the secure, the tech and especially the security community is extremely small. Do you know how they say, what is that thing that they said about the uh, the six degrees of Kevin Bacon is it? Is that what it's called? Something like that? Here, if you're at DEF CON, like the degree of separation is not even six. It's like more like one or two. And it is just absolutely crazy to hear, you know, that former students and friends have while working with Jared. And it's just like absolutely and this is, and I've been at DEF CON for many, many years and this has been, it just happened each and every year when I'm here. So just to let you know is that, you know, you don't even, chances are you'll probably know who you're going to be talking to or you probably have, you know, a little bit about the person next to you. So just be careful that the degree of separation is extremely small. But nonetheless, it is my pleasure to introduce to you, Jared Stroud, who's going to talk about line pairing with malware. Take it away. Alright. Well thank you Ming and thank you Packet Hacking Village for having me. DEF CON, this is awesome. That was a really nice introduction. Hope this doesn't suck. So, how's everybody doing today? Alright, not hungover at all. Exciting. Cool. So, my name is Jared Stroud. On the internet, I am DLO Cool J. And today we're going to be talking about line pairing with malware and some fun we can have across the way. So, fun disclaimer, but since it's DEF CON, we don't read those. I am a lead security engineer at the MITRE Corporation. I'm also an adjunct lecturer at the Rochester Institute of Technology. Go Tigers. And additionally, recently I actually just was a finalist in the Sentinel 1 and VX Underground Malware Analyst Competition. And that's where a lot of the talk is going to come from. Some of the side work that I do at home in my home lab and some interesting things around malware. And additionally, after this, come swing by the contest village. I'm helping run a contest called Battle of the Bots. Also Hack Fortress. Would love to chat more later. Cool. So, why are we here? Right? And again, thank you all for coming. We're going to talk about what wine is. So, if you've never heard of wine, don't worry. But out of curiosity, how many people have heard of wine? Awesome. A lot of hands. Also out of curiosity, how many people have had issues with wine? Somehow more hands went up. I'm a little confused about that. But excellent. Hopefully I can shed some light into this. So, we're going to talk about how wine works and why we care about using wine for both offensive and defensive purposes. And my big goal is to get you to walk away with some actionable evidence today that makes sense for both, again, offensive and defensive things. Cool. So, this all got started because, again, I have a home lab that I'm super passionate about and I call that Arch Cloud Labs. I blog about silly things related to malware. Now more than ever, anyone can go and grab APT samples from a VX underground or a mal share and start digging in and doing their own reverse engineering, their own blue teamwork or red teamwork where they're trying to emulate threats. That's really cool. Never has that happened before. And along with releases like Ghidra and various other open source tools with Yara, you can really build your own blue team D4 home lab and get those skills up for whether it be like contests or employment, whatever the case may be. But something that I was running into in my home lab, if you get a big old batch of malware, going in and executing this to get those initial artifacts is a super big pain. I want DNS requests. I want outbound TCP and UDP. I want all that good data. But I don't want the overhead of actually managing that infrastructure. I don't want to have to run an ESXI cluster and then install cuckoo and manage my base images. And then after I run the malware, take snapshots, store those snapshots, and at some point I finally get the PCAP and go, okay, here's the domain that this cobalt strike beacon was calling out to. This seems like too much. This is all too much. I want initial artifacts that I can immediately start digging into. So with that, I started to take a look at wine. Right? And again, seems like a lot of people in here know wine. I'm going to take a shot in the dark and say that some people may know that from valve and steam and their fork of it called proton. But if you've never heard of wine before, wine is a recursive acronym that stands for wine is not an emulator. It does not do emulation of win 32 API calls. It does translation from whatever is happening in the windows world and DLLs and kernels and so on and so forth into the posit calls equivalent. So it's actually executing him on the underlying Linux kernel. So this is really cool. Right? So with this, it's a open source project that's labeled or that's under the GPL license and there's a couple of commercial backers. Notably valve and their proton release of that which is really just focused around some fixes of graphics drivers and more intense things to run triple A games. And then there's also code weavers. And code weavers has a tool called crossover and crossover is just trying to help you run whatever your windows software of choice is on Linux a little bit easier. That being said, the core of wine is a free open source product that is getting all of these contributions rolling in all the time. There's three different staging branches of excuse me, there's three different branches of wine. You have your staging branches where some bug fixes are coming in. It's not quite stable. You have stable and you have some release candidates as well. So this is a very active project that's constantly getting new patches submitted upstream and this example that I have on the screen here is just to show, hey, folks from valve are submitting their upstreams. Folks from crossover are submitting their upstream patches and overall that wine project keeps getting better and better over time. So with this, let's go ahead and take a look at how wine actually works underneath the hood and how we can start thinking about ways that we can use it for our workflows. So when you run wine and then whatever exe, like malware.exe or Microsoft office.exe, what's happening underneath the hood is a separate service is getting spun up, excuse me, a separate process called wine server. Wine server is going to go ahead and create a Unix socket that your main process is going to talk to it over. This wine server is then going to load its DLLs which are really just Linux shared objects that are going to do all of that translation to the underlying Linux API calls from the Windows 32 calls. As an example, up here to my right, we see the MSDN documentation for git native system info. It's going to go ahead and take in some pointer to some struct, populate that data and return it to you. And then the wine equivalent over here, you take in some struct of sys info, you start populating it as we go down the path. So all of the magic of that actual translation where that's occurring is in these DLLs. That's going to be an important thing to keep in mind that we'll circle back on later how we can use that to our advantage. So at this point we're thinking, all right, that's pretty cool. We can start seeing like you can execute maybe an interpreter shell or something like that on a Linux system and start getting those artifacts. But naturally I'm not the first person to think of this. Doing a little bit of deep dive in both the academic and open source research, the earliest document I could find was from 2005 and it was a Linux.com article talking about running Windows viruses on Linux. And this was all getting done via wine. But the overall result was, hey, this sucks. We don't have, you know, the spammers aren't spamming, the worms aren't worming, it looks like Linux wins again. And that was kind of all you saw for a pretty long time. Then, excuse me, but it does pose the question of as wine got better over time, does Windows malware pose a threat to Linux servers, right? Now, any Linux admin or Linux user over there is probably thinking right now, well, wine's not installed by default. I'm not super concerned about that. But that is a lot of the angles that academia take of, hey, can we run these Windows samples on a Linux machine if wine is installed and will the damage be equivalent? And the overall result from these papers was maybe and a lot of that came out from the samples that they were picking. And when I say samples, I'm referring to malware samples. Largely this was just an arbitrary selection of whatever malware dump the researcher had to them at the time. In a lot of situations, the malware they were executing was dependent on external services that wine did not spawn. For example, with Mimi cats, there is no LSAS process. So if you have some kind of precompiled binary that's going to try to dump from LSAS, it's immediately going to fail. That's not the fault of wine, that's just the service doesn't exist. Same thing to be said about trying to poke at an active directory server. You know, you can go from there with the other dependencies that may exist. Additionally, a lot of these academic research projects were using open source projects that wrapped wine but did not use wine directly themselves. And these open source projects were largely abandonware. A paper from 2018 was leveraging something that wasn't last updated from 2013. But I'm here to talk to you today about saying not all hope is lost. We can actually build our own execution environment with thinly wrapped wine wrappers to execute malware. So this is where my talk title actually kind of comes full circle here. This is the wine pairing with malware. We have to pick our samples appropriately to make sure that we're not going to be dependent on some kind of foreign service that isn't going to run in wine. Now, that doesn't mean you need an aged cobalt strike to pair with a newer release of wine. You can just go ahead and grab the latest version of wine off the website and execute it against the samples that you have today. Looking at the threat trends, we're seeing from a SOPHOS report released about last month, we're seeing that Meterpreter and Metasploit and its associated projects and payloads are kind of on the rise, right, to the surprise of no one. Criminal groups and APT actors alike, maybe a shell code runner's difference, but Metasploit gets used a lot. It's very scriptable. It's very easy to make to use into whatever offensive workflow you have. Looking at a 2013 report from Red Canary, they said that cobalt strike and Metasploit continue to be the most popular C2 framework with a couple of other open source and commercial vendors on the rise. Those include Brute Radle, Sliver and Mythic. But again, we're seeing the usual suspects here, right? We're not surprised at what we're seeing. We're seeing Metasploit, we're seeing cobalt strike and a handful of offensive frameworks. So with that, why grab all of these random old ransomware samples or old malware samples? Why not test what is likely going to end up at some point in the ticket queue for your SOC? And then what can you do with that information? So for my research, I picked these three frameworks largely because of their ubiquitousness in the APT and crimeware world as well as the ability to kind of make a little lab for everybody to test out afterwards with Metasploit, right? So cobalt strike, no surprise there. Human operated ransomware groups continue to use this. Same thing with APT groups. Empire is getting picked up more by APT groups and notably it has C sharp functionality. So that's a nice little twist at Metasploit because again, Metasploit. So let's go ahead and start talking about why we're using wine and not just spinning up a Windows VM to actually do this execution, right? We love Linux because of its flexibility. We want to pipe set and awk and grep our way to victory. We want to get those initial shared objects. Again, I don't want to have to instrument a whole ESXI workflow to get these artifacts. And what we're having shown here is a very, very, very simple example of instrumenting this execution with a container. I go ahead and spin up a container that simply copies my malware over, runs wine and then on the underlying host, I'm capturing that data with wire shark, a TCP dump, whatever you may have you. And then also I'm getting the rest of the host based artifacts in what's known as a wine prefix. Looking at, you know, scaling this execution, we can go ahead and actually take our container with pod man and generate the YAML to get it to execute in Kubernetes as well. So while we're doing basic example execution with just one sample, that's not to say that you can't actually scale this to handle all of the daily dump that you're getting from virus total mal share or VX underground. But I talked about a wine prefix a moment ago and we're going to dive deeper into that. Your wine prefix is effectively your C drive or a wrapper for the C drive for the underlying wine environment. Here we see DOS devices end up being your com objects, drive C is the C drive and then you have a handful of registry files that get created as well. When you're executing a malware sample with wine, you can go ahead and create a unique wine prefix per sample. Suddenly you have N number of wine prefixes for N number of samples and again you can sed, awk and grep your way for those artifacts and start looking at what's going on there. Looking at the two files that we have here of user def dot reg and user dot reg, these are the, excuse me, the difference here is that user def dot reg is the default registry keys that get created and user dot reg are the registry keys that get created after execution. So if a malware sample goes and creates registry keys and is trying to do a UAC bypass, you can easily diff these files and see the changes. That's pretty sweet compared to using red shot, taking snapshots and reverting. That's very fast. That shortens your workflow for basic samples that you may be pulling in from a virus total or what have you. Looking at this in a slightly different light, if we went ahead and got an interpreter session through wine, started executing commands and dumping data to files like we see here at 1, malware does a thing, I'm just listing the contents of a directory, we can jump down to the host machine, in that wine prefix we can grab whatever files are getting dropped. So again, that wine prefix ends up being a pretty neat thing that we can tar up and move to a file system without having to juggle VMDKs and any big virtual disk images. That's pretty neat. The same can be said about the registry. As I stated earlier, we just go ahead and can cat user.reg, pipe grep for HKCU and start looking at newly created registry keys. Up at the top here, I'm simply using a post exploitation module from Metasploit to create a run once key so on boot I will get my session restored. Nothing super crazy but a demonstration of how this could be beneficial to you. Cool. So you didn't just come here for me to tell you, hey, run wine and then evil.exe and get your IOCs. That's not why we're here. The real magic is in the DLLs as I said earlier. What you can do is effectively build your own DLLs to get loaded at run time and then start instrumenting your execution. What do I mean by that? Well, if there's specific API calls you want to capture more data on dynamically, you can go ahead and grab that data, send it to a sim, write it to a file or otherwise ingest it into your workflow to start gathering more valuable intelligence information. Additionally, wine has the equivalent of an LD preload where you can say, hey, look here for my shared objects. So you don't need to recompile wine every time you want to suddenly get say registry keys like I have on the screen. You can simply have a directory for your custom shared objects, load them when you need them to get that data and then otherwise execute wine normally. So this is super powerful especially when you start thinking about altering return values and really controlling the execution of malware as a whole. But it's not perfect. Wine again is trying its best to go ahead and provide a one to one translation for these calls. But when things go awry, you can't just say, oh, this is broken, this isn't good. You have to dig a little bit deeper and look at the source code. For example, the anti-malware scan interface at the time of this recording of this talk, if we go ahead and look, all this simply does is return, hey, there's no malware here. Everything's good. Just go ahead and execute that. So this is an example of where you need to dive deeper and understand what these return values are going to be from wine. But the neat thing about this also is that, well, if AMSI is always returning, hey, this isn't malware, maybe this is an opportunity to start looking at fuzzing targets and playing around with other Windows software that leverages AMSI, right? Could be a neat thing to explore. But for my red team focused friends, there's also hope for you as well. If we go ahead and take a look at an example offensive development life cycle up here, right? Maybe you leave DEF CON, you're on Twitter, X or Mastodon, pick your social media site and you get a new idea for some blog or some talk post and you're like, hey, this is a pretty cool thing I want to integrate into my offensive workflow and I want to start messing around with it, right? So then you start developing that POC, integrating it with whatever offensive framework you get. Then you test in your range, you test in your VM, so on and so forth. Double check all the things and you finally get to the stage where you're ready to go and use that in an engagement. All of this is a fairly long cycle, right? You don't want to get caught as a red teamer. Well, I'm here to talk to you about shortening that churn zone by having faster feedback loops, right? Don't wait until your SCP or file share, your malware sample copies over, you can kind of execute everything on one host. So that's pretty powerful when you start thinking about shell code runners or looking at making sure that your tunnels are working the way that you expect them to. Simply running line and then whatever you're building, making sure that those tunnels exist and you're getting those callbacks is a quick way to avoid issues down the road. Additionally, it allows for much easier adoption for CICD for shell code runners. If I can go ahead and not have to spin up and maintain and patch and host a Windows service or Windows machine, excuse me, I can go ahead and just leverage a docker container, run wine with my shell code runner, verify that the output said, hey, you got a shell, you got execution and go on from there. And this is how you can start adopting software engineering practices into your offensive work flow. That's super powerful when you start considering maybe you want to play around with different frameworks or seeing how other frameworks are going to integrate. There's always a new thing written in rust or whatever the framework of the day is. Last year at DEF CON NIM was the hotness. This allows for a little bit easier integration and repeatability. And then looking for my friends that are leveraging more in memory execution, talking about beacon object files. If you're unfamiliar with beacon object files, they're made popular by cobalt strike. Effectively what they are is a way to execute a payload in memory without writing to disk. However, they're tricky to write. They have a limited C API. And if something goes wrong and they crash, well, you lose your beacon because it's executing in the process of beacon. That being said, Metasploit has its own beacon object file loader. And because we can execute Metasploit generated payloads with wine, we can suddenly create a feedback loop of writing a potentially complicated or maybe it's new to you boff file. Executing that in the meterpreter session via wine and ensuring that you're getting the output that you expect. So here with my meterpreter session, I'm leveraging trusted sex cough loader and there's situational awareness boffs to go and get the ARP information of the host that I'm executing on. Pretty neat. Furthermore, you can grab all of this output through Metasploit because of its easy scriptability features, making sure that you can or excuse me, allowing you to integrate it into your CICD workflows. But again, the world isn't perfect. It does fall short, right? I'm not suggesting you go and blow away all your Windows VMs and just go, hey, wine's great, let's do that from here on out. But this does shorten that initial proof of concept phase to get to the point to go and test as close to the target host as possible. Some of the issues that I've personally found is anything in kernel land, so doing direct sys calls, that's not a great time. And again, we have some issues with everything not being one to one with our API call implementations. For example, with those AMSI returns, we're always returning, hey, this isn't malware, this isn't a problem. So taking some time to look at the code base is super important. And wine by itself does not provide any sandboxing capabilities. So you still need a dedicated machine to execute malware on and isolate it appropriately, making sure that you're not about to run something on your host machine or machine you carry about. Additionally, for the folks that are interested in this from a how do I detect or evade this, there's a lot of very key artifacts that would show that you're running in a wine environment. Such as the name being such as some of the process names being wine. Additionally, wine for this is executing x86 and 64 bit PE files. So if you have some kind of old DOS binary or something like that, that's where you're going to start looking at DOS box and your results may vary there. And again, it is an evolving project. There are bugs. So there are unknown unknowns that you may run into. But for the vast majority of malware that is getting reported on by these threat intel companies as the most commonly seen, you can easily instrument an execution environment for the situations where maybe you don't want to upload that sample to virus total or maybe you don't have a cuckoo or the equivalent execution environment locally. So with all that being said, I will have a handful of key takeaways that I want you to go away from this talk, right? Because Packet Hacking Village is very much structured around actionable talks and being able to take something from them. Wine can execute trending malware in 2023. Absolutely a fact. You can go grab some cobalt strike off the shelf mess plate or grab some cobalt off the shelf artifact from mal share and execute it to get those DNS and host artifacts. You can also build custom DLLs to instrument your execution, grab additional artifacts or maybe some neat instrumentation that you're looking to do. And then Wine can also shorten the red team testing for our friends that are looking to do proof of concept stuff related to new ideas. I really want to give a shout out to everybody coming here to watch this. This means the world to me. So thank you very much. And then if any of this was interesting or you're looking at recreating this on your own, go ahead and take a screenshot of this. The slides and then some walk through examples of leveraging pod man and docker for creating these environments and doing the execution. They're all on GitHub as of about an hour ago. So definitely check these out. Create Git issues if you run into them. And I'll be around after this talk to chat more. Thank you all so much. I really appreciate it. Thank you, Jared. I can tell you right now, I can tell you're a good teacher. I can just tell. I was watching this whole thing. Now, if anyone actually have any questions for Jared, you can feel free to use the microphone. Yeah. If anyone will have a question for Jared, you can feel free to use the mic. Feel free. Yeah. It should be open. Hey, thanks for the talk. Just wondering, in your experience, as you mentioned, it's not a new thing to run it under wine. Have you seen malware that's either looking for wine to do something benign instead of its true payload? Or have you seen things that are actually looking to actively burn it down? Hello. Okay. Great question. So the question was, have I seen any malware samples that are looking for any wine artifacts that then do something different? I have not. I think largely, you know, a lot of socks have the ability to throw data to a virus total or equivalent. But for the situation such as home lab enthusiasts or people just getting started, wine provides a pretty neat opportunity to execute those payloads. I'm quite lazy and don't like running my own instrumentation or compiling my own stuff. Would you recommend any like L trace or S trace equivalents built into wine doing the dynamic instrumentation you recommend? I think I heard you. I think you said that you're looking for any kind of L trace or S trace equivalents built into wine. Cool. So wine does have a debugger that you can use to go just like GDB or win debug that you can go forth and start poking at memory addresses to dump it. Your results may vary on the success that you have there. But also in the same vein of things, because all of those syscalls are getting translated to the POSIX equivalent syscalls, you can check out S trace. Furthermore, two years ago I actually gave a talk on leveraging S trace for Linux binary analysis at hacking village that you will also find on that GitHub. So definitely check that out. Similar vein of question. How easy is it to like compile the shared libraries? Hello? Hello? Okay. How easy is it to compile the like shared libraries for wine to like do any kind of analysis on the things you? I'm sorry, I cannot hear you. I think I'm backing away. Okay. For yeah, for the shared libraries, is it like you compile it and it's like a Linux shared library that wine then loads or? Yeah, great question. So yes, it absolutely is a Linux shared library. And then you can get it to execute or return data or whatever you want to do. Yes. Hi, thanks for the talk. So you tried it out on Metasploit and Empire. These are both pretty well supported malware. Well, malware or red team tooling project. Have you tried this out on just random samples on VX underground, for example, that are often less or those samples support less Windows versions, for example? Yes, those are great questions. The question was, tried it out on Metasploit, Empire, Cobalt Strike. Have you tried it with other samples that you just kind of grab off of VX underground? So going back to kind of the home lab story here, I pull in daily dumps from MalShare. Those MalShare samples end up largely being Cobalt Strike and Returpreter samples. So my big target base is that. I haven't tested it on all or a bunch of VX underground samples, but I have thrown in some random things that are kind of custom built and I've had success. But your results may vary. All right. Thank you. Sounds cool. I'm going to try it out. All right. So you've made a bunch of changes to the Wine source code to do various things. Have you sent anything back upstream? And if so, how did that go? Yes, that's a great question. So the question was, you've made changes to the Wine source code. Have you submitted anything back upstream? So most of the changes that I've made have been to capture specific parameters that are getting passed into, say, like a reg query to then log off to the side. So these changes don't improve the overall functionality or support of Wine. WineHQ.com has an excellent breakdown on how to submit upstream patches, how to double check their bug tracker, so on and so forth of everything related to development. And I would highly encourage you to check that out. But for the small samples, or excuse me, for the small changes that I've made, it has been nothing substantial to go forth and contribute upstream. Anyone else? If I may, then sure, if there's time. So how easy is it to make changes to Wine in such a way that it behaves like a sandbox? Because many sandboxes do not only have the functionality of being a Windows box, but also making memory dumps, taking dumps of the network traffic, stuff like that. Test. So I think the question was, how easy is it to make changes to the underlying Wine source code? Did I hear you correctly? Yeah, so either the source code or just setting up... Sure. Just all of the things. Sure, sure, sure. So cool. So like, let's run through that really quick. So one of the things in the, like, lab repo thing that I have up here is I'm leveraging Podman over Docker. And the reason for that is you can actually pause containers when you're executing containers with Podman. So with that, if we're running a malware sample in Wine in a container with Podman and I pause that execution, we can go ahead and dump that memory and start taking a look at those artifacts that may get decrypted, decompressed, so on and so forth, right? Same example for a packed or encrypted sample or region of memory. For the situation of how easy is it to capture Wireshark data, it's as easy as literally spinning up Wireshark and selecting the interface and capturing it from there. But again, and I just want to double stop this, you know, Wine doesn't provide any kind of sandboxing features, so you still need that host to make, that host hardening and sanitization process to make sure that you're not about to run malware on a host you care about. Dan Shroud, everyone. Have a drink.