WEBVTT

00:00:01.340 --> 00:00:04.480
So now that we created the TCP port server,

00:00:04.490 --> 00:00:07.860
we can obviously test that using different approaches.

00:00:07.860 --> 00:00:10.040
The first one obviously was using TCP client,

00:00:10.040 --> 00:00:11.900
which is part of the .NET namespace.

00:00:11.900 --> 00:00:16.070
But what about if we wanted to use just the regular

00:00:16.070 --> 00:00:19.580
PowerShell option called Test‑Connection?

00:00:19.590 --> 00:00:22.880
This one is going to obviously take an IP address or name,

00:00:22.880 --> 00:00:24.200
which we already have.

00:00:24.200 --> 00:00:29.200
And then, it will take a TCP port, which is the port that we already have.

00:00:29.380 --> 00:00:32.590
So I can do this here, and you can see it returns simple.

00:00:32.600 --> 00:00:33.670
It just says true.

00:00:33.670 --> 00:00:35.320
So it works really well.

00:00:35.330 --> 00:00:39.710
It's the simple way of testing if a port actually exists.

00:00:39.710 --> 00:00:43.210
Now of course, if we were testing more than one IP address,

00:00:43.210 --> 00:00:46.540
then we can use the simple approach that we used before.

00:00:46.540 --> 00:00:50.270
So let's say we were doing everything from 1,

00:00:50.270 --> 00:00:51.070
port 1,

00:00:51.070 --> 00:00:55.720
all the way to 1024, we could do the same thing that we've done

00:00:55.730 --> 00:00:58.390
in the past where we can say ForEach‑Object.

00:00:58.390 --> 00:01:02.280
And then we can take that same command that we just utilized,

00:01:02.280 --> 00:01:06.460
the Test‑Connection one, and we can, like we've done in the past,

00:01:06.460 --> 00:01:10.940
when we were pinging things where we can simply just say I

00:01:10.940 --> 00:01:13.740
want to take the TCP port and actually it's going to be the

00:01:13.750 --> 00:01:18.430
_$ value from the loop of port, so I can press Enter here.

00:01:18.640 --> 00:01:21.310
Now this will go ahead and connect to that machine again,

00:01:21.310 --> 00:01:25.680
and it will start to interrogate each of the ports and return a value back,

00:01:25.680 --> 00:01:28.610
which will be false, true, false, true, false,

00:01:28.610 --> 00:01:32.180
true as it goes down the list from 1 to 1024.

00:01:32.180 --> 00:01:33.150
Now, of course,

00:01:33.150 --> 00:01:36.250
we're not going to wait for this to happen because this will take a long time.

00:01:36.250 --> 00:01:38.390
As you can see, it's only done three so far.

00:01:38.400 --> 00:01:41.210
So we'll just terminate this one a little bit here.

00:01:41.270 --> 00:01:42.760
Stop that from executing.

00:01:42.760 --> 00:01:44.010
There we go.

00:01:44.050 --> 00:01:45.990
But it works very well.

00:01:46.000 --> 00:01:48.970
You can iterate through one port to another port.

00:01:48.970 --> 00:01:49.850
Now, of course,

00:01:49.850 --> 00:01:53.230
the other approach here is to use the Nmap tool with

00:01:53.230 --> 00:01:55.530
PowerShell that we used previously.

00:01:55.760 --> 00:01:57.050
This one works very similar.

00:01:57.050 --> 00:02:00.600
I can say nmap, and what we'll do is we'll specify a port.

00:02:00.600 --> 00:02:03.170
I'm going to use port 80, now I know that that doesn't exist,

00:02:03.170 --> 00:02:04.610
and then we'll change it in a second.

00:02:04.610 --> 00:02:07.370
And I'm going to say $ip, do nmap.

00:02:07.370 --> 00:02:11.880
It'll go ahead and say I'm looking for port 80, and it

00:02:11.880 --> 00:02:14.340
just returns back and says it's HTTP.

00:02:14.340 --> 00:02:17.140
But the state of it, remember the state that we had before,

00:02:17.140 --> 00:02:21.440
which was open, closed, or filtered, this one comes back as filtered.

00:02:21.440 --> 00:02:27.020
So let's clear this for a second, and then we'll iterate the same thing again,

00:02:27.020 --> 00:02:32.100
but we'll use 16000 as the port, and we'll do the same thing.

00:02:32.320 --> 00:02:33.420
Now notice this time,

00:02:33.420 --> 00:02:37.650
the state is now set to open because obviously that's

00:02:37.650 --> 00:02:39.820
my echo server that's now running.

00:02:39.820 --> 00:02:44.640
So we can identify specific ports, individual or multiple,

00:02:44.640 --> 00:02:48.650
very simply by using something like Nmap or using PowerShell.

00:02:49.070 --> 00:02:56.220
So let's say we wanted to use a specific port like we had before, so 16000.

00:02:56.230 --> 00:02:59.740
But maybe we want to target the protocol that we want to use.

00:02:59.890 --> 00:03:01.560
So I can say nmap.

00:03:01.630 --> 00:03:04.610
I could do the ‑p again, so there's our syntax.

00:03:04.610 --> 00:03:09.340
But this time, maybe I want to say it's a TCP port I'm looking for.

