WEBVTT

00:00:01.640 --> 00:00:04.280
Now that we have the PowerShell Active Directory module installed,

00:00:04.280 --> 00:00:07.600
we can then start to enumerate domain information such as users,

00:00:07.600 --> 00:00:09.000
computers and assets.

00:00:09.000 --> 00:00:12.860
In this demo, we'll use some manual commands to enumerate this information,

00:00:12.960 --> 00:00:16.460
and then we will create an automated script so we can reuse our code later.

00:00:18.540 --> 00:00:19.080
Perfect.

00:00:19.080 --> 00:00:20.430
We are back to our live environment.

00:00:20.430 --> 00:00:23.370
In here, I already have the PowerShell terminal open,

00:00:23.380 --> 00:00:25.760
and also have the ActiveDirectory module loaded.

00:00:26.240 --> 00:00:28.540
We are ready to start enumerating information.

00:00:28.540 --> 00:00:29.990
Just as a note,

00:00:30.000 --> 00:00:33.760
I'm using here a low‑level user with minimal privileges in the domain.

00:00:34.740 --> 00:00:36.250
So, let's start by the basics.

00:00:36.250 --> 00:00:40.450
All the domain enumeration commands starts with Get‑AD something.

00:00:41.340 --> 00:00:44.280
For example, if I run Get‑ADDomain,

00:00:44.360 --> 00:00:47.360
we get the basic information about our Globomantics domain,

00:00:47.740 --> 00:00:51.040
like the DNS name, the Windows version of this domain,

00:00:51.050 --> 00:00:52.360
and some other information.

00:00:53.440 --> 00:00:55.270
We can actually get a list of all the enumeration

00:00:55.270 --> 00:00:57.910
commands by using the feature Get‑command,

00:00:58.640 --> 00:01:02.040
and then get‑AD, and then star.

00:01:02.040 --> 00:01:06.970
This star means that we want to list all the commands that starts with get‑AD.

00:01:06.970 --> 00:01:10.770
Once I run this, you can note the amount of enumeration commands.

00:01:11.020 --> 00:01:12.040
It is a lot.

00:01:12.040 --> 00:01:14.910
In this course, we will cover the main commands,

00:01:14.920 --> 00:01:18.310
but feel free to explore this list and see if you find any other

00:01:18.310 --> 00:01:20.160
enumeration command that is interesting for you.

00:01:21.340 --> 00:01:23.280
One good tip here is that you can Filter the

00:01:23.280 --> 00:01:25.790
enumeration commands by using a where Filter.

00:01:25.790 --> 00:01:29.010
For example, I will run the exact same command as before,

00:01:29.020 --> 00:01:31.060
but now I will put Where‑Object,

00:01:31.840 --> 00:01:34.060
and then I will add a Filter so the name of the

00:01:34.060 --> 00:01:36.360
command contains the word Policy.

00:01:36.940 --> 00:01:39.550
In this way, we can enumerate policies in the domain.

00:01:41.440 --> 00:01:41.960
Take a look.

00:01:41.970 --> 00:01:44.420
We have here quite a few policy enumeration commands.

00:01:44.680 --> 00:01:47.700
Some of them might require admin privileges to get information,

00:01:47.710 --> 00:01:50.650
but a lot of them can be executed as a normal user.

00:01:51.540 --> 00:01:54.860
For example, let's check the password policy for Globomantics.

00:01:55.740 --> 00:02:00.260
We can do that by using the Get‑ADDefaultDomainPasswordPolicy.

00:02:01.440 --> 00:02:04.760
Once I run this, it will give me all the details of the password policy.

00:02:05.440 --> 00:02:08.860
We can see here that the minimum password length is 7 characters.

00:02:09.740 --> 00:02:12.970
Also, we can see that my LockoutThreshold is 0,

00:02:13.120 --> 00:02:15.260
meaning there is no account lockout in here.

00:02:16.040 --> 00:02:19.150
I can try thousands of passwords, and I will not get locked out.

00:02:19.150 --> 00:02:22.510
In some companies, you might have here a number like 5,

00:02:22.510 --> 00:02:26.750
for example, meaning that I can try up to 4 passwords before locking the account.

00:02:27.440 --> 00:02:31.250
We can also see here that accounts get locked for 30 minutes and the

00:02:31.250 --> 00:02:33.950
failed login attempts are forgotten after 30 minutes.

00:02:34.940 --> 00:02:37.620
This information can be really valuable to perform a password

00:02:37.620 --> 00:02:39.950
brute force attack without locking any accounts.

