Welcome back.
Let's continue with our programs.
So in the previous video, we managed to establish a connection between these two programs or we didn't
really manage to establish, but we created a part of code that will establish the connection once we
run these programs.
Now, let us go to our server program first and let's figure out this target communication function.
Remember, this function will send the comments to the target system that we want to execute, and it
will also receive the response of the target system.
So let us it up here and we're just going to start it and then we are going to go to the pacta program,
first thing that we're going to do is we are going to initiate the function to define and then target
underscore communication.
As we can see, it takes no parameters.
And what we are going to do straightaway inside of this function is we are going to enter an infinite
while loop.
What we will essentially do here is we're going to ask for a command from the user of this program and
then we're going to send that command to the payload and go back to the beginning of this file to loop
once we receive the response.
Let me show you what they mean inside of here.
The first thing that we want to do is we want to initiate a comment since we don't know what command
we want to execute.
We're just going to use an input statement that will allow the user of this program to type in the command.
And we're going to write it like this.
Let's make it pretty.
Let's make it look like a terminal and use this sine percent.
S and you're going to see why we are using this percent as in just a second.
So after three percent as type two dots and then empty space and add a single quote at the end, and
here you can add another percent and string of I.P. address.
And if you don't know Python, you're probably wondering what even happened here.
Well, this is a statement that will print out and once we type this percent s it will get exchanged
with this string of IP address.
And remember, our IP is simply the IP address of the target system that we initiated in this line right
here.
So what this will print is it will print the shell and then after it the IP address of the target machine
and then two dots.
And here we will be able to type in our comment.
We just made it look a little bit prettier once we run the program.
So the next thing that we want to do is then send that comment and we're going to use a function that
I'm going to call a reliable send, and this function also doesn't exist.
It will take one parameter, which will be the command itself.
So we're sending the command to the target.
Now, this reliable function is something the code in the next lecture for now, just picture it as
the function that will send this command to the target system.
Then right here, after we send the comment, we want to check out what this comment was, for example,
this type, if comment equals equals to quit, then this will initiate to our program that we want to
exit out of the shell and we want to exit this program.
So we're just going to break out of this while loop and that will end our program.
So remember, once you type quit, that means you want to stop communicating with the target system
and you want to close this server program.
So we're going to break out the default loop and that will exit out of this target communication function
and then it will exit out of the program.
If it is not quit, so else we're going to type right here, result equals and then reliable underscore
receipt and this function is also something we'll create in the next lecture for now.
And just picture this function right here as a function that will receive the response from the target
after the target runs over comment.
Then we're going to store the response inside of this result variable and we want to print the result,
simple as that.
So let's go through this real quick.
Once again, we're asking for the input of the command.
Then we are sending that command to the target.
We check if the command was quitte.
If it was, then we exit the program.
If it wasn't, then we thought the response of the command that we received using this function to this
result variable and then we print out the result.
For example, if the command was less or dear, that command lists out all of the files and folders
inside of a directory, we would then store this inside of this result variable and then we would print
out all of the files and folders inside the target's directory.
Simple as that.
Now that we did this, let's go to our back door program and code something similar.
Just inside this back door program, we do that using the shell function.
So what I'm going to do is I'm going to go below the connection function and right here I will initiate
this shell function.
And as our target communication function, the shell function will also start with a while loop.
Then what we are going to do is we are going to create the command variable.
And in this program, this command variable will receive the command that our server sent.
So in impacter, we first receive the command.
Then after we receive the command, we check if that command was quite the same thing that we did in
our server and in the same way we are going to exit out of the program by breaking out of this wall
Tulip.
And the other case, we want to execute the comment, but this is something that I'm going to type as
a comment for now.
So here in the statement, we want to execute the comment.
And the reason why I'm not typing it right now is because this execution of command requires another
library.
We're going to touch on as soon as we finish coding these reliable receive functions and reliable functions.
So first, we need to code them and then we're going to go and type the code of the command execution.
So for now, we just started the base of our shell and target communication function and we're going
to continue coating them in the next lecture.
See you there.