[00:00.000 --> 00:06.540] All right, welcome. I hope you're going to have to readjust this. You're a little taller than me. [00:06.840 --> 00:13.400] But we're welcoming up, I can't pronounce his name, but he assures me that that's common. So [00:14.120 --> 00:22.660] you can call him Scooby. That's what he goes by. And Scooby is a senior security architect, [00:22.660 --> 00:29.760] adversary detection team lead, and threat hunting team lead for Belk Canada, one of Canada's [00:29.760 --> 00:36.400] largest carriers. The talk that he's going to give is really cool because Bloodhound started [00:36.400 --> 00:43.400] out as a red teaming tool, right? But we've learned through using the tool that it's really, [00:43.400 --> 00:50.880] really useful for blue teamers to discover the attack paths in your active directory. So [00:50.880 --> 00:55.760] Scooby's going to give us some information on that and how you can use this tool on the blue [00:55.760 --> 01:10.100] side to understand your active directory and, and the attack paths better. Hello everybody. [01:10.100 --> 01:14.340] Welcome to this talk called Bloodhound from Red to Blue. I'm Scooby, you can find me on Twitter [01:14.340 --> 01:21.440] at ScoobyMTL. Um, I was mentioned I'm a senior security architect at Belk Canada. Adversary team [01:21.440 --> 01:28.140] lead detection and uh, threat hunting team lead as well. Um, this talk was first presented at [01:28.140 --> 01:33.400] B-Side Charm a few months ago. Uh, so if there's some parts that I need to skip, I will refer you [01:33.400 --> 01:38.840] to that talk. Uh, I might have to go a bit faster because I've added a few things. Um, at this [01:38.840 --> 01:43.020] point of the con- the talk, you might wonder is this guy mentally challenged or does he have an [01:43.020 --> 01:47.720] accent? Well, according to my doctors, because I'm French Canadian, that I speak like this. [01:47.720 --> 01:52.220] Uh, Canadian, we're usually nice people until Aki comes along. Then if you're not on our team, [01:52.220 --> 01:56.780] well, you best STFU. Um, because I'm French Canadian, you will probably notice I won't [01:56.780 --> 02:02.620] pronounce S's at the end of words, uh, or H's, or I might have them where they don't belong, [02:02.620 --> 02:07.580] but, uh, don't worry, just bear with me. With this talk, I have a few, uh, unlock [02:07.580 --> 02:12.140] achievements. First of all, uh, I'm giving a talk at DEF CON. Secondly, I'm giving a talk with [02:12.260 --> 02:18.020] a Mohawk. Um, as I mentioned, this is my second talk here at Hacker Summer Camp, so that makes [02:18.020 --> 02:23.840] me, uh, equal with, uh, Pyrotech. He gave also two talks. That's one more talk than Sub-T and [02:23.840 --> 02:28.380] that's two more talk than Matt Graber. Uh, Matt mentioned that I had to talk about quality [02:28.380 --> 02:34.940] over quantity. I don't know what he meant. Um, no security researcher, uh, ego was harmed in [02:34.940 --> 02:40.440] the making of this slide, so rest assured. So here's the agenda for today. We're going to talk [02:40.440 --> 02:45.400] about what Blowdown is, the basic usage of Blowdown, we're going to do an introduction to [02:45.400 --> 02:50.280] the Cypher language, and then we're going to set and des- to destroy PATS. And then I'm going [02:50.280 --> 02:55.680] to talk about report and automation. Uh, by show of hands, who here have used Blowdown [02:55.680 --> 03:06.140] before? Okay, and who have built their own Cypher queries? Uh, okay, awesome. Defenders [03:06.140 --> 03:11.440] thinking list, attackers thinking graphs, as long as this is true, attacker wins. You [03:11.440 --> 03:17.240] probably all heard this before, it's a very, uh, common saying from John Lambert and it comes [03:17.240 --> 03:23.600] with a whole blog. Um, what, what it really means is when an adversary, uh, land in your [03:23.600 --> 03:28.500] networks, it doesn't land in a list that you have, it lands in a graph which is a complex [03:28.500 --> 03:33.500] set of relationship between objects. Blowdown is one of the tools that will actually show you [03:33.500 --> 03:39.380] the relationship between those objects, um, and are they are actually linked together. So [03:39.380 --> 03:43.340] when we talk about a list, this is what we think, talk about, we think about a list of [03:43.340 --> 03:49.880] assets, a list of server names, a list of group, uh, a list of serial numbers. Then we go [03:49.880 --> 03:54.460] deeper and we have even more lists, a list of open port, a list of uninstalled software, [03:54.460 --> 04:00.100] compliancy box, but what all those lists won't tell you that a graph will is how are those [04:00.100 --> 04:06.000] things actually connected together. What is the relationship that exists that you know of [04:06.000 --> 04:11.660] and especially that you do not know of between all of those objects and all of your assets. So [04:11.660 --> 04:17.860] for those who are not familiar with graph, uh, it's not a security concept per se, um, so [04:17.860 --> 04:24.000] here's an example in real life. So you and Alexis are going to a restaurant, comes along [04:24.000 --> 04:28.760] Taylor and Jordan and you become infatuated with Jordan. So you're gonna leverage [04:28.760 --> 04:32.120] relationship in order to get what you want. So first of all, you're gonna leverage your [04:32.120 --> 04:38.780] family relation, relationship with Alexis, who is a co-worker of Taylor, who is a friend of [04:38.780 --> 04:44.020] Jordan and then you'll get Jordan's phone number. By the icon I choose for the phone, you [04:44.020 --> 04:49.140] might guess roughly how old I am. Um, so you can see here, uh, I've made a big effort to [04:49.140 --> 04:54.100] stay, uh, gender neutral in my names and my relation, I'm really proud of that. Um, in [04:54.100 --> 04:58.880] active directory it will look a little bit more like this. So an attacker will land somewhere [04:58.880 --> 05:04.340] in the network by compromising an account via phishing or password spraying because my [05:04.340 --> 05:11.340] password is always summer 2019 and there he is. And then he's gonna leverage, um, uh, the [05:11.340 --> 05:17.180] fact that this, uh, user is admin to his workstation. A bad InfoSec practice, but it does [05:17.180 --> 05:23.240] happen way more than we want. And then that machine can RDP to a terminal server, for [05:23.240 --> 05:28.520] example, in your environment and depending how much, uh, employee you have, this might be [05:28.520 --> 05:35.240] between 1,000 or 100 to 1,000 people. Then on that machine, there's a user who has a [05:35.240 --> 05:40.200] session and he has a little crown because he's a member of a high value group. I see people [05:40.200 --> 05:44.660] with phones, um, last slide of the deck will contain the link where you can download the whole [05:44.660 --> 05:50.860] slide so you don't need to take pictures of every slides. Now let's go over an overview of [05:50.860 --> 05:55.980] Bloodhound. I'll try to go quickly as more than half of the people, uh, seems to have used the [05:55.980 --> 06:00.540] tool before. But first of all, what is Bloodhound? Rest assured there's lots of word, but [06:00.540 --> 06:05.080] it's the only slide with so many words. So Bloodhound uses graph theory to reveal the hidden [06:05.080 --> 06:10.800] and often unintended relationship within an active directory environment. Both attackers and [06:10.800 --> 06:16.740] defenders can use those paths. Uh, red teamer to exploit them and of course, blue teamer to [06:16.740 --> 06:21.840] destroy them before they are being exploited. Here's a very quick history of Bloodhound. It [06:21.840 --> 06:28.240] was, it was released at Bloodhound 24 in a talk called Six Degrees of, uh, Domain Admin. If [06:28.240 --> 06:32.700] you go to that link, you'll see Rowan actually unlocking his password manager and making the [06:32.700 --> 06:38.560] repo live. I was personally, um, introduced to Bloodhound a year after that at Black Hat 2007 [06:38.560 --> 06:44.720] in a talk called Industrial Revolution of Lateral Movement from Tal Mahar and Tal Barry. And [06:44.720 --> 06:49.760] it's an excellent talk where they explain how they can use a path generated by Bloodhound and, [06:49.760 --> 06:55.900] um, uh, through PowerShell, they just exploit and get the credential automatically. And then [06:55.900 --> 07:01.880] last year at Bloodhound, uh, at Black Hat, sorry, 2018, the team released Bloodhound 2.0 and [07:01.880 --> 07:06.020] Bloodhound is developed by Waldo, Captain Jesus, and Armjoy, three people I'm sure you're [07:06.020 --> 07:11.740] familiar with. So what does Bloodhound do exactly? Well, there's three simple things. It [07:11.740 --> 07:17.060] queries Active Directory, it imports the data in the Neo4j database, and then it shows the [07:17.060 --> 07:23.300] relationship between the objects. So why should you use Bloodhound? Well, for red teamers, you [07:23.300 --> 07:28.480] can use the UI to bu- to build complex attack path offline and this reduce the noise on the [07:28.480 --> 07:33.160] network a lot. So every time you jump on a machine, you already know which credentials you [07:33.160 --> 07:38.440] need to steal and which attack path you need to follow to get to the next, you don't need to [07:38.440 --> 07:43.580] re-scan the network every time you land in a new machine. For blue teamer, we can use query to [07:43.580 --> 07:49.800] find the busiest attack path. Um, we can test the relationship of deleting or removing, uh, [07:49.800 --> 07:54.700] relationship or remediating would be the right term, um, on your graph. And then you can [07:54.700 --> 08:01.500] destroy the path before they are being exploited. So it's now time to talk about the basic, or [08:01.500 --> 08:07.500] what I like to call the first steps. So first of all, you need an ingester. There's three [08:07.500 --> 08:12.260] ingesters, there's SharpHound, which is a C-sharp tool, there's InvokeBloodhound, which [08:12.260 --> 08:17.320] is a PowerShell that loads, uh, SharpHound reflectively, and then there's BloodhoundPython [08:17.320 --> 08:22.600] that was built by, uh, Dirkjen from Foxit. So if you land in a Linux machine, you can still [08:22.600 --> 08:27.640] leverage the goodness of Bloodhound. Uh, on the right, I've put some comment. I'm gonna go [08:27.640 --> 08:32.780] very quickly through them. Uh, just want to mention that, uh, collection method all does not [08:32.780 --> 08:38.860] include logged on anymore, because starting in Windows 10, 10th anniversary, uh, and, um, [08:38.860 --> 08:44.300] Windows Server 2016, you need to be local admin in order to list the session. So now you need [08:44.300 --> 08:49.200] to add that if you want to have everything. DC only is something that is, um, less quiet, [08:49.200 --> 08:53.300] makes a lot less noise on the network, but you, as a defender, you should still run that in [08:53.300 --> 08:58.580] order to make sure that you can detect it. Uh, max loop time goes with session loop. By [08:59.020 --> 09:04.700] default, uh, Bloodhound will loop for session for 2 hours. Um, as we're defender, we don't [09:04.700 --> 09:09.460] really care about being detected, so we should run that as long as possible. Uh, the reason [09:09.460 --> 09:13.860] being that if you run it during the day, you'll get all your user session, whereas if you run [09:13.860 --> 09:18.500] it at night, you might get some administrative tasks that are happening only at night. Um, and [09:18.500 --> 09:21.980] you should also shift the days that you're running it because some activities might happen [09:21.980 --> 09:28.100] only a day a week. Um, search forest, uh, yeah, whatever, if you have more than one forest, [09:28.100 --> 09:34.720] sharpound-h for help, uh, could be useful. Uh, this is a screenshot of the GUI, but there's [09:34.720 --> 09:39.240] nothing like a live demo, so let's jump into the UI. This is the screen that you're gonna see [09:39.240 --> 09:45.280] when you get here. Um, because I'm a bit short on time, I'm gonna make it, okay, as quick as [09:45.280 --> 09:54.640] possible. I'm just gonna turn like this. Um, so the thing I wanted to show you guys is, um, [09:54.640 --> 09:59.860] gonna skip a few things, but query, most people when they land here, they will use the, uh, [09:59.860 --> 10:05.940] fine administrative, fine shortest path to domain admin, um, and the domain, so I'm gonna let [10:05.940 --> 10:11.440] the little doggy do, the doggy do his thing while I just show you here the filtering option. So [10:11.440 --> 10:16.040] these are all the edges that you have available for you. Um, this is not the latest version, [10:16.040 --> 10:20.220] they're quite, there's a few more now, but it was working for the presentation and I didn't [10:20.220 --> 10:25.380] dare to try the new version. Um, so you can remove any of those edge and re, recreate the graph [10:25.380 --> 10:32.140] and it's just gonna be gone. Um, so from here, what I wanted to show, but now I, I can't really [10:32.140 --> 10:39.880] not read, but if you don't know how to, um, yeah, anyway, I cannot see the, the thing, but you [10:39.880 --> 10:46.900] can right click on any edge and get help, um, and information about how you can abuse that type [10:46.900 --> 10:51.140] of relationship. So this is really useful and it's not really well documented. Uh, you have [10:51.140 --> 10:56.400] some, uh, OPSEC, uh, consideration and of course, uh, lots of reference as well for any type [10:56.400 --> 11:06.060] of link. Um, another interesting thing is that if you right click on any of the nodes, you have [11:06.060 --> 11:10.200] a few little menu here and you have edit nodes. So if you go there, you can see all the property [11:10.200 --> 11:17.200] of that node and you can also add properties using the little add button right here. Um, there's a [11:17.200 --> 11:22.920] few undocumented shortcut as well that I want to, um, point out today. So first of all, there's [11:22.920 --> 11:28.760] the space bar that will bring you spotlight. Here you'll have all the elements of your, uh, graph. [11:28.760 --> 11:34.620] So you can click on anything and it's gonna, uh, zoom in on your element and put it in the, um, [11:34.620 --> 11:40.500] directory here. So here you have, uh, if you, if you wanna, if you have a, a user that is called [11:40.500 --> 11:45.720] Matt, you can click on him and if you wanna know if he has a path to domain admin, you just use a [11:45.720 --> 11:52.360] little road here and you type domain admin. And just like Google Map, it will show you if the [11:52.360 --> 11:59.040] user has a path to domain admin. So here's the path for that user. Um, beside that, a few other [11:59.040 --> 12:05.640] maybe keywords, uh, you can use shift command and I to bring a console. So if there's any error [12:05.640 --> 12:13.600] message, uh, that you want to read, they will be here. Um, lastly here in the settings, there's [12:13.600 --> 12:19.040] two, uh, uh, yeah, two interesting thing. First of all, the debug query mode that goes with the [12:19.040 --> 12:24.440] raw query here. So when you activate that, every time you click somewhere, you will actually have, [12:24.440 --> 12:28.660] um, the query in Cypher at the bottom in the raw query bar. And this is really helpful if you [12:28.660 --> 12:35.560] wanna learn Cypher. And, uh, last but not least, there is the dark mode, which is probably the [12:35.560 --> 12:41.520] most important part of Bloodhound. So let's get back to the presentation. And by the way, every [12:41.520 --> 12:48.180] time I say, uh, dark team in this presentation, there's a fairy that is born. So here it is. Uh, [12:48.180 --> 12:52.600] why fairies? Because I have two daughters and they love fairies. Um, here are the [12:52.600 --> 12:58.000] undocumented feature that I talked about. So using, uh, the right click on an edge to show [12:58.000 --> 13:03.220] contextual help. Using control to toggle on or off the labels. Control shift I for the console [13:03.220 --> 13:09.620] space bar. And you can also search for GPO or OU, uh, right in the bar and also domain. So if you [13:09.620 --> 13:15.440] wanna know what's, have been enumerated, you can use those keywords. So graph database, as I [13:15.440 --> 13:21.200] mentioned, you, you load, uh, the data in Neo4j. Uh, this is where you can download the [13:21.200 --> 13:25.440] community edition, which is free. And then you start it like you would start any other Linux [13:25.440 --> 13:33.420] services just by using the start. Um, once it's installed, you can go to a, uh, web console on [13:33.420 --> 13:39.640] port 7474. So some people might ask why use the web console when Bloodhound comes with a UI. [13:39.760 --> 13:44.640] Well, there's a few reason for that, uh, especially when you start writing your own query. If [13:44.640 --> 13:50.760] you make a mistake in your query in the console, um, you'll quickly know that your query is [13:50.760 --> 13:55.640] wrong and it will point you what is wrong in your query. So right here you'll see that equal is [13:55.640 --> 14:01.100] not the right, uh, symbol. You need to put a semi-colon. So when you fix that, you get the [14:01.100 --> 14:06.780] result of your, um, of your query. Also, you can see that if you're not returning a path but [14:06.780 --> 14:11.260] you're returning a property, it will actually list, uh, in a table, which doesn't happen in [14:11.260 --> 14:17.640] the GUI, but we're gonna come back to that. A last reason to use, uh, the web GUI, the web [14:17.640 --> 14:23.440] console, sorry, it's because it also has a dark theme. Hey, another fairy. Uh, let's go [14:23.440 --> 14:30.160] through an introduction of Cypher or what I like, I like to call learning to run. So a basic [14:30.160 --> 14:36.040] Cypher query will have a few objects, a few, a few elements with a, a match statement. Then [14:36.040 --> 14:41.160] you have to declare some objects or variables. So here you can see that we are declaring a [14:41.160 --> 14:46.400] variable U of the type user. And if you want to, uh, access the attributes, you need to put a [14:46.400 --> 14:52.760] dot with the attributes name. Then you'll likely want to find some relation, so that says two [14:52.760 --> 14:56.960] dash and an arrow pointing in the direction that you want, and in brackets, you can put the [14:56.960 --> 15:03.060] relation type. After that, you'll probably want to find paths, so you have shortest path or all [15:03.060 --> 15:08.840] shortest paths from one variable towards another one. And then you have where if you want to [15:08.840 --> 15:13.040] make some filtering. And then you need to, a return function to say exactly what you want to [15:13.040 --> 15:20.520] return. So there's two methods for doing the filtering. There's the explicit methods and [15:20.520 --> 15:24.560] there's the where clause. So I'll show you the difference between the two. Here is with an [15:24.560 --> 15:29.240] explicit function. So you can see that I'm declaring a variable called N and it's type of a [15:29.240 --> 15:34.980] group. And the name must be equal to, uh, domain user at test lab dot local. Then I'm [15:34.980 --> 15:40.420] defining another variable M, which is a group, uh, and this one is domain admin at test lab dot [15:40.420 --> 15:44.720] local. And then I'm looking for a shortest path between those two groups and I don't care how [15:44.720 --> 15:50.380] many ops there is and I want to return the path. With the where clause it will look a little bit [15:50.380 --> 15:56.120] more like this. So we have the match shortest path N towards M group and then we say what we [15:56.120 --> 16:00.660] want for those domain, uh, those variable. So the first one is we want it to start with domain [16:00.660 --> 16:06.020] user, whereas the other one we want it to contain something. There's also end widths that [16:06.020 --> 16:11.280] exist. And then we return the path. Here are the two queries side by side. When you run them, [16:11.280 --> 16:16.980] not surprisingly, you get the exact same result. So why use one instead of the other? First of [16:16.980 --> 16:22.360] all, the time. It is way faster to use explicit when you can versus a where clause. On the other [16:22.360 --> 16:27.560] end, if you're, um, a consultant or if you have multiple domains and you, you use specific, [16:27.560 --> 16:31.120] you'll have to make your query for all the domains that you go to, you'll have to change your, [16:31.120 --> 16:35.820] your query all the time. So depending on the situation, one might be more suited than the [16:35.820 --> 16:40.920] other. Also when you're using the web UI, it will help you improve your query. So when your [16:40.920 --> 16:46.300] query works but is not optimal, you'll get those little, um, exclamation mark and when you [16:46.300 --> 16:52.800] click on them, uh, the UI will tell you how you can actually improve them. So here's the query [16:52.800 --> 16:57.680] that we have improved. So if we put them side by side, you can see that in the first one, we [16:57.680 --> 17:02.680] declared a variable and then we do the shortest path, whereas in the second one, we do the [17:02.680 --> 17:06.680] shortest path and we declare our variable right inside the function, which is now the preferred [17:06.680 --> 17:17.950] way to do it in Cypher. This is pro tip number one of the talk. So using appending explain or [17:17.950 --> 17:22.530] profile in front of your query will help you understand what's actually happening under the [17:22.530 --> 17:27.630] hood. So explain will, will do the execution plan but will not run the statement, whereas the [17:27.630 --> 17:32.410] run, uh, the profile will run the statement and you'll see exactly which operator is taking [17:32.410 --> 17:37.690] more, uh, doing most of the work. So here is how it works. So here's a complex query that [17:37.690 --> 17:43.070] returns pretty much all the object in the graph, um, and you do match. So when you do explain [17:43.070 --> 17:48.190] match, just put explain and, and before, you'll get this. So you know, this is explain. So you [17:48.190 --> 17:54.590] can see here we have, uh, since, uh, 1600 hits estimated. When we run it with profile, we see [17:54.590 --> 18:00.110] that it's actually 16,000. So you can see that, uh, profile is way more precise than the other [18:00.110 --> 18:06.390] one. Here are some, uh, useful query and I'll just put also my GitHub link here. So if you [18:06.390 --> 18:10.890] want to download it, all the custom queries that I did not show you in the UI, they are there. [18:11.590 --> 18:15.530] Um, so domain user, those are the first thing that I like to do when I start an engagement or go [18:15.530 --> 18:20.230] on a new domain. Uh, looking where domain user, our local admins, if they have a shortest path [18:20.230 --> 18:25.090] to high value target, if there are any places that they can RDP to, and then all the other bad [18:25.090 --> 18:29.810] rights that they might have. Then I like to look into Kerberos thing. If you have no idea what [18:29.810 --> 18:35.650] Kerberos thing is, in a nutshell, it's, um, it's an attack where you request a weak password, a [18:35.650 --> 18:40.830] weak cipher of a password in RC4 and then you crack it offline. If you want more information, [18:40.830 --> 18:48.410] ADSecurity.org, the site by Sean McAlf. And then I also brought back the, back the top 10, uh, [18:48.410 --> 18:52.530] that were removed from version 1 to 10 because I believe as a blue teamer, it's a good place to [18:52.530 --> 18:58.530] start exploring your graph. So I just put them back. Here's, uh, an example of some advanced [18:58.530 --> 19:03.810] query that were shared in the Blowdown Cipher Query Slack channel. Uh, I believe those, the [19:03.810 --> 19:09.190] both of them were built by Waldo. Um, just to show you that, uh, you can start doing optional [19:09.190 --> 19:13.590] match, you can start collecting variables, you can add them together, you can unwind, uh, you [19:13.590 --> 19:18.070] can count stuff. And if you look at the second one, you can extract, uh, labels, you can extract [19:18.070 --> 19:24.010] variable, you can filter things, um, you can do, um, average length and lots of mathematical [19:24.010 --> 19:29.950] things also, uh, in there. If you want to learn more about cipher, there's a good cheat sheet [19:29.950 --> 19:35.150] from Neo4j and this is the link. Now that we know a little bit how to build cipher queries, it's [19:35.150 --> 19:44.100] time to destroy paths. So what are we trying to do when we're destroying paths? Well, we're [19:44.100 --> 19:49.900] trying to find the busiest path and then we're trying to find, to test the effect of the [19:49.900 --> 19:54.740] proposed remediation. So when you have the old path, sometimes you, it might seem obvious [19:54.740 --> 19:59.600] that if you remove a link, you'll destroy the path and domain user won't have access, uh, won't [19:59.600 --> 20:05.380] have a path anymore to domain admin, but we'll see that this is not always the case. Um, and [20:05.380 --> 20:09.620] then when we know exactly which path should be removed, then we can inform our domain admins [20:09.620 --> 20:15.000] and have them make the change. Let's try this in a control environment. First of all, we're [20:15.000 --> 20:20.200] gonna create a problem. So I'm gonna merge the domain user and I'm gonna give them admin [20:20.200 --> 20:25.780] rights to the computer 673. When I run that in a console, I get that one relation was [20:25.780 --> 20:30.820] created and I'm very happy. After that, we're gonna test our relationship, so we're gonna ask [20:30.820 --> 20:36.800] for a path between domain user and the computer 673 and we're gonna ask to return the path. Not [20:36.800 --> 20:42.780] surprisingly, our path is there. Now we have two options that we can use. We can filter out [20:42.780 --> 20:48.320] the relationship. This is, this is to be used when there's only one relationship type, uh, in [20:48.320 --> 20:54.100] that path. Or you can delete the relationship if there's more than one relation. I'll show [20:54.100 --> 20:58.500] you how to do both. So first of all, filtering out the relationship. So here's the same [20:58.500 --> 21:03.540] beginning of the query. We're looking for a path between domain user and computer 673 and we [21:03.540 --> 21:09.060] want to filter a relationship where the type of relationship is not admin 2 and we want to [21:09.060 --> 21:14.160] return the path. If we do it with a delete, it will look like this. So pretty much the same [21:14.160 --> 21:20.840] query again, but then we just delete the relation. And then you need to print it, so same [21:20.840 --> 21:25.540] thing, but you return the path. And those are the three queries side by side. When you run [21:25.540 --> 21:32.680] them, again, not surprisingly, you have no data. The thing is, everything I just said was [21:32.680 --> 21:39.100] wrong. So you're like, okay, everything was wrong, so why are we here? Is, are we losing our [21:39.100 --> 21:44.980] time? Um, I'll take you to what happened in my head in the last 36 hours and remember that I've [21:44.980 --> 21:50.120] presented this at B-Side Charm and, uh, this part was not in B-Side Charm. So let's do it [21:50.120 --> 21:54.860] against real data. So we're going to do the same thing, we're going to find, uh, our target, so [21:54.860 --> 21:59.020] we're going to do the shortest path between domain user and domain admin and we're going to [21:59.020 --> 22:04.840] get a path that looks like this. Uh, the top here is execute decom and it's the only execute [22:04.840 --> 22:11.980] decom in the path, so this should be a prime target for a filter out. So here how you would [22:11.980 --> 22:17.260] do that, you would say shortest path between domain admin to domain, uh, between domain user [22:17.260 --> 22:23.600] to domain admin, where the path is not execute decom. And if the fix is right, and if this is [22:23.600 --> 22:28.480] the fix that we want to send to our, uh, sysadmin, we should not have a path to domain admin [22:28.480 --> 22:35.700] anymore. Now we have a problem. We still have a path, but it's much longer. So this is, the [22:35.700 --> 22:41.460] execute decom is not the right thing that we want to execute, we want to exclude. But why [22:41.460 --> 22:47.500] filtering is wrong? I'll show you right here. So this is instead of shortest path to domain [22:47.500 --> 22:52.440] admin, this is all shortest paths to domain admin. So as you can see there's two paths with [22:52.440 --> 22:57.400] the same length that lends to domain admin. This is the first one that we excluded with the [22:57.400 --> 23:03.460] execute decom, but right here there's another execute decom and that link was also removed [23:03.460 --> 23:08.880] from our view. So not only did we still have, um, a path to domain admin when we excluded [23:08.880 --> 23:15.760] execute decom, but we removed every, uh, execute decom everywhere in every path of the graph. So [23:15.760 --> 23:22.440] that's why filtering out is actually a bad idea. Now it's like, okay, but at least I can [23:22.440 --> 23:28.000] delete relationship, right? So here's the same shortest path, but then I print the label and [23:28.000 --> 23:36.320] you can see that in between, uh, computer, uh, sorry, group 4574 and computer 65, uh, 652, [23:36.320 --> 23:41.460] there's our execute decom. So we're going to target that link and we're going to say, we're [23:41.460 --> 23:47.320] going to take the path, uh, I want a path between, sorry, the, and then, yeah, assign it a [23:47.320 --> 23:53.440] variable R and then we're going to delete the relationship. And then this happened. And then I [23:53.440 --> 23:59.520] was like, well, shit, now I've deleted two relationship when I wanted to only delete [23:59.520 --> 24:05.120] execute decom. And I was like, okay, now what do I do? My talk is in 36 hours and none of my [24:05.120 --> 24:12.740] techniques actually work and I'm going to look like, uh, anyway. But, uh, the solution was [24:12.740 --> 24:19.200] quite easy. I googled how to target a single link and the first, uh, result was actually [24:19.200 --> 24:24.840] there. So it's very easy. The same query, but you can see that here I have actually tell it [24:24.840 --> 24:31.380] exactly which relation I wanted to target and I, oops, and, uh, delete only one relationship. [24:31.380 --> 24:35.360] And then I was partying like Dave Vader was not there. Uh, that's pretty much what I looked [24:35.360 --> 24:40.700] like in my room, uh, yesterday. So now we get something that looks like this when you're [24:40.700 --> 24:45.020] using the filter out to this path, which is actually the path that we saw on the top in our [24:45.020 --> 24:52.400] execute decom is right there. So that brings me to this part. So when you do the same query in [24:52.400 --> 24:58.740] the web UI, you get the picture on the left, which has all, you can see all the, um, all the [24:58.740 --> 25:03.860] links. When you do it in Bloodown, you only have one link. So I looked a little bit, I asked, [25:03.860 --> 25:08.840] uh, the guys from Bloodown and the reason is when you do a query to Neo4j, it returns only [25:08.840 --> 25:15.780] one, uh, link, but then the GUI somehow add them back when the query is done. So that's why, uh, [25:15.780 --> 25:20.420] on the Bloodown GUI, they only get the one link that is returned by the query. And it's by [25:21.140 --> 25:28.600] alphabetical order. So let's, let's talk about what, what exactly happened here. So a [25:28.600 --> 25:33.580] graph is like a map. So imagine that you want to find all the routes between Chicago and New [25:33.580 --> 25:38.100] York City, for example. You'll, maybe you'll be shown one or two routes on the map, but [25:38.100 --> 25:43.580] that's by, by not, it's not all the paths that exist by any stretch of the imagination. You can [25:43.580 --> 25:49.240] turn left on the street, right, whatever. So that's exactly what's happening here. Bloodown, [25:49.240 --> 25:52.480] well, Bloodown will only show you one relationship, so you might think that there's only one [25:52.480 --> 25:56.960] when there's many. And it is possible to delete a very specific relationship using this [25:56.960 --> 26:02.740] command, so assigning the name of the relationship that you want to delete before. Now, [26:02.740 --> 26:08.060] let's get back to our regular scheduled programming. This is the pro tip number two of the [26:08.060 --> 26:15.940] talk. Um, by default, there's five groups that are high value in Bloodown. But in your [26:15.940 --> 26:19.800] environment, it's probably not the case. You probably have way more groups that are very [26:19.800 --> 26:24.940] important. So this is a query that will help you find all the group that contains admin and [26:24.940 --> 26:30.340] that their high value, uh, attributes is not set to true. You're going to return those name [26:30.340 --> 26:36.300] and your environment, we have Asia admins, Europe admin, and North America admins. Now, [26:36.300 --> 26:39.700] what we're going to do is that we're going to run the same query, but we're going to set those [26:39.700 --> 26:45.800] group high value property to true. So we go from the five original ones to eight groups that [26:45.800 --> 26:52.160] are high value. Pro tip number three, what about the user inside of those groups? So here's a [26:52.160 --> 26:56.360] query that's going to help you find all the high value groups that you have and all the user [26:56.360 --> 27:00.780] that belongs to those group and then you're going to set the high value property of those user to [27:00.780 --> 27:05.300] true. If you have a good eye, you might have noticed that this relationship is in the other [27:05.300 --> 27:10.880] direction and just is, this is just to show you how flexible Cypher can be. So what it's going [27:10.880 --> 27:14.500] to do, it's going to change something like this where you have domain admins with a diamond [27:14.500 --> 27:22.140] meaning that it's a high value, a group, and, uh, user are not high value to this. Now, [27:22.160 --> 27:29.320] it will also change your shortest, all shortest path to this, from this to this. So you see that [27:29.320 --> 27:35.620] in reality, you have a lot more path than you actually thought at the beginning. Pro tip [27:35.620 --> 27:41.800] number four, I know, I know, it's not Christmas and I keep on giving. So here is, uh, in the, [27:41.800 --> 27:46.500] uh, in the shell, uh, CLI where you can, uh, you can use Cypher shell and I'm going to talk [27:46.500 --> 27:52.360] about that a little bit later. Um, but basically here, we see that the first one is longer to [27:52.360 --> 27:56.700] execute than the second one and the reason is very simple. In the first one, we are returning [27:56.940 --> 28:03.180] a path, where on the second one, we are returning a, uh, attribute. So it's a lot faster to [28:03.180 --> 28:09.600] return attributes if you don't have to, uh, send a path. Uh, pro tip number five, another way [28:09.600 --> 28:15.100] to accelerate your query or make them faster is to remove the relationship variable if you [28:15.100 --> 28:20.200] don't need them. Here the difference seems very small, but bear in mind that my database is very [28:20.200 --> 28:25.940] short. If you want to learn more things about how you can use Bloodown as a defender, you can [28:25.940 --> 28:30.980] watch operationalizing Bloodown attack graph for defenders. There's also SAT processor who did [28:30.980 --> 28:35.680] quite, uh, a lot of research. Uh, you also present another methodology where you actually [28:35.680 --> 28:40.820] whitelist or whi- blacklist the nodes themselves by adding a properties. And then of course, [28:40.820 --> 28:44.380] there's a Bloodown Slack, the Cypher query channel where there's lots of people there, [28:44.380 --> 28:50.180] including myself, that will try to help you with your Cypher query if you have any problems. Now [28:50.180 --> 28:54.180] we're gonna talk about reporting because attackers thinks in graph, management thinks in [28:54.180 --> 29:04.880] metrics, and as long as this is true, ops will suffer. So here's an example of very, very [29:04.880 --> 29:11.480] simple, uh, report that we can have. At the top you can put, uh, say, in January 100 percent of [29:11.480 --> 29:16.620] our user had a path to domain admin. Now in February 7, it's 57, and then in March 12, and [29:16.620 --> 29:21.820] we're trying to get to as low as possible, of course. If this is not visual enough for your [29:21.820 --> 29:27.400] management, you can always use gauges. Those one were built in, uh, Google Doc, for example, [29:27.400 --> 29:31.840] very easily, and if they don't understand this, well, honestly, at this point, I cannot help you [29:31.840 --> 29:40.540] anymore. Here's a query about how, uh, you can find a percentage of user with a dom- uh, path [29:40.540 --> 29:44.660] to domain admin. So what you're doing here is you're looking for a shortest path between [29:44.660 --> 29:51.780] domain user and, um, sorry, shortest path to DA. So here you're looking, yeah, you're looking for a [29:51.780 --> 29:56.200] path from user to domain admin, and then you're going to count the number of user you have in [29:56.200 --> 30:00.840] your path, and then how many user have a path, uh, and then you're going to do some maths [30:00.840 --> 30:05.260] writing the return function. So user that has a path divided by the total of user multiplied by [30:05.260 --> 30:10.640] 100, this will give you your percent, and when you run this, you get 100 percent in this case. [30:10.640 --> 30:13.840] Now when you're done with the low-hanging fruit, you can start looking at things that are a [30:13.840 --> 30:21.020] bit mo- more, a bit more funky, like, do I have any domain admins that have session to non-DC [30:21.020 --> 30:26.520] machines? This is a bad practice. Your domain admin should only log in into the domain [30:26.520 --> 30:33.500] controller. So what we're doing here is that we're looking for, uh, comp- computers that are [30:33.500 --> 30:39.980] not part of the domain controller group, and we assign them a variable called non-DC. Then [30:39.980 --> 30:46.700] we're looking for non-DC that has a session to a user, and the user must be, uh, a member of [30:46.700 --> 30:54.180] domain admin. And then we return the name, the username, and we count the connection. Again, [30:54.180 --> 30:59.380] here, there's something special about this query. We have a double relationship. It's also to [30:59.380 --> 31:04.780] show you how powerful, uh, Cypher can be, and I'm very proud of this. Uh, I, I worked, uh, [31:04.780 --> 31:08.940] really hard on this one. I got another version from Waldo, uh, on the Slack channel, but he [31:08.940 --> 31:15.440] was using SID, and it was not working with SID in the test database. So this will give you [31:15.440 --> 31:19.280] something like this, so you see all of your admins and how many connection they have to [31:19.280 --> 31:25.180] non-DC machine. If these names are too cryptic in your environment, you can do a little [31:25.180 --> 31:30.020] modification right here, and in brackets, you can put all the fields that you actually want [31:30.020 --> 31:35.200] to display, and it's gonna look like this. So here you have the username and also the display [31:35.200 --> 31:41.560] name, so it might be easier for you to find who this account belongs to. So here's another way [31:41.560 --> 31:46.180] of representing the same graph, uh, the same Excel fight. Here's log- log- logarithmic, and [31:46.180 --> 31:51.580] you're aiming for your data to go down, down, down, down, down. Um, it's probably not the [31:51.580 --> 31:56.160] best way to show it, but, uh, at least there's a dark team, and that gives me my third fairy [31:56.160 --> 32:05.180] for the talk. So now let's talk about automation. So as I mentioned earlier, there's a CLI, [32:05.200 --> 32:13.400] um, command, sorry, uh, in the bin directory of Neo4j. So you can go there, you export your [32:13.400 --> 32:18.460] username, you export your password, and then using Cypher shell, you can paste your query [32:18.460 --> 32:24.140] directly there. You just need to, uh, enclose them with single quotes. Um, so another pro tip [32:24.140 --> 32:29.520] would be every time you build a custom query in, um, Cypher, always use double quotes. And [32:29.520 --> 32:34.080] when you go in your, uh, shell, you can use a single quote. Uh, if you do mix and match, it's [32:34.080 --> 32:40.220] gonna be very difficult to automate things. So this query, um, is, we're looking for the [32:40.220 --> 32:45.200] Kerberos table, high value accounts that are Kerberos table, so that's why we have as SPN [32:45.780 --> 32:52.080] attributes to true, and high value group set to true. When you run that, you'll get this in the [32:52.080 --> 32:57.600] shell, but you can also pipe it in a CSV file, and it's gonna look like this. Uh, Q8 is only [32:57.600 --> 33:03.540] because that was my eighth query in the graph. CSV is very easy to open, I mean you can send [33:03.540 --> 33:07.780] that to your manager or your sysadmins, they will be able to open it in their favorite [33:08.680 --> 33:16.800] spreadsheet. Now, alerting. So you, when you have your query, you can start comparing, uh, the [33:16.800 --> 33:22.420] current munch result with the last munch result, and you just send an alert if the number [33:22.420 --> 33:29.500] increase. And I went very fast cause we're already at the conclusion. Here are the key [33:29.500 --> 33:36.960] takeaways for today. Defender can think in graph too, using tool like Bloodown. Cypher is a [33:36.960 --> 33:42.840] very flexible language, and you can do a lot of thing if you put the effort in it. It's also [33:42.840 --> 33:47.880] important to test the real impact of a remediation before you send it to your sysadmin, [33:47.880 --> 33:52.000] otherwise they'll lose faith in Bloodown, they'll lose faith in your process, and they'll [33:52.000 --> 33:58.180] probably lose faith in you. Um, but it's easy to do as I demonstrated. Not all query are [33:58.180 --> 34:05.720] worth automating. What I mean by that is that, yes you can see all the domain, all the user [34:05.720 --> 34:09.480] that are in domain admin, for example, and you probably want to be alerted if there's new [34:10.000 --> 34:14.720] user in that group. But you'll run Bloodown maybe once a quarter, once a month, if you're [34:14.720 --> 34:19.080] lucky maybe once a week. Uh, that's not fast enough to be alerted if there's a new domain [34:19.080 --> 34:25.180] admin. So you're way better off looking for event ID 4728 in your logs to be alerted in [34:25.180 --> 34:31.340] near real time. Finally, I want to give a big thank you to the Blue Team Village for having me [34:31.340 --> 34:37.480] today. I want to thank Pyrotek, Talberry, and Grifter. Um, I'm, I'm here because of these [34:37.480 --> 34:41.800] people and especially Grifter last year, uh, in Toronto said that, uh, if you have something [34:41.800 --> 34:47.360] that you want to share with the community, don't be shy, do it, do CFPs, and, uh, you might [34:47.360 --> 34:52.200] get accepted. And that's what happened to me, so I'm very happy. Um, and you learn a lot [34:52.200 --> 34:57.240] more about what you want to talk about or what you, about your subject when you make a talk [34:57.240 --> 35:01.160] because it's the second talk and as you saw, uh, lots of things have changed since the first [35:01.160 --> 35:06.500] version. Finally, I want to thank Waldo and Captain Jesus, uh, who created the tool and who [35:06.500 --> 35:11.340] are helping everybody in the Slack channel when they have questions. So as promised, here's [35:11.340 --> 35:16.680] the link to the, the, the whole deck. And, uh, the second link is the talk for, uh, the same [35:16.680 --> 35:21.760] talk, but, uh, that I gave at B-Side Charm where I gave a more in-depth tour of, uh, the GUI [35:21.760 --> 35:27.720] and, uh, I go a little bit, well, less fast, let's say, slower. So if you have any questions, I [35:27.720 --> 35:43.630] have a few minutes. So the question is, is there a training or environment you can practice [35:43.630 --> 35:49.510] on? Yes, there is, um, an open database. I don't have the link with me, but if you go to the [35:49.510 --> 35:55.230] Bloodhound Slack, um, or if you, if you send me, uh, a text or something, I will give it to [35:55.230 --> 36:01.570] you. It exists. Uh, the Specter Ops team has built, uh, and put online a database. And you can [36:01.570 --> 36:06.630] also generate your own. There's a DB generator that comes with Bloodhound that you can run and [36:06.630 --> 36:11.330] you just specify how many, uh, you com- user and computer you want and it's going to build [36:11.330 --> 36:22.580] everything. That's what I use for this presentation. So this is all fake data. Yes. So is [36:22.580 --> 36:27.960] iValue a Bloodhound term? Yes, it is. It's an attribute that, uh, that it, uh, that is [36:27.960 --> 36:33.540] collected and that is, uh, you can activate it in the GUI or manually using Cypher. So it's [36:33.540 --> 36:45.510] one of the properties. Well, everything is open source, so you can probably change, uh, the [36:45.890 --> 36:50.050] default iValue group in the code if you want. Uh, but I don't know how to do that, but I'm [36:50.050 --> 37:09.120] pretty sure you can. Any other questions? Yes? So the question was if you run Bloodhound a [37:09.120 --> 37:13.400] multiple time, uh, can you just import data over it or should you kind of clean your [37:13.400 --> 37:18.740] database? Uh, the best way usually is you save your old database and you create, then you, you [37:18.740 --> 37:24.100] save it, then you clear it and you re-import. So you can see, yeah, it's better. Because [37:24.100 --> 37:28.580] otherwise if, if your admins have made changes, they will still be there in your environment [37:28.580 --> 37:33.440] and they will still, when you do your query, it's not going to be a, uh, a real representation [37:34.040 --> 37:52.980] of your environment if you don't clean it. Yes, sir? Is there, uh, the, the question was is [37:52.980 --> 38:00.340] there a reason why I did the deleting the relationship between looking for, for, for the [38:00.340 --> 38:05.400] percentage? Uh, because I believe it's, it's easier to find, to, to break the, the most path [38:05.400 --> 38:10.500] at the beginning, um, but you can do it the other way around also. But if you have something [38:10.500 --> 38:14.420] from domain user that goes to domain admin, that's probably the first thing you want to [38:14.420 --> 38:20.420] remove and that will give you, um, a high win rate or a, a big drop in your percentage. If [38:20.420 --> 38:25.680] you have a path from, from domain user to DA, that means 100 percent of your user have a [38:25.680 --> 38:43.600] path and it's going to be hard to find which one to, if you're not doing the query. Yes, sir? [38:43.600 --> 38:49.940] Okay, uh, is there a difference between the 3 and Jester? The sharp, the sharp, um, uh, the [38:49.940 --> 38:56.020] PowerShell one and then the, uh, Python. So Python should be mostly used if you land in a [38:56.020 --> 39:01.180] Linux environment or if you don't have any credentials. And then you go to the first [39:01.180 --> 39:07.180] machine and you rerun SharPound from there. So SharPound is really the preferred methods to [39:07.180 --> 39:12.200] run it. Uh, you'll see that now since a few months, a lot of antivirus has started [39:12.200 --> 39:18.820] categorizing it as a virus, which is a bit sad, but you can kind of understand maybe why. Um, [39:18.820 --> 39:26.460] so PowerShell is a way to actually load, uh, uh, SharPound reflectively. So if you have [39:26.460 --> 39:31.920] application whitelisting, for example, you might be able to run a script or, yeah. But the [39:31.920 --> 39:36.920] preferred methods, especially for a blue teamer, would be to allow SharPound to be executed in [39:36.920 --> 39:43.540] one machine, in one directory, and then you, you do it this way. As a, as a red teamer, I'll [39:43.540 --> 39:47.780] let other people answer, but as a blue teamer, you should just whitelist in for a very [39:47.780 --> 40:06.330] specific place. Any other questions? Yes? Okay, so the question was, is there any tools in [40:06.330 --> 40:12.470] Neo4j to, uh, see the difference between different graph? I don't know of any, but, uh, my [40:12.470 --> 40:16.330] friend is sitting right there. Give me a good idea and I'm gonna work on that, uh, for next [40:16.330 --> 40:28.680] year. The question was, did I test it in any Azure environment or any other cloud? No, I did [40:28.680 --> 40:37.940] not. Any other questions? Thank you very much, everybody.