00:02:41.340 --> 00:02:43.860
Okay, so now, let's take a look at the other commands.

00:02:44.540 --> 00:02:48.920
We can use the Get‑ADComputer to list out the computers in the domain.

00:02:48.920 --> 00:02:50.000
In here,

00:02:50.010 --> 00:02:53.960
I'm using the star as a Filter so we can actually see every single computer.

00:02:55.340 --> 00:02:58.650
Once I run this, I will get a list of all the machines in the domain.

00:02:58.650 --> 00:03:01.180
In here, I have quite a lot of information,

00:03:01.190 --> 00:03:04.420
so I will select only the few that I want to see using the Select‑Object

00:03:04.430 --> 00:03:07.450
command and giving the fields that I'm interested in.

00:03:08.740 --> 00:03:09.630
Once I run this,

00:03:09.640 --> 00:03:12.460
I'll get a list of all the servers and their status on the domain.

00:03:13.640 --> 00:03:16.960
And the cool thing about using PowerShell is that we can easily explore this,

00:03:17.540 --> 00:03:21.970
like we can run the exact same command, but now using the Export‑CSV feature.

00:03:22.020 --> 00:03:25.360
So then, we can save all data results into a CSV file.

00:03:25.360 --> 00:03:29.180
In here, I will save the results on a file called computers.csv.

00:03:29.180 --> 00:03:33.660
Then, let's take a look at the file that was created.

00:03:35.140 --> 00:03:35.740
Perfect.

00:03:35.750 --> 00:03:36.240
See here?

00:03:36.250 --> 00:03:38.860
We have all the computers saved into the CSV file.

00:03:39.640 --> 00:03:42.370
Now, let's use the same Get‑ADComputer command,

00:03:42.380 --> 00:03:44.860
but now to get more information about a specific server.

00:03:45.740 --> 00:03:49.590
I can do that by using the flag Identity and then providing the

00:03:49.590 --> 00:03:51.660
hostname of the machine that I want to enumerate.

00:03:53.040 --> 00:03:56.160
Once I run this, I get all the basic information about the computer.

00:03:56.840 --> 00:03:59.470
But, if I want to enumerate even more information about this,

00:03:59.480 --> 00:04:03.050
I can just add the flag Properties and then star,

00:04:03.740 --> 00:04:08.870
so then we can see everything about this computer. And take a look, we've

00:04:08.870 --> 00:04:11.310
got a massive amount of information about this machine,

00:04:11.350 --> 00:04:14.660
like the OperationSystemVersion and even the ServicePrincipalNames.

00:04:16.040 --> 00:04:19.339
Similar to the Get‑ADComputer, we have to Get‑ADUser.

00:04:19.339 --> 00:04:23.210
This command here can enumerate all the users in our domain.

00:04:23.210 --> 00:04:24.300
In here,

00:04:24.300 --> 00:04:28.460
I'll run this command with a star as a Filter so we can see all the users.

00:04:30.240 --> 00:04:32.360
Take a look, we've got a huge list of users.

00:04:32.840 --> 00:04:34.560
Just to make it easier to view the data,

00:04:34.570 --> 00:04:38.060
I will run the same command, but now selecting only the ColumnsName,

00:04:38.740 --> 00:04:41.050
SameAccountName, and Enabled.

00:04:42.140 --> 00:04:42.690
Perfect.

00:04:42.700 --> 00:04:46.010
Once I run this, I'll get a list of all the users in the domain.

00:04:46.010 --> 00:04:50.150
Here, I have their full name, their username, and if they are enabled or not.

00:04:51.040 --> 00:04:53.080
And as this is important information for me,

00:04:53.090 --> 00:04:57.060
I will save this into a CSV file using the Export‑CSV command.

00:04:59.740 --> 00:05:02.260
Then, let's just open the file and make sure the data is there.

00:05:04.740 --> 00:05:05.240
Perfect.

00:05:05.250 --> 00:05:05.840
It's all there.

00:05:06.060 --> 00:05:08.290
This list can be really useful during the red team

00:05:08.290 --> 00:05:10.360
engagement since with this information,

00:05:10.360 --> 00:05:12.940
we can start to select our next user targets.

00:05:12.940 --> 00:05:14.710
And talking about data,

00:05:14.720 --> 00:05:17.560
let's say you're looking for a specific employee in the company.

00:05:18.340 --> 00:05:20.670
We can find their domain account by running the same

00:05:20.670 --> 00:05:21.890
command as we were using before,

00:05:21.890 --> 00:05:26.330
but now with a Where‑Object option and a Filter where the account

