Welcome back.
Time to start coding our back door.
So in this video, we're going to start with the base of our program.
Remember that we must create two different programs, a server and a back door, and it doesn't matter
with which one we start.
So let's in this case, start coding the server first.
We're going to code both of them simultaneously.
So what I'm going to do is I'm going to open the terminal and remember that we have these tools directory
from the first project.
Let us navigate to there.
And instead of the port scanner, we're going to make another subdirectory inside of here and call this
back door.
Then we are going to change the directory to the subdirectory.
And here we are going to code our tools.
So, as I said, let's start with server first to do that with type server that be why we open it using
NENO and here we are going to code our project.
So what's the first thing that we must do?
Well, since these two programs are going to communicate with one another, they must establish a connection
first.
And we know that we can do that with the help of a socket library.
So Socket allows us to initiate an Internet connection between two machines.
So how are we going to do that?
Well, first thing that we must do and that we also did inside of our ports scanner is we must initiate
a socket object and I'm going to call my socket object suck inside of the server that way.
And to initiate it, I will type socket at socket.
So we're doing this with the help of the socket library.
And here in the brackets, we want to specify two different parameters socket that av underscore in
it.
Cuma socket dot socket underscore string.
And I know what you're thinking.
What even are these arguments.
Well this socketed if underscore it tells our program that we're going to make a connection over IP
for address and the socket that stream tells of our program that we're going to use the TCP connection.
So simple as that.
Now the next thing that we want to do is we want to bind the IP address and the port.
This is something that we already did inside of our first project.
So there's nothing really too much to explain right here.
We just type SOC and use the methods that bind open to and close to Brackett's.
And the first parameter is going to be the IP address of our Linux machine in my case, if I go and
check it out.
This is not one, but 12, so we'll go right here and specify one or two that one that one dot 12 as
the first parameter.
And remember, it must be between the quotes.
Then I will specify comma and port that we are going to use.
Well, we can just go with Port five five five five.
Why not?
It doesn't even matter, to be honest.
After we do all of this, we find it the IP address with the port and now the next thing that we must
do is we must start listening for the incoming connections.
Remember, this was the crucial part in the reverse.
Chelse, the target executes the payload, but we must listen for the incoming connections.
And that is exactly what our server program will do.
It will listen for the connections.
And once the target executes a payload, they will connect to our server program.
So to do that, we can first print like this, let us print listening for the incoming connections just
so we know which part of the program we are.
And below that we can type SOC dot listen.
And we are going to specify five in the brackets, meaning that we are going to listen up to five different
connections.
OK, so our program will now be stuck on this part until the connection is established.
Once the target tries to connect back to us, we need to store their connection in a few variables.
In another sense, we need to store their socket object that we are going to use to communicate with
the target.
And we're also going to split that into an IP address.
So what I'm going to do is I'm going to type target IP.
These are going to be two separate variables and they're going to be equal to SOC Dot accept.
And this method is simply just accepting the incoming connection and storing the targets socket object
right here.
And the IP address in the second variable.
Simple as that.
Once we do that and once the connection is accepted, we can print.
That target connected and we can add Frumkin and what we're going to do here is we're going to close
the quote and add a plus sign and then the string of the IP variable.
And once again, remember, the IP variable will store the IP address of the target.
So what we are essentially doing right here is we're printing that.
We got the connection from the target's IP address.
OK, we need to close one more bracket right here.
And what we're going to do at the end is we're just going to enter a function called target communication.
Now, of course, this function doesn't exist and we're going to code it in some future video.
But for now, let's just leave it right here.
We successfully created the socket object binded.
The IP address with the port, will listen for the incoming connections.
And at the end, we accepted the connection from our target system.
We're going to leave it at this for now on our server program.
And let's go to our backorder program.
Now we need to figure out the code for our backdoor to make it connect to our server, the API.
So first thing that we're going to do is, of course, to import.
The socket library then, as in the server program, we need to initiate the socket object and I'm not
going to call it soccer right here, I'm just going to call it S.
And here we're going to specify the same parameters.
Socket dot af underscore it.
Comma, socket dot soc underscore straight.
Well, Rudy explained what these are and the only thing that we need to do right here is we need to
connect to our target machine, but we're not going to use the connect method right here.
What we are going to do is we are going to call the connection function.
And of course, this is a function that doesn't exist.
So one must code it up here.
Let's define it first to define connection.
It will take no parameters between the brackets.
And what we are going to do is we are going to type right here, try, which is the tri statement.
So it will try to connect to our killing machine.
And remember, the connect function requires to open and close brackets the same way that the bind function
does.
And it also takes two parameters, which the first one is the IP address of the machine that we want
to connect to.
So this will be the IP address of this machine once again and the port will be once again the Port five
five five five because we want to connect to that port since our server program will be listening on
that port.
If it manages to connect, we're going to enter our second function, which is going to be called Shell.
And this shell function also doesn't exist.
We're going to code it.
And what will be the purpose of this shell function is executing the comments.
So for now, we're just going to leave it right here and we're going to code it later.
Once we leave the shell function, we can close the socket object.
And in the accept statement, we can call again this connection function.
Now, you might be wondering, why are we doing this?
Well, if I had something like this right here.
So I go and type while true, which is to remember the infinite loop, and I tap all of these commands
once so they can belong to the wild Trouillot.
And right here, I'm going to also add a statement, time to sleep and give me just one second.
I will explain why I'm doing this.
Let me just call the function till the end.
I'll break right here and I will import the time library because we are going to need it since we use
it right here.
So what are we doing right here?
We're calling the connection function.
This connection function starts and infinite while loop, this infinite loop sleeps for 20 seconds and
then it tries to connect to our clinics machine.
If it manages to connect, it will go inside of the shell function where we will execute the comments
on the target system.
If it doesn't manage to connect, it will go into this except statement and it will call the same function
once again.
So what does this tell you?
It will run this function infinitely until it manages to connect.
So this is good because one reason we don't want our target to start the payload and not be able to
connect just because we haven't started the server yet.
We want to be able to connect to the target system whenever we want.
So this function will tell the payload to try to connect to every 20 seconds, every 20 seconds while
their machine is running.
This program will try to connect our Kleenex machine so we can start the server at any point of time.
And after 20 seconds, it will establish a connection to us.
So this is just calling this function over and over again until this line right here works and they
connect to us.
Then we enter a second function, which is the shell function.
OK, this is the base of our Back-Door DCPI, here is how we are going to connect to our server and
in the next video, we're going to see what we are going to do with the contents of the shell function.
And if I save this controller and also the target communication function.
So these are the functions that will receive and execute commands.
Feel free to post any question if you have about the code, if there is something that you do not understand.
And in the next lecture, we are going to continue with the coding of our programs.
So there.