Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,070 --> 00:00:01,730
Welcome back.
2
00:00:02,300 --> 00:00:09,770
We are about to start our first coding project, are you ready to create your own first tool for hacking?
3
00:00:10,160 --> 00:00:14,080
We are going to create our tool using Python three.
4
00:00:14,780 --> 00:00:19,580
And since Python is out of scope for discourse, I won't be explaining Python basics.
5
00:00:19,850 --> 00:00:26,060
However, I will give my best to explain what we are exactly doing inside of our code for anyone that
6
00:00:26,060 --> 00:00:27,320
hasn't programmed before.
7
00:00:27,950 --> 00:00:29,420
Now I know what you're thinking.
8
00:00:29,660 --> 00:00:31,850
Programming is not needed for hacking.
9
00:00:32,510 --> 00:00:33,240
That is true.
10
00:00:33,590 --> 00:00:39,700
However, learning programming will help you understand how different tools work in greater details,
11
00:00:39,920 --> 00:00:45,710
and it will also allow you to create and weaponize your own tools that you can use.
12
00:00:46,750 --> 00:00:52,390
My advice for anyone that is learning ethical hacking and penetration testing is to, at some point
13
00:00:52,390 --> 00:00:58,630
of your journey, learn a programming language, since if you're only using tools that other people
14
00:00:58,630 --> 00:01:01,030
create, you're limited to their tools.
15
00:01:01,990 --> 00:01:07,840
Now, these programming projects you can watch as we go through the course, or you can skip it until
16
00:01:07,840 --> 00:01:10,810
you finish entire course and then get back to them.
17
00:01:11,230 --> 00:01:13,490
It is completely up to you nonetheless.
18
00:01:13,630 --> 00:01:16,350
Let's get straight into creating our first stop.
19
00:01:17,230 --> 00:01:19,030
Here we are in our clinics.
20
00:01:19,660 --> 00:01:21,460
So how are we going to approach this?
21
00:01:21,940 --> 00:01:28,210
Well, for some of you that already have programming experience and already know Python, feel free
22
00:01:28,210 --> 00:01:29,980
to call this program wherever you want.
23
00:01:30,490 --> 00:01:32,560
You can code it on your host machine.
24
00:01:32,590 --> 00:01:35,890
You can code it in your clinics machine, whatever you feel the best.
25
00:01:35,920 --> 00:01:37,900
You can also use any editor you want.
26
00:01:38,200 --> 00:01:42,880
But for you that haven't programmed before and have no idea what I'm talking about, what we are going
27
00:01:42,880 --> 00:01:45,190
to do is we are going to open our terminal.
28
00:01:46,670 --> 00:01:52,510
And inside of our desktop directory, we we're going to create a directory called Tool's.
29
00:01:53,630 --> 00:01:56,410
Now, you will notice we got it right here on the screen.
30
00:01:56,750 --> 00:01:59,870
And if we change the directory to that directory.
31
00:02:00,980 --> 00:02:07,760
Right here, we will create our program and we are going to put our code inside of a nano ed. Now,
32
00:02:07,760 --> 00:02:12,390
we are already familiar as to how we can use nano set to open a file.
33
00:02:12,860 --> 00:02:15,200
We want to type Nano and then the file name.
34
00:02:15,740 --> 00:02:20,280
In our case, we are creating a Python program, so it needs to have extension.
35
00:02:21,710 --> 00:02:26,550
And since we just finished our scanning section, we will be creating a port scanner.
36
00:02:27,380 --> 00:02:32,090
It will not be an advance SportsCenter like map, but we are going to see how we can create the simple
37
00:02:32,090 --> 00:02:35,580
one just to better understand how scanning of ports work.
38
00:02:36,350 --> 00:02:44,300
So let's type now and then port scanner p y and this will automatically open up our file here.
39
00:02:44,420 --> 00:02:46,250
We are going to type in our code.
40
00:02:46,820 --> 00:02:52,340
The reason why we are not using anything else to type in our code is because Neno Ed is really simple
41
00:02:52,340 --> 00:02:53,260
and easy to use.
42
00:02:53,840 --> 00:02:58,940
First thing that we are going to do is we are going to import the libraries that we are going to need
43
00:02:58,940 --> 00:02:59,780
for this project.
44
00:03:00,530 --> 00:03:06,110
The first library is called Socket Library and we import them like this.
45
00:03:06,590 --> 00:03:14,240
This import command just loads this library and we need this library to be able to communicate with
46
00:03:14,240 --> 00:03:17,630
other machines using TCP and UDP protocols.
47
00:03:18,290 --> 00:03:23,500
And another library that we are going to use is called Term Color Library.
48
00:03:24,860 --> 00:03:29,680
And we're only going to need this library in order to print some statements in different colors.
49
00:03:30,050 --> 00:03:34,980
So nothing else besides that, let us create the base of our program.
50
00:03:35,960 --> 00:03:43,040
So the first thing we need to do whenever we are creating some type of a connection over TCP UDP, we
51
00:03:43,040 --> 00:03:45,350
need to initiate a socket object.
52
00:03:45,860 --> 00:03:52,850
And socket objects are also called socket descriptors and they are used for Internet communication to
53
00:03:52,850 --> 00:03:54,730
initiate the socket object in Python.
54
00:03:54,920 --> 00:04:02,090
We can call that object SOC, for example, and to initiate it with type equals and then socket socket.
55
00:04:02,780 --> 00:04:08,360
So what we're basically doing right here is we're calling this library and calling the socket function
56
00:04:08,510 --> 00:04:09,860
from that library.
57
00:04:10,160 --> 00:04:14,060
This will initiate the socket object for us and it will be stored right here.
58
00:04:14,300 --> 00:04:21,860
And all we are left to do since Python is an easy programming language, is we need to connect to our
59
00:04:21,860 --> 00:04:24,050
target and our port.
60
00:04:24,350 --> 00:04:30,290
And for that, we're going to use our socket object and the connect function onto our socket object.
61
00:04:30,950 --> 00:04:37,010
This connect function requires two different parameters that we specify between two open and two closed
62
00:04:37,010 --> 00:04:44,150
brackets, and those parameters are IP address and also port.
63
00:04:45,790 --> 00:04:49,690
But these are something that we have not defined yet.
64
00:04:49,990 --> 00:04:54,730
Our program does not know what an IP address is or what the port is.
65
00:04:55,660 --> 00:05:02,470
So what I'm going to do is I will create the function right here and to initiate the function, I just
66
00:05:02,470 --> 00:05:08,770
typedef and then the function name, this function name will be called Scan Port and it will take two
67
00:05:08,770 --> 00:05:11,670
parameters, which will be these two parameters.
68
00:05:11,680 --> 00:05:12,580
So it's Capitán.
69
00:05:13,550 --> 00:05:19,010
And let's face them right here, these are going to be the two parameters that will function will take
70
00:05:19,430 --> 00:05:24,950
and these two lines of code will belong to our function in order to make them belong.
71
00:05:25,190 --> 00:05:30,440
You just tab once both of these lines and they will belong to this cannot function.
72
00:05:31,540 --> 00:05:37,270
Now that we try to connect, there is logically one thing that we need to do, this connect function
73
00:05:37,270 --> 00:05:42,700
will either succeed so we will manage to connect port or it will not succeed.
74
00:05:42,940 --> 00:05:45,000
We won't be able to connect to that port.
75
00:05:45,700 --> 00:05:49,750
So these are two different options once we manage to connect.
76
00:05:49,780 --> 00:05:51,490
That means that the port is open.
77
00:05:52,150 --> 00:05:55,480
And if we don't manage to connect, that means that the port is closed.
78
00:05:56,380 --> 00:06:02,800
And what we are going to do to figure out whether a certain port is closed or opened, we're going to
79
00:06:02,800 --> 00:06:07,660
use try and accept statement and to specify, try and accept statement.
80
00:06:07,900 --> 00:06:11,800
We can do something like this in the first line of our function.
81
00:06:11,800 --> 00:06:16,990
We type try and then we tap these two lines to belong to the tri statement.
82
00:06:17,800 --> 00:06:22,690
And down here we also add except make sure to add two dots at the end.
83
00:06:23,080 --> 00:06:29,890
And what this means is that inside of our function it will try to initiate the socket object and then
84
00:06:29,890 --> 00:06:35,380
it will try to connect onto a certain port on a certain IP address that will specify later.
85
00:06:35,980 --> 00:06:44,220
If it manages to do that, then we can print something like print the port opened.
86
00:06:45,220 --> 00:06:47,050
We can specify something like this.
87
00:06:47,890 --> 00:06:53,980
If it doesn't manage to connect, then it will proceed to this except statement and then we can print
88
00:06:55,390 --> 00:06:56,610
port closed.
89
00:06:57,610 --> 00:06:58,060
All right.
90
00:06:58,360 --> 00:06:59,570
So simple as that.
91
00:07:00,280 --> 00:07:03,580
Now, there are a few things that are wrong with this function.
92
00:07:04,510 --> 00:07:11,680
First of all, we're just printing port opened, so once we try to connect to port, we will not know
93
00:07:11,680 --> 00:07:18,100
which port is open, which port is closed, since we didn't specify a number to specify exactly which
94
00:07:18,100 --> 00:07:18,860
port is open.
95
00:07:19,030 --> 00:07:29,200
What I'm going to do is type port opened and then plus and then I can specify a string of port.
96
00:07:31,750 --> 00:07:35,230
And remember, port is our parameter for our function.
97
00:07:36,640 --> 00:07:42,130
And what this string function does is it converts the port, which is an integer number, most likely
98
00:07:42,520 --> 00:07:47,220
to be a string, so it can print it out using this print statement.
99
00:07:48,190 --> 00:07:50,830
What I'm going to do also is that space right here.
100
00:07:50,830 --> 00:07:52,420
So we print this more nicely.
101
00:07:52,720 --> 00:07:59,980
And right here I will add the plus sign, which means that we successfully discovered an open port and
102
00:07:59,980 --> 00:08:02,530
down here we're going to do the same thing.
103
00:08:02,560 --> 00:08:11,470
So we're going to print sign, which means port is closed and then we're going to add the plus the string
104
00:08:11,710 --> 00:08:12,340
of port.
105
00:08:14,200 --> 00:08:19,720
Another thing we will do in case we find out in open court is we can close the socket object.
106
00:08:19,960 --> 00:08:23,390
Since we successfully completed an action, we found an open port.
107
00:08:23,410 --> 00:08:25,240
We can close the socket object.
108
00:08:26,160 --> 00:08:30,510
OK, so this is our base function for now, and we're going to leave it like this.
109
00:08:31,820 --> 00:08:37,220
But there are a few more things that we need to specify, first of all, we want to prompt to the user
110
00:08:37,220 --> 00:08:41,560
of this program what IP address or what target they want to scan.
111
00:08:42,380 --> 00:08:48,980
So outside of dysfunction, we can create a variable called target or targets, whatever you like,
112
00:08:49,490 --> 00:08:52,460
and that variable will be equal to input.
113
00:08:52,940 --> 00:08:58,910
And this input function allows the user of the program once they run the program to input any string
114
00:08:58,910 --> 00:08:59,600
that they want.
115
00:09:00,380 --> 00:09:05,580
And here we will specify to them that we need a target.
116
00:09:05,600 --> 00:09:07,700
So enter Target to scan.
117
00:09:09,920 --> 00:09:13,370
Once they enter a target, we can also ask them for Port
118
00:09:16,550 --> 00:09:17,690
Port to scan.
119
00:09:19,130 --> 00:09:21,210
Now, trust me, I know what you're thinking right here.
120
00:09:21,320 --> 00:09:22,790
This is too simple.
121
00:09:23,150 --> 00:09:28,240
We're only scanning one port on a target, so we don't really want to do that.
122
00:09:28,640 --> 00:09:30,610
We want to specify right here ports.
123
00:09:31,850 --> 00:09:43,850
So this will be enter how many ports you want to scan so they can scan 100 ports or a thousand ports
124
00:09:44,150 --> 00:09:46,610
or all sixty five thousand ports if they like.
125
00:09:47,270 --> 00:09:50,150
But how are we going to change that inside of our code?
126
00:09:51,280 --> 00:09:57,100
Well, we're not going to touch this at all, but we are going to do is will create another function
127
00:09:57,220 --> 00:10:02,040
called Schenn, but this just started the same.
128
00:10:02,320 --> 00:10:04,470
This one doesn't have the port inside of the name.
129
00:10:05,410 --> 00:10:08,650
And this can function will take two arguments as well.
130
00:10:08,890 --> 00:10:12,640
And those arguments are going to be the targets and the ports.
131
00:10:14,170 --> 00:10:21,550
And all we are going to do right here is we're going to iterate so for support in range from one to
132
00:10:21,550 --> 00:10:25,570
ports, for each and every port, we're going to call scan port function.
133
00:10:26,020 --> 00:10:30,550
And this can port function, remember, takes two arguments and those two arguments are going to be
134
00:10:30,550 --> 00:10:32,770
targets and port.
135
00:10:33,730 --> 00:10:35,710
And let me explain this a little bit better.
136
00:10:36,220 --> 00:10:44,470
What these two lines do is this will iterate from one to any number that they specified right here inside
137
00:10:44,470 --> 00:10:45,010
of this line.
138
00:10:46,020 --> 00:10:52,290
And then it will call for each and every no, this cannot function, so it will start from one and then
139
00:10:52,290 --> 00:10:53,400
it will scan port No.
140
00:10:53,400 --> 00:10:59,790
One using this function, then it will increase port to be two and then it will call scan port function
141
00:10:59,790 --> 00:11:02,340
once again once the port is equal to two.
142
00:11:02,670 --> 00:11:08,340
And it will do that until it reaches the ports number that the user of the program specified right here.
143
00:11:09,450 --> 00:11:16,680
But what if our user wants to specify multiple targets, what then they, for example, don't want to
144
00:11:16,680 --> 00:11:19,650
scan on the one target they want to scan to target?
145
00:11:20,160 --> 00:11:23,370
That's why what we're going to do is we're going to change.
146
00:11:23,370 --> 00:11:30,810
This can function and this can function will take Target as an input and it will scan the port on target.
147
00:11:31,180 --> 00:11:40,830
But notice, this target is something that we don't really have if we call right here on target and
148
00:11:40,830 --> 00:11:48,810
then ports, we have targets, but we do not have target and we're going to change this target variable
149
00:11:48,810 --> 00:11:52,500
to be enter targets to scan.
150
00:11:53,850 --> 00:11:58,650
And inside of the brackets, we will explain to them, split them by.
151
00:12:01,240 --> 00:12:03,540
So they can specify, for example, to target.
152
00:12:03,600 --> 00:12:08,670
They can specify them like this, they want to send money to that 168, that one that one comma 190
153
00:12:08,680 --> 00:12:09,700
to that 168.
154
00:12:09,700 --> 00:12:11,660
But one dot five, for example.
155
00:12:11,660 --> 00:12:14,520
If they specify it like this, then we have a problem.
156
00:12:15,130 --> 00:12:20,140
We will call this can function on one target, but we need to split this input.
157
00:12:20,350 --> 00:12:25,080
So it's scans, this I.P. address and then after it, it scans this I.P. address.
158
00:12:25,780 --> 00:12:26,920
Let's see how we can do it.
159
00:12:28,000 --> 00:12:35,400
For now down here, but we're going to do is we're going to check if there is karma inside of our target's
160
00:12:35,410 --> 00:12:44,440
variable if and to specify that we open single quote type comma and closing quote, if comma is in target.
161
00:12:45,580 --> 00:12:48,290
This means that they specified multiple targets.
162
00:12:48,520 --> 00:12:56,770
So what we are going to do is we're going to go down a little bit and then print and then open double
163
00:12:56,770 --> 00:12:57,340
quotes.
164
00:12:57,710 --> 00:13:04,480
We can specify this starshine just it looks a little bit better scanning multiple targets.
165
00:13:05,920 --> 00:13:11,710
And let's close the double quotes and then right here, what we can do is, instead of calling this
166
00:13:11,710 --> 00:13:17,110
can function outside of the statement, we're going to call it inside of the if statement.
167
00:13:17,650 --> 00:13:23,920
And what we're going to do is we are going to use a for loop inside of this if statement, so forth,
168
00:13:25,600 --> 00:13:26,920
IP address.
169
00:13:27,160 --> 00:13:29,470
And we are going to call it IP ADR.
170
00:13:30,780 --> 00:13:41,160
In targets that split and this split function simply splits the input that the user specified by any
171
00:13:41,160 --> 00:13:43,710
sign that was specified in between these single quotes.
172
00:13:44,730 --> 00:13:50,640
Now, since the users of this program will specify targets with comma, we also want to split the input
173
00:13:50,970 --> 00:13:52,080
with a comma.
174
00:13:52,800 --> 00:13:58,190
That way we are going to get with two IP addresses that don't have this comma in between them.
175
00:13:59,420 --> 00:14:05,630
And for each I.P. address in this target's variable, we're going to scan IP address
176
00:14:08,840 --> 00:14:15,620
and let us strip it out of any empty spaces and we do that by typing strip open the brackets, single
177
00:14:15,620 --> 00:14:17,510
quote, space, single code.
178
00:14:17,990 --> 00:14:20,780
And the second parameter, we believe to be port.
179
00:14:21,980 --> 00:14:28,700
In any other case, in case they specified only one target, we're going to use a statement and in that
180
00:14:28,700 --> 00:14:33,430
case, we are simply just going to scan targets and then report.
181
00:14:34,110 --> 00:14:39,340
So we're just basing the entire input of this variable inside of this can function.
182
00:14:39,890 --> 00:14:45,730
And that is because they only inputted one IP address because there is no comma inside of this variable.
183
00:14:46,010 --> 00:14:50,490
So let's go through this real fast just to figure out everything a little bit better.
184
00:14:51,320 --> 00:14:53,810
Let's go from the beginning of the program, which is down here.
185
00:14:54,200 --> 00:14:56,360
So we asked the user for the targets.
186
00:14:56,600 --> 00:15:01,670
They can specify either one target to scan or multiple targets to scan, separated by a comma.
187
00:15:02,360 --> 00:15:05,140
Then they specify the ports that they want to scan.
188
00:15:05,150 --> 00:15:08,470
And by specifying ports, I mean the amount of port that they want to scan.
189
00:15:08,600 --> 00:15:13,970
So if they type five hundred right here, our program will scan first five hundred ports.
190
00:15:14,720 --> 00:15:21,170
Once we take these two variables and we take the input from the user, we check whether A is inside
191
00:15:21,170 --> 00:15:22,250
of this target variable.
192
00:15:22,910 --> 00:15:26,240
If it is, that means multiple targets have been specified.
193
00:15:26,780 --> 00:15:33,230
Then we go for each IP address inside of this target's variable and we check out those IP addresses
194
00:15:33,230 --> 00:15:35,120
by splitting the input with comma.
195
00:15:35,660 --> 00:15:42,290
Then we will scan each and every IP address with the specified amount of ports in case the only specified
196
00:15:42,410 --> 00:15:43,250
one IP address.
197
00:15:43,700 --> 00:15:48,260
Then we scan that one IP address with the specified amount of port.
198
00:15:48,680 --> 00:15:55,070
Once we go to the scan function, this will go for port in range one to the amount of port specified
199
00:15:55,580 --> 00:15:59,600
and it will perform this port function for each and every port.
200
00:16:00,230 --> 00:16:04,130
If we manage to connect, we will print port is opened.
201
00:16:04,610 --> 00:16:06,980
If we don't manage to connect, we will print.
202
00:16:07,160 --> 00:16:08,150
Port is closed.
203
00:16:09,380 --> 00:16:16,220
Let's see whether this works, if I control, OK, then enter and control, exit to exit, to run this
204
00:16:16,220 --> 00:16:19,810
program, I can use Python three and then SportsCenter top.
205
00:16:19,910 --> 00:16:22,760
Why it asks us to enter targets.
206
00:16:22,780 --> 00:16:24,530
This can split them by comma.
207
00:16:25,070 --> 00:16:29,090
And what I'm going to do, I'm going to scan my router.
208
00:16:29,240 --> 00:16:35,260
What you can do, you can open and start your anticipatable and I'm going to start it right now as well,
209
00:16:35,690 --> 00:16:37,100
just so we can test later.
210
00:16:37,130 --> 00:16:38,990
The multiple targets can.
211
00:16:39,680 --> 00:16:44,060
And I'm going to type the IP address on my router, which is this one press enter.
212
00:16:44,320 --> 00:16:46,250
Enter how many ports you want to scan.
213
00:16:46,490 --> 00:16:51,160
Let's say I want to scan first one hundred ports and we get our first error.
214
00:16:51,590 --> 00:16:54,820
Now, don't worry, errors occur a lot in programming.
215
00:16:55,400 --> 00:16:56,960
Let's see what the error says.
216
00:16:57,410 --> 00:17:02,960
String object cannot be interpreted as integer and it is inside of this line.
217
00:17:03,770 --> 00:17:04,580
Let's check it out.
218
00:17:04,730 --> 00:17:11,570
Let's go back to our program using Nannerl so nanobots cannot apply and let's see where the error is.
219
00:17:12,530 --> 00:17:13,880
It seems to be right here.
220
00:17:14,960 --> 00:17:21,500
So we are pasting this sports option as an integer, but we are taking an input as a string.
221
00:17:22,100 --> 00:17:28,910
So what we can do is we can wrap this port input inside of the integer function, which will convert
222
00:17:28,910 --> 00:17:30,440
this number into an integer.
223
00:17:31,370 --> 00:17:34,190
Let's try and see whether this fixed the problem.
224
00:17:34,880 --> 00:17:41,270
If I type it once again when I do that one sixty eight to find that one and then port one hundred.
225
00:17:42,500 --> 00:17:50,840
Wow, this finished really fast and we can see it's scanned 100 ports, it managed to find these two
226
00:17:50,870 --> 00:17:54,410
that are open and this one as well.
227
00:17:54,500 --> 00:17:59,140
Let me just find it and this one as well.
228
00:18:00,950 --> 00:18:07,310
Now I know what you're thinking, this is a terrible output, we can barely see which ones are open
229
00:18:07,430 --> 00:18:08,870
and which ones are closed.
230
00:18:09,740 --> 00:18:16,490
So what we can do to fix this, we can go back to our program and in the accept part where we print
231
00:18:16,490 --> 00:18:17,630
that the port is closed.
232
00:18:18,690 --> 00:18:26,040
We are not going to print anything, we are just going to pass this by simply means to nothing and continue
233
00:18:26,040 --> 00:18:29,030
with the execution of the program while we do this.
234
00:18:29,460 --> 00:18:32,040
Well, we don't really care which ports are closed.
235
00:18:32,070 --> 00:18:34,680
We only want to print the ports that are open.
236
00:18:36,350 --> 00:18:46,250
So let's see whether this fixed our program, if I type Python three scanner and I run the same IP address,
237
00:18:46,250 --> 00:18:49,700
which is my router first one hundred ports, there it is.
238
00:18:50,030 --> 00:18:53,720
If we get the whole lot better output, if we only get ports that are open.
239
00:18:55,210 --> 00:19:00,580
Let's test this program on two different targets, so I started my Métis botibol, and what I'm going
240
00:19:00,580 --> 00:19:07,620
to do is log in and check the IP address of Anticipatable, which is 192.
241
00:19:07,630 --> 00:19:09,190
It's 168 at one point five.
242
00:19:09,520 --> 00:19:14,620
And if I run the program once again and type one, I took that one eight.
243
00:19:14,620 --> 00:19:21,130
That one, that one which is my router and then comma 182, that 168, that one, that five press enter
244
00:19:21,760 --> 00:19:25,360
and of ports, let's say we want to scan one hundred ports.
245
00:19:26,600 --> 00:19:33,920
And this will work, but it gives us the wrong output if we don't know which ports belong to which target.
246
00:19:34,850 --> 00:19:39,320
So let's go back to our program and see how we can fix this to fix this.
247
00:19:39,350 --> 00:19:44,750
We're going to add a print statement inside of our scan function right at the beginning.
248
00:19:44,780 --> 00:19:45,860
We are going to print.
249
00:19:47,130 --> 00:19:52,980
First, we are going to start with a new online character and the new line character is back slash and.
250
00:19:54,360 --> 00:19:56,280
Close the single quote plus.
251
00:19:57,640 --> 00:20:06,940
And let's open single quote once again, enter space and then type starting scan for another space and
252
00:20:06,940 --> 00:20:10,870
then single quote, plus the string of the target.
253
00:20:11,350 --> 00:20:14,770
And remember, Target is our argument to our function.
254
00:20:15,010 --> 00:20:19,780
And this target is an actual IP address that was split right here.
255
00:20:22,290 --> 00:20:30,000
Here we paste this IP address inside of this can function and this IP are dot strip is the same thing
256
00:20:30,000 --> 00:20:31,470
as this target right here.
257
00:20:32,130 --> 00:20:40,110
So if I print it like this and close to Brackett's, because we have one bracket open right here, let's
258
00:20:40,110 --> 00:20:41,280
test it out once again.
259
00:20:41,280 --> 00:20:46,200
Control autosave, control x exit and let me run the program once again.
260
00:20:49,020 --> 00:20:49,830
First one hundred.
261
00:20:51,480 --> 00:20:53,400
This is a lot better.
262
00:20:53,730 --> 00:21:01,300
We get which ports are open for my router and we also get which ports are open for me at this point.
263
00:21:01,300 --> 00:21:01,380
The.
264
00:21:02,540 --> 00:21:08,450
Now, with this, our program is basically finished, what you can do to make this better is you can
265
00:21:08,450 --> 00:21:09,940
change the outfit a little bit.
266
00:21:10,100 --> 00:21:16,550
So right here where you print scanning multiple targets, we can use the term color library that we
267
00:21:16,550 --> 00:21:17,120
imported.
268
00:21:17,360 --> 00:21:24,650
And from the term color library, we can take the colored function and dysfunction just changes the
269
00:21:24,800 --> 00:21:28,310
color of our print statement into any color that we want.
270
00:21:28,820 --> 00:21:34,550
So what we need to do is inside of the print statement type term color dot the colored open bracket
271
00:21:34,940 --> 00:21:40,820
type the statement that you want to print, close one bracket type comma and then open single quote.
272
00:21:40,880 --> 00:21:47,000
And let's say we want to print this in green and then I need to close two more brackets, one for the
273
00:21:47,000 --> 00:21:50,190
colored function and one for the print function.
274
00:21:50,750 --> 00:21:52,340
Let's see whether this will work.
275
00:21:52,820 --> 00:22:02,690
Control autosave once again and control to exit by three courts cannot occupy unmatched bracket.
276
00:22:02,940 --> 00:22:04,050
So let's check it out.
277
00:22:04,070 --> 00:22:04,670
Yeah, we do.
278
00:22:04,670 --> 00:22:05,990
Got one bracket more.
279
00:22:06,140 --> 00:22:09,260
Let us go back and remove it.
280
00:22:11,460 --> 00:22:17,340
So we got print bracket closed right here and we got the colored bracket close right here.
281
00:22:17,520 --> 00:22:20,840
So, yeah, this one right here is one, two extra.
282
00:22:21,270 --> 00:22:22,020
Let's delete.
283
00:22:24,570 --> 00:22:35,360
Save it once again, run the program type two targets that you want to scan, in my case, I'm using
284
00:22:35,370 --> 00:22:41,470
Rorter and Anticipatable and I want to scan, let's say this time I want to scan first.
285
00:22:41,610 --> 00:22:42,480
Two hundred parts.
286
00:22:43,840 --> 00:22:46,750
Now, it doesn't seem to print it in green for some reason.
287
00:22:47,560 --> 00:22:52,570
Let's see what the problem is if I go all the way down to our print statement.
288
00:22:54,420 --> 00:23:01,770
Right here, it seems that our colored function only took this as an argument and we wanted to take
289
00:23:01,770 --> 00:23:02,440
this as well.
290
00:23:03,090 --> 00:23:07,200
So what we need to do is we, first of all, need to delete this.
291
00:23:07,560 --> 00:23:13,380
What we need to do is open another bracket right here and close another bracket right here.
292
00:23:14,700 --> 00:23:18,600
Now, this does seem confusing with all of these brackets being open, closed.
293
00:23:18,990 --> 00:23:23,490
But what we just did is we extracted this statement to be one function.
294
00:23:24,000 --> 00:23:28,320
So inside of the colored, we open one bracket for the function itself.
295
00:23:29,040 --> 00:23:33,030
Then we paste two arguments and we split these arguments like this.
296
00:23:33,180 --> 00:23:39,210
And first argument is this print statement, while the second argument is the color that we want to
297
00:23:39,210 --> 00:23:39,810
print it in.
298
00:23:40,620 --> 00:23:42,330
Hopefully right now this will work.
299
00:23:42,720 --> 00:23:45,420
And if I go and run the program once again
300
00:23:49,620 --> 00:23:56,100
and scan the first two hundred words, now it seems to work, it says, scanning multiple targets and
301
00:23:56,100 --> 00:23:57,480
it is printed in green.
302
00:23:58,440 --> 00:24:03,810
As we can see for our anticipatable, we also found two more additional ports because we increased the
303
00:24:03,810 --> 00:24:05,280
number to 200.
304
00:24:06,000 --> 00:24:06,360
Cool.
305
00:24:06,960 --> 00:24:11,820
Now you got your first tool ready to use in your penetration test.
306
00:24:13,080 --> 00:24:18,620
Now, even though this is a simple port scanner, you can do many things to make it a little bit better
307
00:24:19,080 --> 00:24:25,410
if you are an experienced programmer, what you can do, you can try to receive a banner from these
308
00:24:25,410 --> 00:24:31,710
open ports so you can try to send packets and receive packets and store the response inside the variable
309
00:24:31,710 --> 00:24:36,110
and then print it out to see what banner does an open port have.
310
00:24:36,600 --> 00:24:42,270
And then there is just something that an open port might send as an information as to which software
311
00:24:42,270 --> 00:24:44,100
it is running on that open port.
312
00:24:44,400 --> 00:24:49,040
And from that vendor, we can also extract the version of that software.
313
00:24:49,500 --> 00:24:54,420
But we are not going to be doing that right now because that would be a little bit too advanced for
314
00:24:54,420 --> 00:24:55,720
us right now.
315
00:24:55,740 --> 00:24:57,330
We are happy with this program.
316
00:24:58,050 --> 00:25:01,650
In the next few videos, we're going to be covering vulnerability analysis.
317
00:25:01,830 --> 00:25:02,400
See you there.
32892
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.