[00:00.000 --> 00:10.780] Good afternoon everyone. It is 3 p.m. at DEF CON 31. Welcome to Village Talks. This [00:10.780 --> 00:17.660] next talk is presented by the Packet Hacking Village. The Packet Hacking Village talk, [00:17.660 --> 00:24.460] the whole premise is, is to give information and content that people can grasp and use [00:24.460 --> 00:33.960] immediately. This next talk that we're going to present, remember when we did the CFP for [00:33.960 --> 00:43.820] this, and it caught our attention right away. And Riverside said, we have to accept this [00:43.820 --> 00:50.100] talk. This talk looks really, really good. And it is my pleasure to introduce to you [00:50.100 --> 01:01.720] someone who I've gotten to know pretty well within the last, what, 24, 48 hours. Jared [01:01.720 --> 01:08.720] Stroud, who is a security lead at the MITRE Corporation. And one of the things is, is that I [01:08.720 --> 01:14.240] will want to let everyone know here, who here is this is your first DEF CON? Is this is your [01:14.240 --> 01:23.540] first DEF CON? Welcome. And please take advantage of your learning opportunities. But I also [01:23.540 --> 01:30.980] warn each and every one of you as well too. And Jared is, sir, gave, served as a really, really [01:30.980 --> 01:37.000] good warning. I don't know if you all know, but the tech and the secure, the tech and [01:37.000 --> 01:43.900] especially the security community is extremely small. Do you know how they say, what is that [01:43.900 --> 01:49.060] thing that they said about the uh, the six degrees of Kevin Bacon is it? Is that what it's [01:49.060 --> 01:56.060] called? Something like that? Here, if you're at DEF CON, like the degree of separation is not [01:56.060 --> 02:03.680] even six. It's like more like one or two. And it is just absolutely crazy to hear, you know, [02:03.680 --> 02:12.180] that former students and friends have while working with Jared. And it's just like [02:12.180 --> 02:18.080] absolutely and this is, and I've been at DEF CON for many, many years and this has been, it [02:18.080 --> 02:23.840] just happened each and every year when I'm here. So just to let you know is that, you know, [02:23.840 --> 02:28.520] you don't even, chances are you'll probably know who you're going to be talking to or you [02:28.520 --> 02:32.600] probably have, you know, a little bit about the person next to you. So just be careful that the [02:32.600 --> 02:38.320] degree of separation is extremely small. But nonetheless, it is my pleasure to introduce to [02:38.320 --> 02:45.080] you, Jared Stroud, who's going to talk about line pairing with malware. Take it away. [02:49.960 --> 02:54.600] Alright. Well thank you Ming and thank you Packet Hacking Village for having me. DEF CON, [02:54.600 --> 03:00.440] this is awesome. That was a really nice introduction. Hope this doesn't suck. So, how's [03:00.440 --> 03:07.520] everybody doing today? Alright, not hungover at all. Exciting. Cool. So, my name is Jared [03:07.520 --> 03:12.160] Stroud. On the internet, I am DLO Cool J. And today we're going to be talking about line [03:12.160 --> 03:17.880] pairing with malware and some fun we can have across the way. So, fun disclaimer, but [03:17.880 --> 03:23.260] since it's DEF CON, we don't read those. I am a lead security engineer at the MITRE [03:23.260 --> 03:27.820] Corporation. I'm also an adjunct lecturer at the Rochester Institute of Technology. Go [03:27.820 --> 03:34.040] Tigers. And additionally, recently I actually just was a finalist in the Sentinel 1 and VX [03:34.040 --> 03:38.860] Underground Malware Analyst Competition. And that's where a lot of the talk is going to come [03:38.860 --> 03:43.420] from. Some of the side work that I do at home in my home lab and some interesting things [03:43.420 --> 03:48.660] around malware. And additionally, after this, come swing by the contest village. I'm [03:48.660 --> 03:52.960] helping run a contest called Battle of the Bots. Also Hack Fortress. Would love to chat more [03:52.960 --> 03:58.740] later. Cool. So, why are we here? Right? And again, thank you all for coming. We're going to [03:58.740 --> 04:03.160] talk about what wine is. So, if you've never heard of wine, don't worry. But out of [04:03.160 --> 04:09.620] curiosity, how many people have heard of wine? Awesome. A lot of hands. Also out of [04:09.620 --> 04:16.440] curiosity, how many people have had issues with wine? Somehow more hands went up. I'm a [04:16.440 --> 04:21.020] little confused about that. But excellent. Hopefully I can shed some light into this. So, [04:21.020 --> 04:26.080] we're going to talk about how wine works and why we care about using wine for both offensive [04:26.080 --> 04:30.300] and defensive purposes. And my big goal is to get you to walk away with some actionable [04:30.300 --> 04:37.600] evidence today that makes sense for both, again, offensive and defensive things. Cool. So, [04:37.600 --> 04:42.800] this all got started because, again, I have a home lab that I'm super passionate about and I [04:42.800 --> 04:47.300] call that Arch Cloud Labs. I blog about silly things related to malware. Now more than [04:47.300 --> 04:52.700] ever, anyone can go and grab APT samples from a VX underground or a mal share and start [04:52.700 --> 04:56.940] digging in and doing their own reverse engineering, their own blue teamwork or red [04:56.940 --> 05:01.440] teamwork where they're trying to emulate threats. That's really cool. Never has that [05:01.440 --> 05:06.800] happened before. And along with releases like Ghidra and various other open source tools [05:06.800 --> 05:11.960] with Yara, you can really build your own blue team D4 home lab and get those skills up for [05:12.560 --> 05:18.080] whether it be like contests or employment, whatever the case may be. But something that I [05:18.080 --> 05:23.140] was running into in my home lab, if you get a big old batch of malware, going in and [05:23.140 --> 05:29.220] executing this to get those initial artifacts is a super big pain. I want DNS requests. I [05:29.220 --> 05:33.660] want outbound TCP and UDP. I want all that good data. But I don't want the overhead of [05:33.660 --> 05:38.280] actually managing that infrastructure. I don't want to have to run an ESXI cluster and [05:38.280 --> 05:42.560] then install cuckoo and manage my base images. And then after I run the malware, take [05:42.560 --> 05:47.440] snapshots, store those snapshots, and at some point I finally get the PCAP and go, okay, [05:47.440 --> 05:51.140] here's the domain that this cobalt strike beacon was calling out to. This seems like too [05:51.140 --> 05:55.400] much. This is all too much. I want initial artifacts that I can immediately start digging [05:55.400 --> 06:02.500] into. So with that, I started to take a look at wine. Right? And again, seems like a lot of [06:02.500 --> 06:06.280] people in here know wine. I'm going to take a shot in the dark and say that some people may [06:06.280 --> 06:12.240] know that from valve and steam and their fork of it called proton. But if you've never heard [06:12.240 --> 06:17.580] of wine before, wine is a recursive acronym that stands for wine is not an emulator. It does [06:17.580 --> 06:22.960] not do emulation of win 32 API calls. It does translation from whatever is happening in the [06:22.960 --> 06:28.420] windows world and DLLs and kernels and so on and so forth into the posit calls equivalent. So [06:28.420 --> 06:34.940] it's actually executing him on the underlying Linux kernel. So this is really cool. Right? So [06:34.940 --> 06:40.000] with this, it's a open source project that's labeled or that's under the GPL license and [06:40.000 --> 06:45.880] there's a couple of commercial backers. Notably valve and their proton release of that which [06:45.880 --> 06:52.320] is really just focused around some fixes of graphics drivers and more intense things to run [06:52.320 --> 06:56.960] triple A games. And then there's also code weavers. And code weavers has a tool called [06:56.960 --> 07:01.160] crossover and crossover is just trying to help you run whatever your windows software of [07:01.160 --> 07:08.660] choice is on Linux a little bit easier. That being said, the core of wine is a free open [07:08.660 --> 07:13.640] source product that is getting all of these contributions rolling in all the time. There's [07:13.640 --> 07:17.900] three different staging branches of excuse me, there's three different branches of wine. You [07:17.900 --> 07:21.880] have your staging branches where some bug fixes are coming in. It's not quite stable. You [07:21.880 --> 07:26.320] have stable and you have some release candidates as well. So this is a very active project [07:26.320 --> 07:31.200] that's constantly getting new patches submitted upstream and this example that I have on the [07:31.200 --> 07:35.380] screen here is just to show, hey, folks from valve are submitting their upstreams. Folks [07:35.380 --> 07:39.380] from crossover are submitting their upstream patches and overall that wine project keeps [07:39.380 --> 07:45.340] getting better and better over time. So with this, let's go ahead and take a look at how wine [07:45.340 --> 07:49.640] actually works underneath the hood and how we can start thinking about ways that we can use [07:49.640 --> 07:55.740] it for our workflows. So when you run wine and then whatever exe, like malware.exe or [07:55.740 --> 08:00.660] Microsoft office.exe, what's happening underneath the hood is a separate service is getting [08:00.660 --> 08:05.520] spun up, excuse me, a separate process called wine server. Wine server is going to go ahead [08:05.520 --> 08:10.700] and create a Unix socket that your main process is going to talk to it over. This wine server [08:10.700 --> 08:15.640] is then going to load its DLLs which are really just Linux shared objects that are going to do [08:15.640 --> 08:23.180] all of that translation to the underlying Linux API calls from the Windows 32 calls. As an [08:23.180 --> 08:29.800] example, up here to my right, we see the MSDN documentation for git native system info. It's [08:29.800 --> 08:34.440] going to go ahead and take in some pointer to some struct, populate that data and return it [08:34.440 --> 08:41.060] to you. And then the wine equivalent over here, you take in some struct of sys info, you [08:41.060 --> 08:47.240] start populating it as we go down the path. So all of the magic of that actual translation [08:47.240 --> 08:51.820] where that's occurring is in these DLLs. That's going to be an important thing to keep in [08:51.820 --> 08:58.300] mind that we'll circle back on later how we can use that to our advantage. So at this point [08:58.300 --> 09:02.320] we're thinking, all right, that's pretty cool. We can start seeing like you can execute [09:02.320 --> 09:09.400] maybe an interpreter shell or something like that on a Linux system and start getting those [09:09.400 --> 09:14.760] artifacts. But naturally I'm not the first person to think of this. Doing a little bit of [09:14.760 --> 09:19.720] deep dive in both the academic and open source research, the earliest document I could find [09:19.720 --> 09:25.960] was from 2005 and it was a Linux.com article talking about running Windows viruses on [09:25.960 --> 09:33.340] Linux. And this was all getting done via wine. But the overall result was, hey, this sucks. [09:33.440 --> 09:38.060] We don't have, you know, the spammers aren't spamming, the worms aren't worming, it looks [09:38.060 --> 09:43.920] like Linux wins again. And that was kind of all you saw for a pretty long time. Then, excuse [09:43.920 --> 09:54.130] me, but it does pose the question of as wine got better over time, does Windows malware pose a [09:54.130 --> 09:59.770] threat to Linux servers, right? Now, any Linux admin or Linux user over there is probably [09:59.770 --> 10:03.630] thinking right now, well, wine's not installed by default. I'm not super concerned about [10:03.630 --> 10:08.510] that. But that is a lot of the angles that academia take of, hey, can we run these Windows [10:08.510 --> 10:15.950] samples on a Linux machine if wine is installed and will the damage be equivalent? And the [10:15.950 --> 10:21.270] overall result from these papers was maybe and a lot of that came out from the samples that [10:21.270 --> 10:25.870] they were picking. And when I say samples, I'm referring to malware samples. Largely this [10:25.870 --> 10:30.450] was just an arbitrary selection of whatever malware dump the researcher had to them at the [10:30.450 --> 10:35.070] time. In a lot of situations, the malware they were executing was dependent on external [10:35.070 --> 10:41.450] services that wine did not spawn. For example, with Mimi cats, there is no LSAS process. So [10:41.450 --> 10:45.150] if you have some kind of precompiled binary that's going to try to dump from LSAS, it's [10:45.150 --> 10:49.070] immediately going to fail. That's not the fault of wine, that's just the service doesn't [10:49.070 --> 10:53.890] exist. Same thing to be said about trying to poke at an active directory server. You know, [10:53.890 --> 10:58.250] you can go from there with the other dependencies that may exist. Additionally, a lot of [10:58.250 --> 11:03.370] these academic research projects were using open source projects that wrapped wine but did [11:03.370 --> 11:08.670] not use wine directly themselves. And these open source projects were largely abandonware. A [11:08.670 --> 11:15.510] paper from 2018 was leveraging something that wasn't last updated from 2013. But I'm here to [11:15.510 --> 11:20.410] talk to you today about saying not all hope is lost. We can actually build our own [11:20.410 --> 11:27.030] execution environment with thinly wrapped wine wrappers to execute malware. So this is [11:27.030 --> 11:31.970] where my talk title actually kind of comes full circle here. This is the wine pairing with [11:31.970 --> 11:36.830] malware. We have to pick our samples appropriately to make sure that we're not going to be [11:36.830 --> 11:42.350] dependent on some kind of foreign service that isn't going to run in wine. Now, that doesn't [11:42.350 --> 11:47.930] mean you need an aged cobalt strike to pair with a newer release of wine. You can just go [11:47.930 --> 11:54.190] ahead and grab the latest version of wine off the website and execute it against the samples [11:54.190 --> 12:00.210] that you have today. Looking at the threat trends, we're seeing from a SOPHOS report [12:00.210 --> 12:04.770] released about last month, we're seeing that Meterpreter and Metasploit and its associated [12:04.770 --> 12:10.290] projects and payloads are kind of on the rise, right, to the surprise of no one. Criminal [12:10.290 --> 12:15.510] groups and APT actors alike, maybe a shell code runner's difference, but Metasploit gets used a [12:15.510 --> 12:20.710] lot. It's very scriptable. It's very easy to make to use into whatever offensive workflow you [12:20.710 --> 12:28.090] have. Looking at a 2013 report from Red Canary, they said that cobalt strike and Metasploit [12:28.090 --> 12:32.570] continue to be the most popular C2 framework with a couple of other open source and [12:32.570 --> 12:37.990] commercial vendors on the rise. Those include Brute Radle, Sliver and Mythic. But again, [12:37.990 --> 12:41.750] we're seeing the usual suspects here, right? We're not surprised at what we're seeing. We're [12:41.750 --> 12:46.430] seeing Metasploit, we're seeing cobalt strike and a handful of offensive frameworks. So [12:46.430 --> 12:51.490] with that, why grab all of these random old ransomware samples or old malware samples? Why [12:51.490 --> 12:56.610] not test what is likely going to end up at some point in the ticket queue for your SOC? And [12:56.610 --> 13:02.150] then what can you do with that information? So for my research, I picked these three [13:02.150 --> 13:10.850] frameworks largely because of their ubiquitousness in the APT and crimeware world as well as the [13:10.850 --> 13:15.130] ability to kind of make a little lab for everybody to test out afterwards with Metasploit, [13:15.130 --> 13:20.790] right? So cobalt strike, no surprise there. Human operated ransomware groups continue to use [13:20.790 --> 13:25.930] this. Same thing with APT groups. Empire is getting picked up more by APT groups and [13:25.930 --> 13:30.830] notably it has C sharp functionality. So that's a nice little twist at Metasploit because [13:30.830 --> 13:37.550] again, Metasploit. So let's go ahead and start talking about why we're using wine and not just [13:37.550 --> 13:41.950] spinning up a Windows VM to actually do this execution, right? We love Linux because of its [13:41.950 --> 13:46.090] flexibility. We want to pipe set and awk and grep our way to victory. We want to get those [13:46.090 --> 13:50.670] initial shared objects. Again, I don't want to have to instrument a whole ESXI workflow to get [13:50.670 --> 13:56.650] these artifacts. And what we're having shown here is a very, very, very simple example of [13:56.650 --> 14:01.530] instrumenting this execution with a container. I go ahead and spin up a container that simply [14:01.530 --> 14:07.410] copies my malware over, runs wine and then on the underlying host, I'm capturing that data [14:07.410 --> 14:11.990] with wire shark, a TCP dump, whatever you may have you. And then also I'm getting the rest of [14:11.990 --> 14:21.430] the host based artifacts in what's known as a wine prefix. Looking at, you know, scaling this [14:21.430 --> 14:28.150] execution, we can go ahead and actually take our container with pod man and generate the YAML [14:28.150 --> 14:33.490] to get it to execute in Kubernetes as well. So while we're doing basic example execution with [14:33.490 --> 14:37.410] just one sample, that's not to say that you can't actually scale this to handle all of the [14:37.410 --> 14:42.830] daily dump that you're getting from virus total mal share or VX underground. But I talked [14:42.830 --> 14:47.830] about a wine prefix a moment ago and we're going to dive deeper into that. Your wine prefix is [14:47.830 --> 14:53.970] effectively your C drive or a wrapper for the C drive for the underlying wine environment. Here [14:53.970 --> 15:00.010] we see DOS devices end up being your com objects, drive C is the C drive and then you have a [15:00.010 --> 15:05.330] handful of registry files that get created as well. When you're executing a malware sample [15:05.330 --> 15:11.590] with wine, you can go ahead and create a unique wine prefix per sample. Suddenly you have N [15:11.590 --> 15:16.350] number of wine prefixes for N number of samples and again you can sed, awk and grep your way [15:16.350 --> 15:22.470] for those artifacts and start looking at what's going on there. Looking at the two files [15:22.470 --> 15:28.270] that we have here of user def dot reg and user dot reg, these are the, excuse me, the [15:28.270 --> 15:33.090] difference here is that user def dot reg is the default registry keys that get created and [15:33.090 --> 15:38.310] user dot reg are the registry keys that get created after execution. So if a malware sample [15:38.310 --> 15:42.750] goes and creates registry keys and is trying to do a UAC bypass, you can easily diff these [15:42.750 --> 15:48.430] files and see the changes. That's pretty sweet compared to using red shot, taking snapshots [15:48.430 --> 15:53.210] and reverting. That's very fast. That shortens your workflow for basic samples that you may [15:53.210 --> 16:00.250] be pulling in from a virus total or what have you. Looking at this in a slightly different [16:00.250 --> 16:05.050] light, if we went ahead and got an interpreter session through wine, started executing [16:05.050 --> 16:12.730] commands and dumping data to files like we see here at 1, malware does a thing, I'm just [16:12.730 --> 16:19.410] listing the contents of a directory, we can jump down to the host machine, in that wine [16:19.410 --> 16:24.830] prefix we can grab whatever files are getting dropped. So again, that wine prefix ends up [16:24.830 --> 16:29.450] being a pretty neat thing that we can tar up and move to a file system without having to [16:29.450 --> 16:36.870] juggle VMDKs and any big virtual disk images. That's pretty neat. The same can be said about [16:36.870 --> 16:44.550] the registry. As I stated earlier, we just go ahead and can cat user.reg, pipe grep for [16:44.550 --> 16:49.830] HKCU and start looking at newly created registry keys. Up at the top here, I'm simply [16:49.830 --> 16:55.970] using a post exploitation module from Metasploit to create a run once key so on boot I will [16:55.970 --> 17:00.410] get my session restored. Nothing super crazy but a demonstration of how this could be [17:00.410 --> 17:06.850] beneficial to you. Cool. So you didn't just come here for me to tell you, hey, run wine [17:06.850 --> 17:12.370] and then evil.exe and get your IOCs. That's not why we're here. The real magic is in the [17:12.370 --> 17:18.810] DLLs as I said earlier. What you can do is effectively build your own DLLs to get loaded at [17:18.810 --> 17:24.050] run time and then start instrumenting your execution. What do I mean by that? Well, if [17:24.050 --> 17:29.150] there's specific API calls you want to capture more data on dynamically, you can go ahead [17:29.150 --> 17:34.210] and grab that data, send it to a sim, write it to a file or otherwise ingest it into your [17:34.210 --> 17:40.150] workflow to start gathering more valuable intelligence information. Additionally, wine [17:40.150 --> 17:46.110] has the equivalent of an LD preload where you can say, hey, look here for my shared [17:46.110 --> 17:50.470] objects. So you don't need to recompile wine every time you want to suddenly get say [17:50.470 --> 17:55.110] registry keys like I have on the screen. You can simply have a directory for your custom [17:55.110 --> 17:59.510] shared objects, load them when you need them to get that data and then otherwise execute [17:59.510 --> 18:04.430] wine normally. So this is super powerful especially when you start thinking about [18:04.430 --> 18:11.570] altering return values and really controlling the execution of malware as a whole. But it's [18:11.570 --> 18:17.410] not perfect. Wine again is trying its best to go ahead and provide a one to one translation [18:17.410 --> 18:22.170] for these calls. But when things go awry, you can't just say, oh, this is broken, this isn't [18:22.170 --> 18:26.050] good. You have to dig a little bit deeper and look at the source code. For example, the [18:26.050 --> 18:29.970] anti-malware scan interface at the time of this recording of this talk, if we go ahead and [18:29.970 --> 18:34.990] look, all this simply does is return, hey, there's no malware here. Everything's good. Just [18:34.990 --> 18:39.750] go ahead and execute that. So this is an example of where you need to dive deeper and [18:39.750 --> 18:44.230] understand what these return values are going to be from wine. But the neat thing about this [18:44.230 --> 18:49.810] also is that, well, if AMSI is always returning, hey, this isn't malware, maybe this is an [18:49.810 --> 18:54.330] opportunity to start looking at fuzzing targets and playing around with other Windows [18:54.330 --> 19:03.710] software that leverages AMSI, right? Could be a neat thing to explore. But for my red team [19:03.710 --> 19:09.170] focused friends, there's also hope for you as well. If we go ahead and take a look at an [19:09.170 --> 19:14.890] example offensive development life cycle up here, right? Maybe you leave DEF CON, you're on [19:14.890 --> 19:20.170] Twitter, X or Mastodon, pick your social media site and you get a new idea for some blog or [19:20.170 --> 19:23.630] some talk post and you're like, hey, this is a pretty cool thing I want to integrate into my [19:23.630 --> 19:27.510] offensive workflow and I want to start messing around with it, right? So then you start [19:27.510 --> 19:32.730] developing that POC, integrating it with whatever offensive framework you get. Then you test [19:32.730 --> 19:37.350] in your range, you test in your VM, so on and so forth. Double check all the things and you [19:37.350 --> 19:41.950] finally get to the stage where you're ready to go and use that in an engagement. All of this is a [19:41.950 --> 19:46.990] fairly long cycle, right? You don't want to get caught as a red teamer. Well, I'm here to talk [19:46.990 --> 19:52.170] to you about shortening that churn zone by having faster feedback loops, right? Don't [19:52.170 --> 19:57.070] wait until your SCP or file share, your malware sample copies over, you can kind of execute [19:57.070 --> 20:01.050] everything on one host. So that's pretty powerful when you start thinking about shell code [20:01.050 --> 20:07.110] runners or looking at making sure that your tunnels are working the way that you expect them [20:07.110 --> 20:10.690] to. Simply running line and then whatever you're building, making sure that those tunnels [20:10.690 --> 20:16.550] exist and you're getting those callbacks is a quick way to avoid issues down the road. [20:17.790 --> 20:23.370] Additionally, it allows for much easier adoption for CICD for shell code runners. If I can go [20:23.370 --> 20:27.770] ahead and not have to spin up and maintain and patch and host a Windows service or Windows [20:27.770 --> 20:33.170] machine, excuse me, I can go ahead and just leverage a docker container, run wine with my [20:33.170 --> 20:38.150] shell code runner, verify that the output said, hey, you got a shell, you got execution and go [20:38.150 --> 20:41.810] on from there. And this is how you can start adopting software engineering practices into [20:41.810 --> 20:46.090] your offensive work flow. That's super powerful when you start considering maybe you want to [20:46.090 --> 20:49.970] play around with different frameworks or seeing how other frameworks are going to integrate. [20:49.970 --> 20:53.770] There's always a new thing written in rust or whatever the framework of the day is. Last year [20:53.770 --> 20:57.790] at DEF CON NIM was the hotness. This allows for a little bit easier integration and [20:57.790 --> 21:05.610] repeatability. And then looking for my friends that are leveraging more in memory execution, [21:05.610 --> 21:09.810] talking about beacon object files. If you're unfamiliar with beacon object files, they're [21:09.810 --> 21:15.250] made popular by cobalt strike. Effectively what they are is a way to execute a payload in [21:15.250 --> 21:21.530] memory without writing to disk. However, they're tricky to write. They have a limited C API. [21:21.970 --> 21:25.210] And if something goes wrong and they crash, well, you lose your beacon because it's [21:25.210 --> 21:31.310] executing in the process of beacon. That being said, Metasploit has its own beacon object file [21:31.310 --> 21:36.150] loader. And because we can execute Metasploit generated payloads with wine, we can [21:36.150 --> 21:41.330] suddenly create a feedback loop of writing a potentially complicated or maybe it's new to you [21:41.330 --> 21:46.990] boff file. Executing that in the meterpreter session via wine and ensuring that you're [21:46.990 --> 21:52.030] getting the output that you expect. So here with my meterpreter session, I'm leveraging trusted [21:52.030 --> 21:58.150] sex cough loader and there's situational awareness boffs to go and get the ARP information [21:58.150 --> 22:04.530] of the host that I'm executing on. Pretty neat. Furthermore, you can grab all of this output [22:04.530 --> 22:08.690] through Metasploit because of its easy scriptability features, making sure that you can [22:08.690 --> 22:14.610] or excuse me, allowing you to integrate it into your CICD workflows. But again, the world [22:14.610 --> 22:18.830] isn't perfect. It does fall short, right? I'm not suggesting you go and blow away all your [22:18.830 --> 22:23.430] Windows VMs and just go, hey, wine's great, let's do that from here on out. But this does [22:23.430 --> 22:30.290] shorten that initial proof of concept phase to get to the point to go and test as close to the [22:30.290 --> 22:35.730] target host as possible. Some of the issues that I've personally found is anything in [22:35.730 --> 22:40.970] kernel land, so doing direct sys calls, that's not a great time. And again, we have some [22:40.970 --> 22:45.330] issues with everything not being one to one with our API call implementations. For example, [22:45.330 --> 22:49.030] with those AMSI returns, we're always returning, hey, this isn't malware, this isn't a [22:49.030 --> 22:56.110] problem. So taking some time to look at the code base is super important. And wine by itself [22:56.110 --> 23:01.130] does not provide any sandboxing capabilities. So you still need a dedicated machine to [23:01.130 --> 23:06.490] execute malware on and isolate it appropriately, making sure that you're not about to run [23:06.490 --> 23:11.070] something on your host machine or machine you carry about. Additionally, for the folks [23:11.070 --> 23:15.330] that are interested in this from a how do I detect or evade this, there's a lot of very key [23:15.330 --> 23:20.130] artifacts that would show that you're running in a wine environment. Such as the name being [23:20.130 --> 23:27.110] such as some of the process names being wine. Additionally, wine for this is executing [23:27.110 --> 23:33.550] x86 and 64 bit PE files. So if you have some kind of old DOS binary or something like that, [23:33.550 --> 23:37.230] that's where you're going to start looking at DOS box and your results may vary there. And [23:37.230 --> 23:41.610] again, it is an evolving project. There are bugs. So there are unknown unknowns that you may [23:41.610 --> 23:46.030] run into. But for the vast majority of malware that is getting reported on by these [23:46.030 --> 23:50.950] threat intel companies as the most commonly seen, you can easily instrument an execution [23:50.950 --> 23:55.230] environment for the situations where maybe you don't want to upload that sample to virus [23:55.230 --> 24:02.810] total or maybe you don't have a cuckoo or the equivalent execution environment locally. So [24:02.810 --> 24:08.170] with all that being said, I will have a handful of key takeaways that I want you to go away [24:08.170 --> 24:11.390] from this talk, right? Because Packet Hacking Village is very much structured around [24:11.390 --> 24:18.190] actionable talks and being able to take something from them. Wine can execute trending [24:18.190 --> 24:23.650] malware in 2023. Absolutely a fact. You can go grab some cobalt strike off the shelf [24:24.330 --> 24:29.970] mess plate or grab some cobalt off the shelf artifact from mal share and execute it to get those [24:29.970 --> 24:35.670] DNS and host artifacts. You can also build custom DLLs to instrument your execution, grab [24:35.670 --> 24:40.590] additional artifacts or maybe some neat instrumentation that you're looking to do. And [24:40.590 --> 24:44.910] then Wine can also shorten the red team testing for our friends that are looking to do proof [24:44.910 --> 24:50.630] of concept stuff related to new ideas. I really want to give a shout out to everybody coming [24:50.630 --> 24:54.530] here to watch this. This means the world to me. So thank you very much. And then if any of [24:54.530 --> 24:58.710] this was interesting or you're looking at recreating this on your own, go ahead and take a [24:58.710 --> 25:03.630] screenshot of this. The slides and then some walk through examples of leveraging pod man and [25:03.630 --> 25:08.170] docker for creating these environments and doing the execution. They're all on GitHub as of [25:08.170 --> 25:13.450] about an hour ago. So definitely check these out. Create Git issues if you run into them. And [25:13.450 --> 25:17.930] I'll be around after this talk to chat more. Thank you all so much. I really appreciate it. [25:24.550 --> 25:29.670] Thank you, Jared. I can tell you right now, I can tell you're a good teacher. I can just tell. I was [25:29.670 --> 25:35.030] watching this whole thing. Now, if anyone actually have any questions for Jared, you can feel [25:35.030 --> 25:41.190] free to use the microphone. Yeah. If anyone will have a question for Jared, you can feel [25:41.190 --> 25:44.030] free to use the mic. Feel free. Yeah. It should be open. [25:47.560 --> 25:55.280] Hey, thanks for the talk. Just wondering, in your experience, as you mentioned, it's not a new [25:55.280 --> 26:01.660] thing to run it under wine. Have you seen malware that's either looking for wine to do [26:01.660 --> 26:06.560] something benign instead of its true payload? Or have you seen things that are actually looking [26:06.560 --> 26:14.590] to actively burn it down? Hello. Okay. Great question. So the question was, have I seen any [26:14.590 --> 26:19.330] malware samples that are looking for any wine artifacts that then do something different? I [26:19.330 --> 26:26.270] have not. I think largely, you know, a lot of socks have the ability to throw data to a virus [26:26.270 --> 26:30.230] total or equivalent. But for the situation such as home lab enthusiasts or people just getting [26:30.230 --> 26:38.590] started, wine provides a pretty neat opportunity to execute those payloads. I'm quite lazy and [26:38.590 --> 26:44.190] don't like running my own instrumentation or compiling my own stuff. Would you recommend any [26:44.190 --> 26:49.370] like L trace or S trace equivalents built into wine doing the dynamic instrumentation you [26:49.370 --> 26:56.170] recommend? I think I heard you. I think you said that you're looking for any kind of L trace [26:56.170 --> 27:01.070] or S trace equivalents built into wine. Cool. So wine does have a debugger that you can use to [27:01.070 --> 27:05.470] go just like GDB or win debug that you can go forth and start poking at memory addresses to [27:05.470 --> 27:11.170] dump it. Your results may vary on the success that you have there. But also in the same vein [27:11.170 --> 27:15.450] of things, because all of those syscalls are getting translated to the POSIX equivalent [27:15.450 --> 27:20.550] syscalls, you can check out S trace. Furthermore, two years ago I actually gave a talk on [27:20.550 --> 27:25.270] leveraging S trace for Linux binary analysis at hacking village that you will also find on [27:25.270 --> 27:35.100] that GitHub. So definitely check that out. Similar vein of question. How easy is it to [27:35.100 --> 27:45.010] like compile the shared libraries? Hello? Hello? Okay. How easy is it to compile the like shared [27:45.010 --> 27:50.950] libraries for wine to like do any kind of analysis on the things you? I'm sorry, I cannot [27:50.950 --> 27:58.470] hear you. I think I'm backing away. Okay. For yeah, for the shared libraries, is it like [27:58.490 --> 28:03.950] you compile it and it's like a Linux shared library that wine then loads or? Yeah, great [28:03.950 --> 28:09.070] question. So yes, it absolutely is a Linux shared library. And then you can get it to execute [28:09.070 --> 28:16.890] or return data or whatever you want to do. Yes. Hi, thanks for the talk. So you tried it out [28:16.890 --> 28:26.390] on Metasploit and Empire. These are both pretty well supported malware. Well, malware or [28:26.390 --> 28:32.950] red team tooling project. Have you tried this out on just random samples on VX underground, [28:32.950 --> 28:40.490] for example, that are often less or those samples support less Windows versions, for [28:40.490 --> 28:47.030] example? Yes, those are great questions. The question was, tried it out on Metasploit, [28:47.030 --> 28:51.150] Empire, Cobalt Strike. Have you tried it with other samples that you just kind of grab off of [28:51.150 --> 28:56.230] VX underground? So going back to kind of the home lab story here, I pull in daily dumps [28:56.230 --> 29:00.030] from MalShare. Those MalShare samples end up largely being Cobalt Strike and Returpreter [29:00.990 --> 29:07.830] samples. So my big target base is that. I haven't tested it on all or a bunch of VX underground [29:07.830 --> 29:13.970] samples, but I have thrown in some random things that are kind of custom built and I've had [29:13.970 --> 29:20.290] success. But your results may vary. All right. Thank you. Sounds cool. I'm going to try it [29:20.290 --> 29:29.640] out. All right. So you've made a bunch of changes to the Wine source code to do various [29:29.640 --> 29:36.980] things. Have you sent anything back upstream? And if so, how did that go? Yes, that's a [29:36.980 --> 29:40.660] great question. So the question was, you've made changes to the Wine source code. Have you [29:40.660 --> 29:44.700] submitted anything back upstream? So most of the changes that I've made have been to capture [29:44.700 --> 29:48.540] specific parameters that are getting passed into, say, like a reg query to then log off to [29:48.540 --> 29:53.220] the side. So these changes don't improve the overall functionality or support of Wine. [29:53.900 --> 29:58.220] WineHQ.com has an excellent breakdown on how to submit upstream patches, how to double check [29:58.220 --> 30:02.260] their bug tracker, so on and so forth of everything related to development. And I would [30:02.260 --> 30:06.760] highly encourage you to check that out. But for the small samples, or excuse me, for the small [30:06.760 --> 30:10.800] changes that I've made, it has been nothing substantial to go forth and contribute upstream. [30:25.540 --> 30:36.720] Anyone else? If I may, then sure, if there's time. So how easy is it to make changes to Wine in [30:36.720 --> 30:42.540] such a way that it behaves like a sandbox? Because many sandboxes do not only have the [30:42.540 --> 30:50.180] functionality of being a Windows box, but also making memory dumps, taking dumps of the [30:50.180 --> 30:57.800] network traffic, stuff like that. Test. So I think the question was, how easy is it to make [30:57.800 --> 31:03.900] changes to the underlying Wine source code? Did I hear you correctly? Yeah, so either the [31:03.900 --> 31:10.920] source code or just setting up... Sure. Just all of the things. Sure, sure, sure. So cool. So [31:10.920 --> 31:15.420] like, let's run through that really quick. So one of the things in the, like, lab repo thing [31:15.420 --> 31:19.600] that I have up here is I'm leveraging Podman over Docker. And the reason for that is you can [31:19.600 --> 31:25.600] actually pause containers when you're executing containers with Podman. So with that, if [31:25.600 --> 31:29.400] we're running a malware sample in Wine in a container with Podman and I pause that [31:29.400 --> 31:33.040] execution, we can go ahead and dump that memory and start taking a look at those artifacts [31:33.040 --> 31:37.440] that may get decrypted, decompressed, so on and so forth, right? Same example for a [31:37.440 --> 31:43.040] packed or encrypted sample or region of memory. For the situation of how easy is it to [31:43.040 --> 31:47.440] capture Wireshark data, it's as easy as literally spinning up Wireshark and selecting the [31:47.440 --> 31:51.780] interface and capturing it from there. But again, and I just want to double stop this, you [31:51.780 --> 31:55.300] know, Wine doesn't provide any kind of sandboxing features, so you still need that host [31:55.300 --> 32:00.280] to make, that host hardening and sanitization process to make sure that you're not about to [32:00.280 --> 32:02.920] run malware on a host you care about. [32:07.200 --> 32:09.700] Dan Shroud, everyone. Have a drink.