Welcome back.
Now that we covered our shell and targeted communication functions, it is time we employed the reliable
and reliable receive functions.
So if I go to my server code right here, you will notice that we did code a part of the targeted communication
function.
But this is not really working.
These functions do not exist.
We must create them first in order to be able to successfully send and receive data.
Let's start with the reliable function first.
Since that one is easier, we just need to send the data.
And for this we're going to use the JSON library in order to more easily pass the data.
So down here, I'm going to define reliable, underscore and reliable and will take one parameter.
As we can see right here, it has to be the data that we are going to send.
So we're just going to name that parameter data.
Then let's add two dots.
And inside of the function, we're going to define something called Jason Data.
And this is going to be a variable that is going to store the output of the dumps method from the Jason
Library onto our data.
Now, keep in mind that this data is the actual command in our case, since inside of the targeted communication
function, once we call the reliable send, it passes the command inside of the brackets so you can
just change those command to be this data right here.
Then we perform the Jason dumps onto that command and we store it inside of JSON data.
And finally, we can use the same function from the socket library onto our target to send the actual
data so we can type JSON data.
And just to remind you, this target is the actual target socket object that we get once we accept the
connection, we're just using our sockets and function onto this target object once we're sending the
data.
But one more thing before we finish with the reliable function is that in Python three, once we are
sending the data over sockets, we need to encode that data so we can do that by simply specifying inside
of the brackets our data and then encode function onto it.
Then it will first encode the data and then it will send it with this end function.
Simple as that, not the same thing we need to do with our reliable receive.
So I'm going to code it right here for reliable receive.
And we know that the reliable receive doesn't take any parameters inside of the brackets.
And what we're going to do to receive the data is we're first going to define a variable to be an empty
string.
We're just going to call it data.
And we're going to then enter inside of the infinite while troop inside of that loop, what we are going
to try is we are going to try to get the data by typing data equals data, plus target dot receive.
And just to remind you, the receive function is the function from the socket library.
So we're just using it once again on to our target connection.
And this receive function takes one parameters.
That is the amount of bytes that we want to receive.
In our case, we are just going to specify a thousand and twenty four bytes.
But this is not everything that we must do.
Remember that once we are sending the data, we actually encode the data well in order for us to get
the data as it was before it got encoded, we must then decode the data once we receive it right.
And at the end we are going to add a strip function onto all of this.
OK, great.
After that, once we receive the data, we can return from this function digits on dot loads of our
data.
And this is just the format that we're going to output it since remember, we must return from this
function as it does get stored inside of a variable.
Our result will be our data.
And in the accept statement, of course, we must not forget that.
So I'm going to go down here and add, accept and what we're going to accept is the value error.
So in case we get the value error, we're simply going to continue with the execution.
So once again, what is this function doing?
Well, it initiates a data variable to be empty string, then we try to get 20, 24 bytes from our target.
We add it to the previous data that we received.
Then we decode that data, of course, before adding it, and then we strip it from any additional characters.
We then return the Jason loads of that data and that will be stored inside of the results variable that
we then print to our screen.
So all we need to do right now is we need to add these two functions to our backdoor code as well.
So Capitán, save the server code and then no Back-Door, go up here.
And based the functions.
However, there is one thing that we must change, and that is this target that sent right here, since
we are not sending to the target from our backdoor.
We are sending to the server and we initiated the socket object to be s.
So this is our only socket object and we are going to use that to send our data the same thing we want
to do inside of the reliable receive function.
We are not receiving from the target using the socket object since if we left here, target target is
undefined inside of our backdoor code.
Therefore it will throw us an error.
Everything else can stay the same.
And now that we got these two functions ready in the next video, we're going to right the part of the
code that will execute the command.
It is once again stored in this statement right here.
We for now and just put the comment and in the next video, we're going to use the subprocess library
to perform the action of executing the command.
See you in the next video.