1 00:00:00,000 --> 00:00:01,400 Good afternoon everyone. 2 00:00:01,400 --> 00:00:03,040 It is 3 p.m. 3 00:00:03,040 --> 00:00:04,880 at DEF CON 31. 4 00:00:07,120 --> 00:00:09,520 Welcome to Village Talks. 5 00:00:10,140 --> 00:00:14,160 This next talk is presented by the Packet Hacking Village. 6 00:00:15,600 --> 00:00:25,880 The Packet Hacking Village talk, the whole premise is, is to give information and content that people can grasp and use immediately. 7 00:00:27,100 --> 00:00:39,820 This next talk that we're going to present, remember when we did the CFP for this, and it caught our attention right away. 8 00:00:40,400 --> 00:00:44,840 And Riverside said, we have to accept this talk. 9 00:00:45,160 --> 00:00:47,480 This talk looks really, really good. 10 00:00:47,480 --> 00:00:59,540 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. 11 00:01:01,260 --> 00:01:06,100 Jared Stroud, who is a security lead at the MITRE Corporation. 12 00:01:06,580 --> 00:01:13,480 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? 13 00:01:13,480 --> 00:01:15,760 Is this is your first DEF CON? 14 00:01:15,860 --> 00:01:17,060 Welcome. 15 00:01:17,960 --> 00:01:22,460 And please take advantage of your learning opportunities. 16 00:01:22,820 --> 00:01:27,040 But I also warn each and every one of you as well too. 17 00:01:27,040 --> 00:01:32,280 And Jared is, sir, gave, served as a really, really good warning. 18 00:01:32,840 --> 00:01:41,980 I don't know if you all know, but the tech and the secure, the tech and especially the security community is extremely small. 19 00:01:42,420 --> 00:01:48,040 Do you know how they say, what is that thing that they said about the uh, the six degrees of Kevin Bacon is it? 20 00:01:48,100 --> 00:01:49,580 Is that what it's called? 21 00:01:49,580 --> 00:01:51,000 Something like that? 22 00:01:51,380 --> 00:01:56,760 Here, if you're at DEF CON, like the degree of separation is not even six. 23 00:01:56,760 --> 00:01:59,460 It's like more like one or two. 24 00:01:59,460 --> 00:02:10,640 And it is just absolutely crazy to hear, you know, that former students and friends have while working with Jared. 25 00:02:10,860 --> 00:02:20,800 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. 26 00:02:20,800 --> 00:02:31,020 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. 27 00:02:31,020 --> 00:02:35,020 So just be careful that the degree of separation is extremely small. 28 00:02:35,060 --> 00:02:43,060 But nonetheless, it is my pleasure to introduce to you, Jared Stroud, who's going to talk about line pairing with malware. 29 00:02:44,040 --> 00:02:45,080 Take it away. 30 00:02:49,960 --> 00:02:50,920 Alright. 31 00:02:51,080 --> 00:02:54,020 Well thank you Ming and thank you Packet Hacking Village for having me. 32 00:02:54,020 --> 00:02:55,920 DEF CON, this is awesome. 33 00:02:56,180 --> 00:02:57,720 That was a really nice introduction. 34 00:02:57,720 --> 00:02:59,260 Hope this doesn't suck. 35 00:02:59,620 --> 00:03:01,660 So, how's everybody doing today? 36 00:03:02,420 --> 00:03:04,240 Alright, not hungover at all. 37 00:03:04,440 --> 00:03:05,400 Exciting. 38 00:03:05,420 --> 00:03:06,060 Cool. 39 00:03:06,060 --> 00:03:08,180 So, my name is Jared Stroud. 40 00:03:08,180 --> 00:03:10,200 On the internet, I am DLO Cool J. 41 00:03:10,480 --> 00:03:15,700 And today we're going to be talking about line pairing with malware and some fun we can have across the way. 42 00:03:16,500 --> 00:03:19,880 So, fun disclaimer, but since it's DEF CON, we don't read those. 43 00:03:20,560 --> 00:03:23,940 I am a lead security engineer at the MITRE Corporation. 44 00:03:23,940 --> 00:03:27,660 I'm also an adjunct lecturer at the Rochester Institute of Technology. 45 00:03:27,660 --> 00:03:28,580 Go Tigers. 46 00:03:28,820 --> 00:03:36,580 And additionally, recently I actually just was a finalist in the Sentinel 1 and VX Underground Malware Analyst Competition. 47 00:03:36,620 --> 00:03:39,360 And that's where a lot of the talk is going to come from. 48 00:03:39,360 --> 00:03:44,500 Some of the side work that I do at home in my home lab and some interesting things around malware. 49 00:03:45,040 --> 00:03:48,400 And additionally, after this, come swing by the contest village. 50 00:03:48,400 --> 00:03:50,560 I'm helping run a contest called Battle of the Bots. 51 00:03:50,560 --> 00:03:51,620 Also Hack Fortress. 52 00:03:51,620 --> 00:03:53,820 Would love to chat more later. 53 00:03:55,140 --> 00:03:55,660 Cool. 54 00:03:55,660 --> 00:03:56,600 So, why are we here? 55 00:03:56,600 --> 00:03:56,860 Right? 56 00:03:56,860 --> 00:03:58,400 And again, thank you all for coming. 57 00:03:58,400 --> 00:04:00,280 We're going to talk about what wine is. 58 00:04:00,280 --> 00:04:02,560 So, if you've never heard of wine, don't worry. 59 00:04:02,560 --> 00:04:06,520 But out of curiosity, how many people have heard of wine? 60 00:04:07,180 --> 00:04:07,860 Awesome. 61 00:04:07,860 --> 00:04:09,100 A lot of hands. 62 00:04:09,100 --> 00:04:13,540 Also out of curiosity, how many people have had issues with wine? 63 00:04:14,000 --> 00:04:15,760 Somehow more hands went up. 64 00:04:15,760 --> 00:04:17,800 I'm a little confused about that. 65 00:04:17,800 --> 00:04:18,800 But excellent. 66 00:04:18,800 --> 00:04:20,780 Hopefully I can shed some light into this. 67 00:04:20,820 --> 00:04:27,100 So, we're going to talk about how wine works and why we care about using wine for both offensive and defensive purposes. 68 00:04:27,260 --> 00:04:35,600 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. 69 00:04:36,420 --> 00:04:37,280 Cool. 70 00:04:37,320 --> 00:04:44,140 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. 71 00:04:44,140 --> 00:04:46,560 I blog about silly things related to malware. 72 00:04:46,640 --> 00:04:59,180 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. 73 00:04:59,220 --> 00:05:00,540 That's really cool. 74 00:05:00,540 --> 00:05:02,620 Never has that happened before. 75 00:05:02,620 --> 00:05:16,260 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. 76 00:05:16,860 --> 00:05:27,520 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. 77 00:05:27,520 --> 00:05:29,120 I want DNS requests. 78 00:05:29,120 --> 00:05:30,940 I want outbound TCP and UDP. 79 00:05:30,940 --> 00:05:32,400 I want all that good data. 80 00:05:32,400 --> 00:05:35,820 But I don't want the overhead of actually managing that infrastructure. 81 00:05:35,940 --> 00:05:40,920 I don't want to have to run an ESXI cluster and then install cuckoo and manage my base images. 82 00:05:40,920 --> 00:05:50,200 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. 83 00:05:50,200 --> 00:05:51,500 This seems like too much. 84 00:05:51,500 --> 00:05:52,500 This is all too much. 85 00:05:52,500 --> 00:05:56,260 I want initial artifacts that I can immediately start digging into. 86 00:05:57,500 --> 00:06:00,260 So with that, I started to take a look at wine. 87 00:06:00,320 --> 00:06:00,700 Right? 88 00:06:00,700 --> 00:06:03,720 And again, seems like a lot of people in here know wine. 89 00:06:03,720 --> 00:06:11,220 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. 90 00:06:11,400 --> 00:06:17,340 But if you've never heard of wine before, wine is a recursive acronym that stands for wine is not an emulator. 91 00:06:17,380 --> 00:06:20,280 It does not do emulation of win 32 API calls. 92 00:06:20,280 --> 00:06:28,380 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. 93 00:06:28,380 --> 00:06:32,360 So it's actually executing him on the underlying Linux kernel. 94 00:06:32,760 --> 00:06:34,160 So this is really cool. 95 00:06:34,160 --> 00:06:34,700 Right? 96 00:06:34,700 --> 00:06:42,180 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. 97 00:06:42,180 --> 00:06:53,540 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. 98 00:06:53,560 --> 00:06:54,980 And then there's also code weavers. 99 00:06:54,980 --> 00:07:03,800 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. 100 00:07:05,100 --> 00:07:13,320 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. 101 00:07:13,320 --> 00:07:17,880 There's three different staging branches of excuse me, there's three different branches of wine. 102 00:07:17,880 --> 00:07:20,520 You have your staging branches where some bug fixes are coming in. 103 00:07:20,520 --> 00:07:21,780 It's not quite stable. 104 00:07:21,780 --> 00:07:24,760 You have stable and you have some release candidates as well. 105 00:07:24,760 --> 00:07:35,260 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. 106 00:07:35,260 --> 00:07:41,420 Folks from crossover are submitting their upstream patches and overall that wine project keeps getting better and better over time. 107 00:07:42,220 --> 00:07:51,200 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. 108 00:07:51,600 --> 00:08:04,380 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. 109 00:08:04,380 --> 00:08:09,780 Wine server is going to go ahead and create a Unix socket that your main process is going to talk to it over. 110 00:08:09,780 --> 00:08:22,140 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. 111 00:08:22,580 --> 00:08:29,580 As an example, up here to my right, we see the MSDN documentation for git native system info. 112 00:08:29,580 --> 00:08:35,240 It's going to go ahead and take in some pointer to some struct, populate that data and return it to you. 113 00:08:35,240 --> 00:08:44,740 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. 114 00:08:44,740 --> 00:08:49,980 So all of the magic of that actual translation where that's occurring is in these DLLs. 115 00:08:49,980 --> 00:08:55,680 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. 116 00:08:57,260 --> 00:09:00,460 So at this point we're thinking, all right, that's pretty cool. 117 00:09:00,460 --> 00:09:10,300 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. 118 00:09:10,620 --> 00:09:13,820 But naturally I'm not the first person to think of this. 119 00:09:14,060 --> 00:09:26,840 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. 120 00:09:27,080 --> 00:09:29,600 And this was all getting done via wine. 121 00:09:29,980 --> 00:09:33,340 But the overall result was, hey, this sucks. 122 00:09:33,440 --> 00:09:39,860 We don't have, you know, the spammers aren't spamming, the worms aren't worming, it looks like Linux wins again. 123 00:09:39,860 --> 00:09:42,920 And that was kind of all you saw for a pretty long time. 124 00:09:43,140 --> 00:09:56,790 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? 125 00:09:57,170 --> 00:10:02,310 Now, any Linux admin or Linux user over there is probably thinking right now, well, wine's not installed by default. 126 00:10:02,310 --> 00:10:04,230 I'm not super concerned about that. 127 00:10:04,230 --> 00:10:14,730 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? 128 00:10:15,050 --> 00:10:22,270 And the overall result from these papers was maybe and a lot of that came out from the samples that they were picking. 129 00:10:22,810 --> 00:10:25,050 And when I say samples, I'm referring to malware samples. 130 00:10:25,270 --> 00:10:31,150 Largely this was just an arbitrary selection of whatever malware dump the researcher had to them at the time. 131 00:10:31,290 --> 00:10:37,610 In a lot of situations, the malware they were executing was dependent on external services that wine did not spawn. 132 00:10:37,970 --> 00:10:41,290 For example, with Mimi cats, there is no LSAS process. 133 00:10:41,450 --> 00:10:46,350 So if you have some kind of precompiled binary that's going to try to dump from LSAS, it's immediately going to fail. 134 00:10:46,450 --> 00:10:49,890 That's not the fault of wine, that's just the service doesn't exist. 135 00:10:49,970 --> 00:10:53,230 Same thing to be said about trying to poke at an active directory server. 136 00:10:53,690 --> 00:10:56,710 You know, you can go from there with the other dependencies that may exist. 137 00:10:57,230 --> 00:11:05,150 Additionally, a lot of these academic research projects were using open source projects that wrapped wine but did not use wine directly themselves. 138 00:11:05,150 --> 00:11:08,550 And these open source projects were largely abandonware. 139 00:11:08,550 --> 00:11:13,190 A paper from 2018 was leveraging something that wasn't last updated from 2013. 140 00:11:14,030 --> 00:11:18,950 But I'm here to talk to you today about saying not all hope is lost. 141 00:11:18,950 --> 00:11:25,910 We can actually build our own execution environment with thinly wrapped wine wrappers to execute malware. 142 00:11:26,590 --> 00:11:30,250 So this is where my talk title actually kind of comes full circle here. 143 00:11:30,250 --> 00:11:32,690 This is the wine pairing with malware. 144 00:11:32,690 --> 00:11:41,190 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. 145 00:11:41,330 --> 00:11:47,430 Now, that doesn't mean you need an aged cobalt strike to pair with a newer release of wine. 146 00:11:47,430 --> 00:11:55,610 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. 147 00:11:56,310 --> 00:12:09,990 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. 148 00:12:09,990 --> 00:12:15,890 Criminal groups and APT actors alike, maybe a shell code runner's difference, but Metasploit gets used a lot . 149 00:12:15,890 --> 00:12:16,870 It's very scriptable. 150 00:12:16,870 --> 00:12:21,350 It's very easy to make to use into whatever offensive workflow you have . 151 00:12:21,970 --> 00:12:33,970 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. 152 00:12:33,970 --> 00:12:37,370 Those include Brute Radle, Sliver and Mythic. 153 00:12:37,490 --> 00:12:40,010 But again, we're seeing the usual suspects here, right? 154 00:12:40,010 --> 00:12:41,670 We're not surprised at what we're seeing. 155 00:12:41,670 --> 00:12:46,110 We're seeing Metasploit, we're seeing cobalt strike and a handful of offensive frameworks. 156 00:12:46,270 --> 00:12:51,330 So with that, why grab all of these random old ransomware samples or old malware samples? 157 00:12:51,330 --> 00:12:56,510 Why not test what is likely going to end up at some point in the ticket queue for your SOC? 158 00:12:56,510 --> 00:12:58,810 And then what can you do with that information? 159 00:12:59,410 --> 00:13:15,770 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? 160 00:13:15,770 --> 00:13:18,310 So cobalt strike, no surprise there. 161 00:13:18,310 --> 00:13:21,350 Human operated ransomware groups continue to use this. 162 00:13:21,350 --> 00:13:23,190 Same thing with APT groups. 163 00:13:23,190 --> 00:13:28,590 Empire is getting picked up more by APT groups and notably it has C sharp functionality. 164 00:13:28,590 --> 00:13:32,370 So that's a nice little twist at Metasploit because again, Metasploit. 165 00:13:34,070 --> 00:13:40,590 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? 166 00:13:40,590 --> 00:13:42,810 We love Linux because of its flexibility. 167 00:13:42,810 --> 00:13:45,510 We want to pipe set and awk and grep our way to victory. 168 00:13:45,510 --> 00:13:47,090 We want to get those initial shared objects. 169 00:13:47,090 --> 00:13:51,750 Again, I don't want to have to instrument a whole ESXI workflow to get these artifacts. 170 00:13:51,950 --> 00:13:59,350 And what we're having shown here is a very, very, very simple example of instrumenting this execution with a container. 171 00:13:59,390 --> 00:14:10,370 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. 172 00:14:10,370 --> 00:14:15,890 And then also I'm getting the rest of the host based artifacts in what's known as a wine prefix. 173 00:14:18,430 --> 00:14:30,710 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. 174 00:14:30,890 --> 00:14:41,550 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. 175 00:14:42,310 --> 00:14:46,670 But I talked about a wine prefix a moment ago and we're going to dive deeper into that. 176 00:14:46,670 --> 00:14:53,870 Your wine prefix is effectively your C drive or a wrapper for the C drive for the underlying wine environment. 177 00:14:53,870 --> 00:15:03,070 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. 178 00:15:03,070 --> 00:15:10,090 When you're executing a malware sample with wine, you can go ahead and create a unique wine prefix per sample. 179 00:15:10,090 --> 00:15:19,590 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. 180 00:15:20,450 --> 00:15:36,910 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. 181 00:15:37,070 --> 00:15:44,850 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. 182 00:15:44,990 --> 00:15:49,150 That's pretty sweet compared to using red shot, taking snapshots and reverting. 183 00:15:49,150 --> 00:15:50,290 That's very fast. 184 00:15:50,290 --> 00:15:57,510 That shortens your workflow for basic samples that you may be pulling in from a virus total or what have you. 185 00:15:58,490 --> 00:16:16,550 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, 186 00:16:16,550 --> 00:16:22,230 we can jump down to the host machine, in that wine prefix we can grab whatever files are getting dropped. 187 00:16:22,730 --> 00:16:33,610 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. 188 00:16:33,610 --> 00:16:34,730 That's pretty neat. 189 00:16:35,550 --> 00:16:37,950 The same can be said about the registry. 190 00:16:38,170 --> 00:16:48,530 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. 191 00:16:48,530 --> 00:16:57,730 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. 192 00:16:57,750 --> 00:17:01,710 Nothing super crazy but a demonstration of how this could be beneficial to you. 193 00:17:03,050 --> 00:17:04,010 Cool. 194 00:17:04,010 --> 00:17:09,270 So you didn't just come here for me to tell you, hey, run wine and then evil.exe and get your IOCs. 195 00:17:09,270 --> 00:17:10,750 That's not why we're here. 196 00:17:10,870 --> 00:17:14,570 The real magic is in the DLLs as I said earlier. 197 00:17:14,750 --> 00:17:21,830 What you can do is effectively build your own DLLs to get loaded at run time and then start instrumenting your execution. 198 00:17:22,070 --> 00:17:23,450 What do I mean by that? 199 00:17:23,450 --> 00:17:38,530 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. 200 00:17:38,930 --> 00:17:46,830 Additionally, wine has the equivalent of an LD preload where you can say, hey, look here for my shared objects. 201 00:17:46,830 --> 00:17:52,570 So you don't need to recompile wine every time you want to suddenly get say registry keys like I have on the screen. 202 00:17:52,570 --> 00:18:00,890 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. 203 00:18:01,250 --> 00:18:09,730 So this is super powerful especially when you start thinking about altering return values and really controlling the execution of malware as a whole. 204 00:18:10,990 --> 00:18:12,510 But it's not perfect. 205 00:18:13,010 --> 00:18:18,690 Wine again is trying its best to go ahead and provide a one to one translation for these calls. 206 00:18:18,890 --> 00:18:22,470 But when things go awry, you can't just say, oh, this is broken, this isn't good. 207 00:18:22,470 --> 00:18:25,030 You have to dig a little bit deeper and look at the source code. 208 00:18:25,130 --> 00:18:34,270 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. 209 00:18:34,270 --> 00:18:34,890 Everything's good. 210 00:18:34,890 --> 00:18:36,530 Just go ahead and execute that. 211 00:18:36,590 --> 00:18:43,030 So this is an example of where you need to dive deeper and understand what these return values are going to be from wine. 212 00:18:43,150 --> 00:18:56,990 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? 213 00:18:57,130 --> 00:18:59,850 Could be a neat thing to explore. 214 00:19:02,130 --> 00:19:06,830 But for my red team focused friends, there's also hope for you as well. 215 00:19:07,030 --> 00:19:12,930 If we go ahead and take a look at an example offensive development life cycle up here, right? 216 00:19:12,930 --> 00:19:26,390 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, 217 00:19:26,390 --> 00:19:26,730 right? 218 00:19:26,730 --> 00:19:32,170 So then you start developing that POC, integrating it with whatever offensive framework you get. 219 00:19:32,170 --> 00:19:35,990 Then you test in your range, you test in your VM, so on and so forth. 220 00:19:36,030 --> 00:19:40,870 Double check all the things and you finally get to the stage where you're ready to go and use that in an engagement. 221 00:19:40,950 --> 00:19:43,110 All of this is a fairly long cycle, right? 222 00:19:43,110 --> 00:19:45,170 You don't want to get caught as a red teamer. 223 00:19:45,530 --> 00:19:51,910 Well, I'm here to talk to you about shortening that churn zone by having faster feedback loops, right? 224 00:19:51,930 --> 00:19:58,730 Don't wait until your SCP or file share, your malware sample copies over, you can kind of execute everything on one host. 225 00:19:58,730 --> 00:20:07,510 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. 226 00:20:07,510 --> 00:20:16,550 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. 227 00:20:17,790 --> 00:20:22,890 Additionally, it allows for much easier adoption for CICD for shell code runners. 228 00:20:22,910 --> 00:20:36,810 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, 229 00:20:36,810 --> 00:20:39,010 you got execution and go on from there. 230 00:20:39,010 --> 00:20:43,350 And this is how you can start adopting software engineering practices into your offensive work flow. 231 00:20:43,350 --> 00:20:49,970 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. 232 00:20:49,970 --> 00:20:53,530 There's always a new thing written in rust or whatever the framework of the day is. 233 00:20:53,530 --> 00:20:55,610 Last year at DEF CON NIM was the hotness. 234 00:20:55,610 --> 00:20:58,930 This allows for a little bit easier integration and repeatability. 235 00:21:00,810 --> 00:21:07,710 And then looking for my friends that are leveraging more in memory execution, talking about beacon object files. 236 00:21:07,710 --> 00:21:11,790 If you're unfamiliar with beacon object files, they're made popular by cobalt strike. 237 00:21:11,790 --> 00:21:17,310 Effectively what they are is a way to execute a payload in memory without writing to disk. 238 00:21:17,750 --> 00:21:19,210 However, they're tricky to write. 239 00:21:19,210 --> 00:21:21,530 They have a limited C API. 240 00:21:21,970 --> 00:21:27,750 And if something goes wrong and they crash, well, you lose your beacon because it's executing in the process of beacon. 241 00:21:27,890 --> 00:21:32,250 That being said, Metasploit has its own beacon object file loader. 242 00:21:32,250 --> 00:21:42,610 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. 243 00:21:42,630 --> 00:21:49,130 Executing that in the meterpreter session via wine and ensuring that you're getting the output that you expect. 244 00:21:49,190 --> 00:22:00,410 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. 245 00:22:00,930 --> 00:22:02,110 Pretty neat. 246 00:22:02,170 --> 00:22:13,210 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. 247 00:22:13,910 --> 00:22:15,370 But again, the world isn't perfect. 248 00:22:15,370 --> 00:22:16,750 It does fall short, right? 249 00:22:16,750 --> 00:22:22,470 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. 250 00:22:22,470 --> 00:22:31,870 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. 251 00:22:32,410 --> 00:22:39,110 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. 252 00:22:39,290 --> 00:22:44,770 And again, we have some issues with everything not being one to one with our API call implementations. 253 00:22:44,770 --> 00:22:49,470 For example, with those AMSI returns, we're always returning, hey, this isn't malware, this isn't a problem . 254 00:22:49,550 --> 00:22:53,850 So taking some time to look at the code base is super important. 255 00:22:54,370 --> 00:22:59,130 And wine by itself does not provide any sandboxing capabilities. 256 00:22:59,130 --> 00:23:09,190 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. 257 00:23:09,730 --> 00:23:19,310 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. 258 00:23:19,310 --> 00:23:22,890 Such as the name being such as some of the process names being wine. 259 00:23:24,390 --> 00:23:29,730 Additionally, wine for this is executing x86 and 64 bit PE files. 260 00:23:29,730 --> 00:23:37,010 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. 261 00:23:37,150 --> 00:23:38,930 And again, it is an evolving project. 262 00:23:38,930 --> 00:23:39,850 There are bugs. 263 00:23:39,850 --> 00:23:42,770 So there are unknown unknowns that you may run into. 264 00:23:42,770 --> 00:24:01,710 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. 265 00:24:02,590 --> 00:24:09,030 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? 266 00:24:09,030 --> 00:24:16,170 Because Packet Hacking Village is very much structured around actionable talks and being able to take something from them. 267 00:24:16,610 --> 00:24:19,710 Wine can execute trending malware in 2023. 268 00:24:19,710 --> 00:24:20,870 Absolutely a fact. 269 00:24:20,870 --> 00:24:31,590 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. 270 00:24:31,730 --> 00:24:40,370 You can also build custom DLLs to instrument your execution, grab additional artifacts or maybe some neat instrumentation that you're looking to do. 271 00:24:40,570 --> 00:24:47,770 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. 272 00:24:48,410 --> 00:24:51,470 I really want to give a shout out to everybody coming here to watch this. 273 00:24:51,470 --> 00:24:52,290 This means the world to me. 274 00:24:52,290 --> 00:24:53,750 So thank you very much. 275 00:24:53,750 --> 00:24:59,290 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. 276 00:24:59,290 --> 00:25:06,190 The slides and then some walk through examples of leveraging pod man and docker for creating these environments and doing the execution. 277 00:25:06,190 --> 00:25:09,090 They're all on GitHub as of about an hour ago. 278 00:25:09,190 --> 00:25:10,810 So definitely check these out. 279 00:25:10,810 --> 00:25:12,750 Create Git issues if you run into them. 280 00:25:12,850 --> 00:25:15,910 And I'll be around after this talk to chat more. 281 00:25:15,910 --> 00:25:16,790 Thank you all so much. 282 00:25:16,790 --> 00:25:17,930 I really appreciate it. 283 00:25:24,550 --> 00:25:25,690 Thank you, Jared. 284 00:25:25,930 --> 00:25:28,690 I can tell you right now, I can tell you're a good teacher. 285 00:25:28,730 --> 00:25:29,510 I can just tell. 286 00:25:29,510 --> 00:25:30,930 I was watching this whole thing. 287 00:25:31,510 --> 00:25:37,190 Now, if anyone actually have any questions for Jared, you can feel free to use the microphone. 288 00:25:37,650 --> 00:25:38,190 Yeah. 289 00:25:38,190 --> 00:25:41,990 If anyone will have a question for Jared, you can feel free to use the mic. 290 00:25:41,990 --> 00:25:42,550 Feel free. 291 00:25:42,550 --> 00:25:42,750 Yeah. 292 00:25:42,750 --> 00:25:44,030 It should be open. 293 00:25:47,560 --> 00:25:51,620 Hey, thanks for the talk. 294 00:25:51,960 --> 00:25:56,800 Just wondering, in your experience, as you mentioned, it's not a new thing to run it under wine. 295 00:25:56,800 --> 00:26:04,000 Have you seen malware that's either looking for wine to do something benign instead of its true payload? 296 00:26:04,000 --> 00:26:08,520 Or have you seen things that are actually looking to actively burn it down? 297 00:26:11,490 --> 00:26:12,230 Hello. 298 00:26:12,230 --> 00:26:12,550 Okay. 299 00:26:12,550 --> 00:26:13,170 Great question. 300 00:26:13,170 --> 00:26:19,050 So the question was, have I seen any malware samples that are looking for any wine artifacts that then do something different? 301 00:26:19,050 --> 00:26:20,430 I have not. 302 00:26:20,450 --> 00:26:27,490 I think largely, you know, a lot of socks have the ability to throw data to a virus total or equivalent. 303 00:26:27,490 --> 00:26:34,450 But for the situation such as home lab enthusiasts or people just getting started, wine provides a pretty neat opportunity to execute those payloads. 304 00:26:37,370 --> 00:26:43,150 I'm quite lazy and don't like running my own instrumentation or compiling my own stuff. 305 00:26:43,150 --> 00:26:50,170 Would you recommend any like L trace or S trace equivalents built into wine doing the dynamic instrumentation you recommend? 306 00:26:51,570 --> 00:26:53,130 I think I heard you. 307 00:26:53,130 --> 00:26:57,970 I think you said that you're looking for any kind of L trace or S trace equivalents built into wine. 308 00:26:57,970 --> 00:26:58,590 Cool. 309 00:26:58,590 --> 00:27:05,950 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. 310 00:27:06,090 --> 00:27:08,730 Your results may vary on the success that you have there. 311 00:27:08,750 --> 00:27:18,110 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. 312 00:27:18,110 --> 00:27:26,170 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. 313 00:27:26,170 --> 00:27:28,190 So definitely check that out. 314 00:27:31,880 --> 00:27:33,780 Similar vein of question. 315 00:27:33,780 --> 00:27:37,260 How easy is it to like compile the shared libraries? 316 00:27:39,830 --> 00:27:40,730 Hello? 317 00:27:40,730 --> 00:27:41,350 Hello? 318 00:27:41,350 --> 00:27:42,070 Okay. 319 00:27:42,510 --> 00:27:49,870 How easy is it to compile the like shared libraries for wine to like do any kind of analysis on the things you? 320 00:27:49,970 --> 00:27:51,470 I'm sorry, I cannot hear you. 321 00:27:51,470 --> 00:27:53,010 I think I'm backing away. 322 00:27:53,010 --> 00:27:53,690 Okay. 323 00:27:54,470 --> 00:28:03,750 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? 324 00:28:03,750 --> 00:28:04,310 Yeah, great question. 325 00:28:04,310 --> 00:28:06,650 So yes, it absolutely is a Linux shared library. 326 00:28:06,930 --> 00:28:10,450 And then you can get it to execute or return data or whatever you want to do. 327 00:28:10,450 --> 00:28:11,090 Yes. 328 00:28:13,430 --> 00:28:14,910 Hi, thanks for the talk. 329 00:28:15,090 --> 00:28:18,550 So you tried it out on Metasploit and Empire. 330 00:28:18,550 --> 00:28:24,490 These are both pretty well supported malware. 331 00:28:24,510 --> 00:28:29,430 Well, malware or red team tooling project. 332 00:28:29,430 --> 00:28:41,330 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? 333 00:28:43,310 --> 00:28:44,610 Yes, those are great questions. 334 00:28:44,610 --> 00:28:47,890 The question was, tried it out on Metasploit, Empire, Cobalt Strike. 335 00:28:47,890 --> 00:28:52,430 Have you tried it with other samples that you just kind of grab off of VX underground? 336 00:28:52,430 --> 00:28:56,910 So going back to kind of the home lab story here, I pull in daily dumps from MalShare. 337 00:28:56,910 --> 00:29:01,870 Those MalShare samples end up largely being Cobalt Strike and Returpreter samples. 338 00:29:01,870 --> 00:29:04,410 So my big target base is that. 339 00:29:04,410 --> 00:29:14,870 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. 340 00:29:15,710 --> 00:29:17,190 But your results may vary. 341 00:29:17,950 --> 00:29:18,370 All right. 342 00:29:18,370 --> 00:29:18,910 Thank you. 343 00:29:18,910 --> 00:29:19,630 Sounds cool. 344 00:29:19,630 --> 00:29:20,850 I'm going to try it out. 345 00:29:23,420 --> 00:29:24,180 All right. 346 00:29:24,180 --> 00:29:30,280 So you've made a bunch of changes to the Wine source code to do various things. 347 00:29:30,280 --> 00:29:32,840 Have you sent anything back upstream? 348 00:29:32,860 --> 00:29:34,500 And if so, how did that go? 349 00:29:36,140 --> 00:29:37,360 Yes, that's a great question. 350 00:29:37,360 --> 00:29:40,160 So the question was, you've made changes to the Wine source code. 351 00:29:40,160 --> 00:29:41,840 Have you submitted anything back upstream? 352 00:29:41,840 --> 00:29:49,260 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. 353 00:29:49,260 --> 00:29:53,220 So these changes don't improve the overall functionality or support of Wine. 354 00:29:53,900 --> 00:30:01,960 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. 355 00:30:01,960 --> 00:30:04,080 And I would highly encourage you to check that out. 356 00:30:04,200 --> 00:30:10,800 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. 357 00:30:25,540 --> 00:30:27,160 Anyone else? 358 00:30:29,400 --> 00:30:32,400 If I may, then sure, if there's time. 359 00:30:32,400 --> 00:30:39,000 So how easy is it to make changes to Wine in such a way that it behaves like a sandbox? 360 00:30:39,000 --> 00:30:52,400 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. 361 00:30:55,060 --> 00:30:55,760 Test. 362 00:30:55,760 --> 00:30:59,880 So I think the question was, how easy is it to make changes to the underlying Wine source code? 363 00:30:59,880 --> 00:31:00,780 Did I hear you correctly? 364 00:31:02,720 --> 00:31:07,660 Yeah, so either the source code or just setting up... Sure. 365 00:31:07,660 --> 00:31:09,640 Just all of the things. 366 00:31:09,640 --> 00:31:10,280 Sure, sure, sure. 367 00:31:10,280 --> 00:31:10,840 So cool. 368 00:31:10,840 --> 00:31:12,060 So like, let's run through that really quick. 369 00:31:12,060 --> 00:31:18,260 So one of the things in the, like, lab repo thing that I have up here is I'm leveraging Podman over Docker. 370 00:31:18,260 --> 00:31:24,940 And the reason for that is you can actually pause containers when you're executing containers with Podman. 371 00:31:24,940 --> 00:31:36,260 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? 372 00:31:36,260 --> 00:31:39,880 Same example for a packed or encrypted sample or region of memory. 373 00:31:40,220 --> 00:31:49,040 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. 374 00:31:49,500 --> 00:32:02,920 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. 375 00:32:07,200 --> 00:32:08,860 Dan Shroud, everyone. 376 00:32:08,860 --> 00:32:09,700 Have a drink.