We'll come to another video of our offensive cyber operations.
Listen, we've been talking about Python before and starting from this lesson, we will try to build
our own backdoor in Python.
But first, we need to know how python socket works.
Let's get started.
A socket in general is one in point of a two way communication link, typically between client and server,
where we can just say two devices in a network in order for us to build a socket, we need to be able
to connect, send, receive and close the connection.
In this lesson, we are going to talk about two types of sockets, TCP and UDP socket.
Let's start with building UDP sockets first.
To build a UDP socket, we start by creating a variable that will hold the socket object, then the
syntax for the socket, as you can see in the slide socket, that socket, then open parenthesis, then
we have two arguments inside the socket.
First one.
Is soccer dad, if underscore inet, which is used for IPV for the second one, is the protocol we're
using and in this case we're using UDP.
So we type socketed that Sorkh underscore the ground.
A node is the acronym is UDP.
Now that's where we build a socket.
Let's look at how we listen on a port at the server side.
We listen to a report using the brain function, so the name of the baby.
We created the blind then inside to print these, we pass two arguments, the IP you want to listen
on and a court notice that the IP is a string.
So it has to be inside double quotes.
After that, we started receiving packets from the sender.
We do that using the socket that's received from and above her or how much bias you want to receive
every time in this case we used one thousand twenty four bytes.
We can also save what we receive in a variable so we can use it later.
Let's see that in action.
Let's import our Soviet module first, using the word import, followed by the name of the module,
which is socket.
Then we build the socket.
Now we bind on an IP import.
But this time we will use 0.01 zero, that zero to listen on all interfaces so we can receive traffic
from other devices in our network.
Let's receive some data now, but we need to save them in a variable called data and then print it.
Now let's run this server and connect to it from another terminal using Ngarkat.
As you noticed, when we print our data available, we get the message that was received along with
the IP and Port of the Sender.
Now, how do we separate the data from the sender information like IP and Port, since we know it's
a couple of elements of two elements, we can assign each one to a different variable on the same line.
If we add a comma and the name of another variable, then we can store IP and port information of the
sender into that variable.
Let's call it can see in an.
And since we know that this information is stored as a list and the IP of the sender is the first element,
then it should be element number zero and the port is element number one.
Let's ride in.
Nice, but we have a problem here, the socket only receives one packet and and then it closes.
If we want to keep it running, we need to put it in a while loop.
Let's do that.
Our UDP server looks good now let's build our UDP client, the UDP client is kind of the same, but
we don't need to bind on any port.
We simply send the data using the Senate to function.
Now, let's try again using the UDP client.
We received the message nice, we have reached the end of this lesson, thank you.
And soon the next one.