Instructor: 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 commands
to the target system that we want to execute
and it will also receive the response
of the target system.
So let us code it up here.
And we are just going to start it
and then we are going to go to the backdoor program.
First thing that we're going to do is we are
going to initiate the function.
So define and then target underscore communication.
As we can see, it takes no parameters
and what we are going to do straight away
inside of this function is we are going to
enter an infinite while true loop.
What we will essentially do here is we are 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 while true 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 command.
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 sign, percent S, and you're going to
see why we are using this percent S in just a second.
So after the percent, S 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 IP 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 command.
We just made it look a little bit prettier
once we're on the program.
So the next thing that we want to do is then
send that command and we are going to use a function
that I'm going to call reliable send.
And this function also doesn't exist.
It will take one parameter,
which will be the command itself.
So we are sending the command to the target.
Now, this reliable send function is something
that we will 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 command
we want to check out what this command was.
For example, let's type if command 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
to this while true 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 to the while true 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 receive.
And this function is also something that we will create
in the next lecture.
For now on, just picture this function right here
as a function that will receive the response
from the target after the target runs our command.
Then we are 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 quit.
If it was, then we exit the program.
If it wasn't, then we store 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 ls or dir,
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 of the target's directory.
Simple as that.
Now that we did this, let's go to our backdoor program,
and code something similar.
Just inside of this backdoor 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 the while true 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 backdoor, we first receive the command.
Then after we receive the command, we check
if that command was quit, the same thing
that we did in our server.
And in the same way, we're going to exit out of the program,
by breaking out of this while true loop.
And the other case we want
to execute the command.
But this is something that I'm going to type
as a comment for now.
So here in the l statement,
we want to execute the command.
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 send 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 start
at the base of our shell and target communication function.
And we are going to continue coding them
in the next lecture.
See you there.