00:05:26.330 --> 00:05:28.260
name contains the name that we're looking for.

00:05:30.140 --> 00:05:34.060
Once I run this, I get here all the users that match with the word Kenny.

00:05:34.840 --> 00:05:37.730
And if I want to get even more information about this Kenny account,

00:05:37.750 --> 00:05:40.080
I can use the same Get‑ADUser command,

00:05:40.080 --> 00:05:45.360
but now with the flag Identity and giving the username I'm looking to enumerate.

00:05:45.360 --> 00:05:49.230
Take a look, we've got here some basic information about Kenny.

00:05:49.490 --> 00:05:51.860
And, if you want to know even more about this user,

00:05:51.870 --> 00:05:53.970
I can simply add the flag Properties,

00:05:54.290 --> 00:05:57.850
and then put star so we can retrieve every single property.

00:06:00.340 --> 00:06:00.740
Perfect.

00:06:00.740 --> 00:06:02.530
We have here tons of information about Kenny.

00:06:03.240 --> 00:06:05.560
We can see here that he's a senior IT analyst,

00:06:05.610 --> 00:06:08.840
his last password set that date, when his account was created,

00:06:08.850 --> 00:06:09.750
and much more.

00:06:11.740 --> 00:06:13.080
Now, let's talk about groups.

00:06:13.360 --> 00:06:16.190
We can enumerate AD groups by using the command

00:06:16.190 --> 00:06:19.760
Get‑ADGroup with the flag Filter equal to star.

00:06:20.940 --> 00:06:22.140
Also, in here,

00:06:22.250 --> 00:06:25.260
I'll format this as a table so it is easier for us to digest the data.

00:06:26.740 --> 00:06:27.120
Perfect.

00:06:27.120 --> 00:06:27.530
Take a look.

00:06:27.530 --> 00:06:29.740
We have here all the groups at Globomantics.

00:06:30.060 --> 00:06:32.950
And if you're in a large domain, this list might be quite large.

00:06:33.540 --> 00:06:34.160
So, for that,

00:06:34.160 --> 00:06:37.650
we can Filter this down to find interesting things for the red team engagement.

00:06:38.540 --> 00:06:39.140
For example,

00:06:39.150 --> 00:06:43.860
we can run the exact same command, but now with a Where‑Object and a

00:06:43.860 --> 00:06:47.460
Filter where the SamAccountName contains the word admin.

00:06:48.640 --> 00:06:51.250
The idea here is finding all the admin groups in the domain.

00:06:52.440 --> 00:06:55.650
Once I run this, I get the list of groups that contains the word admin.

00:06:56.440 --> 00:06:57.250
Interesting, right?

00:06:57.840 --> 00:07:01.130
Now, if I want to find out all the users that are in each group,

00:07:01.140 --> 00:07:06.290
I can use Get‑ADGroupMember and then use the flag Identity to say that I

00:07:06.290 --> 00:07:08.820
want to enumerate users on the Administrators group.

00:07:08.820 --> 00:07:13.820
And as always, I'll format this as a table so we can better see the data.

00:07:13.820 --> 00:07:18.060
Then, take a look, we have here at list of the admins in the company.

00:07:18.840 --> 00:07:21.540
Those are the accounts that you should try to hack into since they might

00:07:21.540 --> 00:07:24.100
give you domain admin privileges in the environment.

00:07:24.100 --> 00:07:26.500
As this data is important for us,

00:07:26.510 --> 00:07:31.150
I will save the contents of this query into a CSV file called admins.csv.

00:07:33.140 --> 00:07:33.640
Perfect.

00:07:33.650 --> 00:07:35.960
So, we saw how to search all the users in the group.

00:07:36.540 --> 00:07:38.390
Now, let's say that I want to do the opposite.

00:07:38.690 --> 00:07:41.660
I want to figure out all the groups that one user belongs to.

00:07:42.640 --> 00:07:47.650
I can do that by using the command Get‑AD PrincipalGroupMembership

00:07:48.140 --> 00:07:51.550
and then using the flag Identity to specify the username that I'm

00:07:51.550 --> 00:07:54.460
interested in, and once I run this,

00:07:54.470 --> 00:07:57.860
I will find out how the groups that Kenny belongs to. And again,

00:07:57.860 --> 00:08:00.160
we can see here that Kenny is an administrator.

00:08:01.940 --> 00:08:05.710
Okay, so I enumerated the domain information, the computers, and the users.

00:08:05.710 --> 00:08:08.750
Let's now explore a few other interesting enumeration commands.

00:08:09.640 --> 00:08:13.460
We can use the command Get‑ADTrust with the star as a Filter to

