Welcome back, security enthusiasts.
In this lecture, we will explore the power of target specification options provided by Nmap.
Understanding different target formats and scanning techniques will enable you to effectively scan IP
addresses and host ranges.
So let's dive into the world of Nmap target specification.
First thing we're going to learn is multiple host specification.
The simplest way to specify a target is by directly listing the IP addresses or hosts you want to scan.
You can specify multiple hosts by separating them with spaces.
For example nmap nmap let's code silly.com.
And after that you can also enter the local IP address.
Let me actually look at my local IP address.
Ipconfig here ipconfig.
And here.
13.138.
And so on.
So here this command will scan the IP addresses of coastal domain here and this local IP address here
and here.
We can also have octet range addressing and wildcards.
So to simplify the specifying a range of hosts, you can use octet range.
Addressing it allows you to specify a range of IP addresses by using a hyphen between the starting and
ending addresses.
For instance, to scan host of, for example, this here.
Let's actually delete the domain for now we will use on the localhost of this here.
So to scan the host of this here, 192.168.
13.1 and 192.168..
13.3 here.
And as you can see, we will scan this, right?
So you instead of this, you can use, for example, this IP address here.
So the only this IP address.
And after that, you will enter the 168.1 13.1 here.
And after that ternary operator here.
So minus operator And here you will enter the IP address you want to range from.
So if you want to scan the IP addresses from 1 to 20, you can use this like this here and now.
In this case, octave range intuition also support wild cards.
Keep in mind enabling you to scan from from 0 to 255 with the expression like this here.
And here this is especially useful when you want to scan a subnet with a large number of hosts and you
can also exclude host from the scan here.
Let's actually clear that.
So sometimes you might need to exclude specific hosts from your scan and Nmap provides the exclude option
for this purpose.
It allows you to exclude one or more hosts from the range being scanned.
So here's an example here.
Nmap 192.
.168.1..
1 to 255 here and we will use the exclude here with two minus operator exclude and 192.168.1. for example,
or actually the IP addresses is 13 and not one and 13.
Here.
13 point example.
Let's exclude 13.3.
Right.
And here with this comment, we are excluding the excluding the 13.3 from the range of this host being
scanned.
Alternatively, alternatively, you can create an exclusion list in a file using the exclude exclude
file option to simply list the IP addresses or host you want to exclude in the file, each separated
by a new line.
For example, let's actually create a new file in graphical user interface here.
Create document and my exclude list dot txt here.
And after that you will open that.
So.
Of course we need to use it.
Some notepad here.
Or mousepad, I think.
Here mousepad.
This is a text programming and Linux.
Here.
So now.
But we are going to do is we will write the IP address if we want to exclude here.
And here.
So we will save this.
And after that, what we are going to do is nmap.
Exclude.
File here.
And after that you will enter the file path.
You can also enter the file path using this home here.
Kali.
And.
Exclude List of text.
And after that you will enter the your IP address range you want to scan, in this case from 1 to 255.
I'm sorry.
Would file unrecognized option.
Exclude file here.
Let's actually try it out this year.
And exclude file again error here.
So if you are getting this error, you're probably using the newer versions of this Nmap here.
So in order to fix that, we will use some grep and here.
So however you can achieve a similar result by using a combination of other tools and commands.
And as I said, one approach is to use grep command to filter out the IP addresses or hosts you want
to exclude and then pass the filtered list to Nmap.
So let's actually clear here.
So we will firstly.
As you remember, we will create.
We have created the file exclude list dot txt.
So let's actually read it.
Cat.
Exclude list dot txt.
And here, this is ours.
This is our excluded, this IP address that we want to exclude from our scan.
And we will using the grep command to exclude the IP addresses or hosts from the list you want to scan.
So you can use the v here, let me actually do it again.
Nmap v option to invert the match and select non-matching lines.
So here nmap f here and here we will exclude.
Exclude.
Exclude list dot txt.
And here we have all hosts dot txt and after that we will enter the filtered filtered dot txt here and
we will use sorry.
Here we will use a pseudo again.
If you are getting this kind of errors, probably the sudo will fix it.
No targets were specified and here failed to resolve exclude list like txt and all.
Host dot txt.
Here.
And here we need to create the URL hosts.txt.
In this case.
And in order to do that, we will use the segue here.
F1192 here with the code here.
192.168.8..
13 point g here and we will encode it.
So one from 1 to 255 here, we will use this pipe key here and here we will print print it one by one
print.
Zero here.
And after that we will encode it and we will write it to all posts.
Dot txt here and now.
Let's cut the text to see what's inside.
And as you can see here, this is all the hosts from 1 to 255.
So what we're going to do is we will run this command again, Nmap command and as you can see, we got
the error again.
Our host text warning no targets were specified.
And here so here we have the two files all host txt and exclude list and we have the filter dot txt
here and here.
This is our output.
So here we also have the exclude list at TXT and all hosts.txt.
And here.
Sorry for the confusion here.
Instead of using nmap, we need to use the grep here.
So what we're going to do is we will change the nmap to grep here.
Rep.
And here.
That's it.
And now let's open the filter that takes actually, we can use the we can open the filter text with
cat here.
And as you can see here, we have excluded the IP address from our list and 20 2120.
22 and 23 doesn't exist because it already existed in filters.
So this is this is a filtered list that all the ports that we want to scan.
So we will we have subtracted exclude list from all hosts here.
So let's actually watch the exclude list here.
And as you can see, we don't have the 23 here, 22 here.
And we will also don't have the 112 here.
And as you can see here, we don't also have the 112 here and so on.
So what we're going to do is here and now we will use the Nmap to scan all of this Nmap.
The lowercase e here and uppercase L here, and we will pass the filtered list to Nmap for scanning
and we will enter the filter dot txt and here Nmap is scans that and keep in mind that this method assumes
you have a list of all the IP addresses or hosts you want to scan initially and a separate list of IP
addresses or hosts you want to exclude.
Adjust the comments accordingly to your to suit your specific requirements.
And please keep in mind that the availability of certain features or options in software tools may be
changed since the 2023.
So this is the last version and updated version of this course and it's always a good idea to.
You can also watch the documentation and the visual sources to make this nmap to more usable and keep
keep keep an eye on the updates and we can also use this seed notation for targets.
So Cidr notation and as actually this Cidr here also pronounced as the Cidr.
So this notation provides a compact method for specifying IP addresses and their routing suffixes.
It also allows for more granular subnet masks compared to classful addressing.
And Cidr notation consists of an IP address followed by a forward slash and a network prefix length.
The network prefix length represents the number of network bits and for example, in Cidr notation.
Actually, let me open the grommet here to write marker here.
So here the Cidr notation.
24 After the IP address, this is the this means the subnet mask of 255 255.
255.
Point zero, indicating that the first 24 bits of the IP address are the network portion and the remaining
eight bits are for are for host addresses.
So to scan the 2256 hosts in this range from, for example, 0 to 255, you can use the Cidr notation
after the IP address 24 here.
Right?
So in order to do that, we will.
So some example here so Nmap 192192.168.
13.0.
And we will use the Cidr notation of 24 and 24.
And as you can see here, we will simplify scanning an entire subnet so we can also work with a target
list in Nmap here.
Uh, for example, uh, let's actually use create a new target list here.
So open the create document here and target my target here, dot txt here and here.
We will open with it with a mousepad here.
And now we will enter some IP addresses in this case.
192192.1681.
13.1382 .168.1 13.2.
And so on.
So in this case we will have two addresses for the scan.
And in order to do that, let's actually use the cut targets here.
My targets dot txt and as you can see, we have two targets and in order to scan the all of the IP IP
addresses in this list, we can use the to and also to load the targets from the to load the targets
from the my targets txt file.
You can use the nmap nmap as we did in previous lecture previous example.
Uh, lowercase e uppercase l here and my target dot txt here.
And this feature greatly simplifies scanning multiple hosts and in the target value you can also mix
different target formats for for instance, you can also add here, let's actually open the file here.
So 192.168.
13.22 50 right.
So with this you can also mix different IP addresses and IP ranges in the same file.
Remember here you can add comments to your target list by starting a new line here with this character
here.
This is really dangerous, dangerous IP here, and this allows you to annotate and organize your target
files for better clarity.
And fantastic, you learned the various target specification techniques in Nmap.
And with our new whether you need to scan specific hosts, define IP ranges, utilize Cidr notation
or work with the target list.
Nmap offers a versatile set of options to meet your scanning requirements, and I'm waiting you in next
lecture and here.