Welcome to your final module.
Before we start working on scripts.
So this last module is a very important one because we have to define what sockets are.
So we're gonna be using sockets to connect to nodes together.
Really that's it.
A more layman's terms what we're doing is we're going to use sockets to connect to an open port an IP
address.
So you're going to see this when we build a port scanner.
You're also going to see this later on in the exploit development portion of the course where we have
to reach out to a specific port an IP address establish a connection and send malicious data.
So what we're going to do here is we're going to just build out a simple socket script and we're going
to connect to an open port with that script and it'll start to make sense.
And then when you see it in the next video when we build out the port scanner make a little bit more
sense and you see it again in the course you're going to say hey I remember that we use sockets for
connecting to ports.
So here's what we're gonna do.
We're going to make a file and call the file s dot pi.
You can call it whatever you want just do not call it socket dot pi if you call it socket that pie you're
going to run into issues because it's going to think it is a socket.
So we need to define a couple of things first.
So we're going to do is we're going to of course shebang of top do our been Python 3 and we're going
to import socket so remember importing is important.
We have to import socket up here at the top.
Now let's define a couple of variables.
So the first variable we're gonna say is host and we're just going to give that our local address here
of 1 2 7 0 0 1.
This is our local host.
And we're going to define port.
And I'm just gonna get mine all sevens.
You can give it whatever you'd like here.
And I'm going to define another variable like this as equals socket dot socket socket.
Dot a f net socket dot SOC underscore string.
Now this looks long and intimidating.
Please do not be intimidated by this.
We are just making our life easier on ourselves.
So we're defining a variable that stores all this into one.
And this is very very common when it comes to sockets.
The syntax here is very common.
So we're saying is hey we want s to equal socket dot socket and this socket a f iiNet socket SOC stream.
So if iiNet just think about that as IP V for we're connecting over an IP V for connection socket that
SOC stream.
You could just think of this as a port.
So I find it IPD for SOC stream.
It's a port.
So let's say we want to make a connection.
We're going to say s dot connect.
Now connect is just another part of the socket module.
So we're going to make a connection here.
So if you think about this we're using all this and then dot connect.
Right.
So we're declaring this.
And then we have these two parameters here a socket a finite socket Sox stream.
So the F iiNet.
We need to say hey let's make this a our host variable and then this one our port variable and we could
in theory just put in 7 7 7 7 and 1 2 7 0 0 1.
But it's just easier to find those in a variable up top and then use them later to connect.
So I'm going to go ahead and save this and then I'm going to open up a new terminal in a new window
here and I'm going to utilize a tool that we have not used before.
And this tool is called net cat and we'll use this later on in the course quite a bit.
So we'll say net cat and I'm just going to say and DLP.
This means I'm going to establish a listening port I'm going to listen on Port seven seven seven seven
for a connection.
So you see here it says hey we're listening on any interface for all sevens you have to worry too much
about this right now where to go into detail on net cat at a later time but all we're doing right now
is we're waiting for anybody to connect to us.
Now here we're sitting at our local host of 1 2 7 0 0 1.
So we need to establish that connection which is what we're going to do with this script.
Now the script does nothing.
It establishes a connection and that is it.
So let's go ahead and take a quick look where it is going to say Python 3 s stop pi do that come over
here and you see that we have established connection made.
And then the connection closed.
We didn't tell it to do anything.
There's nothing here to say hey keep this connection open send over some data do anything at all.
We just said hey make a connection really quick.
And it did.
It made a connection from 1 2 7 0 0 1 to 1 2 7 0 0 1 we connected yourselves but with this script we
had successfully achieved what we wanted to which was to utilise sockets to connect one node to another
node that's it.
So we're gonna build upon this whole thing here in the next lesson we're going to build a port scanner.
It's going to be a bad port scanner but it's still going to be a great lesson.
So let's go ahead and just take a look at that port scanner and I'll catch it in the next video.