00:08:13.460 --> 00:08:15.580
get all the domain trusts for Globomantics.

00:08:15.580 --> 00:08:19.870
In my case, this is empty, but in your case, that might be different.

00:08:19.870 --> 00:08:20.780
Also,

00:08:20.790 --> 00:08:24.580
we can use the Get‑ADDomainController to get information about the

00:08:24.590 --> 00:08:26.850
actual domain controller server in the environment.

00:08:27.640 --> 00:08:29.890
And this has tons of interesting information,

00:08:29.900 --> 00:08:32.159
like the version of Windows that this machine runs.

00:08:32.740 --> 00:08:35.220
This can be really interesting because if the disk is

00:08:35.220 --> 00:08:36.789
running an outdated Windows version.

00:08:36.789 --> 00:08:38.650
We can try to exploit some vulnerabilities.

00:08:40.240 --> 00:08:43.000
Another interesting command is the Get‑ADForest,

00:08:43.000 --> 00:08:46.230
which will return to us information about the forest of the domain.

00:08:47.340 --> 00:08:48.660
A lot of interesting stuff, right?

00:08:50.040 --> 00:08:50.450
Now,

00:08:50.450 --> 00:08:53.610
since we are dealing with PowerShell we can automate out this domain

00:08:53.610 --> 00:08:56.160
enumeration so we don't have to type everything manually.

00:08:56.840 --> 00:09:00.130
What we can do is create a script with the main commands that we cover here,

00:09:00.140 --> 00:09:02.140
so we can reuse that later.

00:09:02.140 --> 00:09:06.990
For that, let's open our PowerShell ISE so we can start our script.

00:09:06.990 --> 00:09:11.060
In here, I will add the domain enumeration commands that we just discussed.

00:09:11.840 --> 00:09:15.350
For example, we can start by enumerating information about the domain itself.

00:09:16.240 --> 00:09:18.960
Then, we can list the password policy for the domain.

00:09:20.040 --> 00:09:20.710
After that,

00:09:20.720 --> 00:09:24.590
we can list all the computers in the domain and save that into a file.

00:09:24.590 --> 00:09:26.010
Similar to that,

00:09:26.010 --> 00:09:29.650
we can enumerate all the users and save that into a CSV file too.

00:09:30.740 --> 00:09:31.270
In here,

00:09:31.280 --> 00:09:33.590
I'll also add the line to enumerate all the groups that

00:09:33.590 --> 00:09:36.960
contain the word admin and save the members of the group

00:09:36.970 --> 00:09:38.750
Administrators into a CSV file.

00:09:40.140 --> 00:09:40.650
And last,

00:09:40.660 --> 00:09:43.280
I will add here two commands to get information about the domain

00:09:43.280 --> 00:09:48.840
controller and the forest. Then, all the commands here are exactly the

00:09:48.840 --> 00:09:50.880
same as the one that we discussed during the demo.

00:09:50.980 --> 00:09:53.160
I'm basically just copying and pasting them here.

00:09:54.340 --> 00:09:57.290
Now, just to make things prettier, I will add some messages during the

00:09:57.290 --> 00:10:00.550
execution of the script, so the data is separated into sections.

00:10:02.940 --> 00:10:03.520
Perfect.

00:10:03.520 --> 00:10:07.860
Just a few more messages, and that's it.

00:10:08.060 --> 00:10:09.150
We have our scripts ready.

00:10:09.740 --> 00:10:12.950
Let's just save this into a file, and I will call this

00:10:12.950 --> 00:10:18.030
as domain‑enumeration.ps1. Perfect.

00:10:18.040 --> 00:10:21.910
Now, let's go to our PowerShell terminal and go to the

00:10:21.910 --> 00:10:26.130
folder where my script is located. Then, now let's cross

00:10:26.130 --> 00:10:27.760
our fingers and run the script.

00:10:32.440 --> 00:10:33.120
Amazing.

00:10:33.130 --> 00:10:33.620
It works.

00:10:33.630 --> 00:10:36.990
We have here all the information about the domain and also a few files

00:10:36.990 --> 00:10:41.960
containing the users, computers, and admins of Globomantics. Pretty cool,

00:10:41.960 --> 00:10:45.230
right? In just a few minutes, we're able to create a script that enumerates

00:10:45.230 --> 00:10:47.260
pretty much everything we need from our domain.

00:10:47.740 --> 00:10:51.890
And the best part is, we then out this enumeration using a low privilege user.

00:10:51.890 --> 00:10:54.550
We don't even need to be an admin to enumerate the domain.