00:03:09.500 --> 00:03:14.510
And so then it can go ahead and do a scan using TCP instead of UDP,

00:03:14.510 --> 00:03:16.950
which I could replace the T with the U.

00:03:17.210 --> 00:03:20.540
So this allows us to go ahead and identify the ports.

00:03:20.720 --> 00:03:23.820
Our final approach here to doing a port scan would be to

00:03:23.820 --> 00:03:25.810
use some type of third‑party library.

00:03:25.820 --> 00:03:31.190
Now I chose PowerSploit, which is a framework that's available,

00:03:31.190 --> 00:03:32.370
a security framework.

00:03:32.380 --> 00:03:34.840
If you do decide to put this on your machine,

00:03:34.850 --> 00:03:36.730
you'll need to have exclusions for antivirus,

00:03:36.730 --> 00:03:38.840
and the real‑time defender will block it,

00:03:38.840 --> 00:03:39.310
etc.

00:03:39.310 --> 00:03:40.280
So just be aware.

00:03:40.290 --> 00:03:41.760
But I'm going to utilize this.

00:03:41.760 --> 00:03:47.510
First thing I'm going to do is import the module, so I'll say Import‑Module.

00:03:47.830 --> 00:03:50.650
And I've got the PowerSploit module available here.

00:03:50.660 --> 00:03:52.990
And I'm going to say yes, I'd like to run that one.

00:03:53.000 --> 00:03:54.510
So all of those are completed.

00:03:54.630 --> 00:04:00.000
And then, what we have access to is a command called Invoke_Portscan.

00:04:00.000 --> 00:04:01.650
I'm going to press Enter here,

00:04:01.650 --> 00:04:03.840
and it will just come back and give me a message that will say,

00:04:03.850 --> 00:04:05.490
oh, the parameter has not been set.

00:04:05.500 --> 00:04:08.260
You're not able to do anything.

00:04:09.000 --> 00:04:13.870
We can simply say Invoke‑Portscan, and then there's a property called hosts.

00:04:14.070 --> 00:04:15.950
Now we already have the IP address,

00:04:15.950 --> 00:04:22.250
and then there's another one called Ports where we can specify the port as well.

00:04:22.260 --> 00:04:24.200
So I'm going to do this, invoke scan.

00:04:24.200 --> 00:04:26.420
It's going to go ahead and connect to that one,

00:04:26.430 --> 00:04:28.720
which is my IP address, look for that port,

00:04:28.720 --> 00:04:33.050
which is 16000, and then return an alive option if needed.

00:04:33.380 --> 00:04:34.410
So this is great.

00:04:34.420 --> 00:04:38.800
It's a simple PowerShell option available to us as a third party.

00:04:38.990 --> 00:04:41.640
Now of course, we can go a little bit more complex as well.

00:04:41.650 --> 00:04:45.000
So let's say I'm going to create a new variable called ports.

00:04:45.020 --> 00:04:49.850
So I'm going to do 80, 443, 3389,

00:04:49.850 --> 00:04:54.030
and then we'll add our 16000 one in there because we know that's been used.

00:04:54.030 --> 00:04:56.960
And then I can loop back through my commands and just say

00:04:56.960 --> 00:04:59.840
ports instead and then initiate the scan.

00:04:59.840 --> 00:05:00.490
And this time,

00:05:00.490 --> 00:05:04.870
it will go through and check the four ports to determine which ones are open,

00:05:04.870 --> 00:05:05.650
and there we go.

00:05:05.650 --> 00:05:07.480
We've got the returned values.

00:05:07.740 --> 00:05:10.820
We've got open ports, and you'll see 3389.

00:05:10.820 --> 00:05:12.090
Of course, that's Remote Desktop.

00:05:12.090 --> 00:05:17.190
And you'll see port 80 and 443, so HTTP and HTTPS are filtered.

00:05:17.480 --> 00:05:21.030
Not necessarily closed, but the firewall is restricting access to them.

00:05:21.370 --> 00:05:26.330
So just a quick example of using a third‑party one. We also have

00:05:26.330 --> 00:05:30.860
the ability to use multiple IPs as well like so. And then if we

00:05:30.860 --> 00:05:32.480
loop through and change our commands,

00:05:32.490 --> 00:05:36.450
we've got the multiple ports, and now we can use the multiple IPs

00:05:36.570 --> 00:05:41.330
and then run the same port scan against the multiple IP addresses

00:05:41.470 --> 00:05:44.070
and the multiple ports at the same time.

00:05:44.080 --> 00:05:48.550
And you can see we get responses back. So you can see that 129 doesn't exist.

00:05:48.550 --> 00:05:49.430
There's nothing.

00:05:49.580 --> 00:05:53.540
128 is the one that we've already scanned. And 130, which is the

00:05:53.540 --> 00:05:56.070
new one, has none of those ports open as well.

00:05:56.140 --> 00:05:58.570
So some of the third‑party ones are great.

00:05:58.580 --> 00:06:00.860
They kind of bundle up the functionality that you might need.

00:06:00.930 --> 00:06:05.130
So that's just a quick example of how to use multiple types, whether it's

00:06:05.160 --> 00:06:09.940
using PowerShell, whether it's using .NET API, whether it's using Nmap or

00:06:09.950 --> 00:06:13.330
even a third‑party framework for doing port scans.
