Hello everybody and welcome back.
And right now let us try to make our sending all messages infinite or basically we will send messages
back and forth until someone terminates the connection and that someone will be the server.
So let us open up our server in this terminal.
We have the same code as from the previous video.
So it is everything the same I did and change everything.
Anything.
So what we want to do first of all we have to create an infinite while loop in both of these programs.
So let's start off with the server.
First of all let us delete the things that we don't need.
Here we have everything.
So we will use all of this after the print Target connected.
We want to open a while loop.
So we want to make it basically infinite.
So we will do while true which means that it will execute everything in the loop forever until the program
is terminated.
So we have to put everything right here in the while loop.
So tab it just tap it right here.
Target set.
Message and Sir equals target not receive print answer and then sock it out close.
Now socket that close you do not want to put in the while loop since every time at the end of the while
loop it will close the connection.
So socket that close or as it got closer or higher renamed it should stay outside of the while true
of the.
Yeah basically outside of the while loop.
So here we also want to add something.
So this should start off with the command or message in our case or input shall and then we pipe our
string input of the IP address and the local port to it.
Now this is something optional you can just type here anything you want.
I just type this or it looks prettier and so we can see from where the connection is coming from then
we send the message and what we want to do after that is actually have to have two different choices
which is basically on two different outcomes which basically if the message is anything else we want
to send it to the target and wait for the reply.
If the message equals Q Just a simple letter Q We want to terminate the connection.
If we do not have that statement to terminate the connection this file to look will on forever and we
will have to close the program on the UN appropriate weight.
So we want to actually exit it properly so after the center command we want to run and if our slope.
So if message which is something that we type equals equals double quotes Q close double quotes and
then two dots we want to actually break out of the loop as we can see right here we break out of the
loop and then we can type your Ls
answer equals target dot receive print answer.
So let's see if this makes sense.
We actually type the message itself we store it in this variable we send the message to the target if
message equals Q This will close the program it will call it will break out of the loop then it will
continue to the next execution which is as close if it is not clear.
Q It will receive a target answer it will print the answer and it will go to the beginning of the loop
which will prompt us with the input of another message and that will do forever until we specify Q As
a message.
So this should work for the server.
Now let's see what we have to type for the client in order for this to actually work together.
So for the client what we want to actually first delete is the answer or no.
Let's actually make a chat program.
So what we want to do is delete these two instructions.
Here we have a message equals saga about receive.
So we want to put both of those into while True loop.
So let's see how this will do.
While true we run the same thing then we tab these two message equals all not receive print message
and then we leave this octet close below.
We do not want to put that in the while loop for same reason that we didn't want to put it here so it
doesn't terminate the connection in our while loop.
So right now let's see what we have to code right here in order for this to work.
So we send the message this will receive the message and it will print the message so good.
Then afterwards we want to specify the message back.
So this is something we can do right here.
The message back let me just see if this will work the way it should work.
So this is something that we want to do so if message that we received equals equals Q Same as in the
previous we want to break the connection as well.
Since if this server right here sent Q it already closed this program.
So if we receive a Q command it means that the server has closed the connection.
So we want to close it as well.
Else we want to actually get an input.
So we want to send message back or we'll call it like that.
That is a variable and then raw input third type message to send to server which is a little bit long
but it doesn't matter.
So we get the message back.
We get an input on our client to send a message back to server and then we basically just suck it up
send the message back then after that it will go back.
Right here it will receive another message that it will print the message and we can go on forever I
believe.
So let us save this control all their control acts to exit.
Same as here.
Control all control extra exit and then we run our server first policing for incoming connections then
we run the reverse shall that be why we get him prompted with this shall command through and we will
just type here.
Hello and we can see that the client printed out our message and it prompts declined to type message
to send to the server and we will type here Hello or Hi there.
Let's just type here.
Hi there.
And we can see this works perfectly.
We got the message back from the client which says hi there that we can say what are you doing.
And the client will receive our question.
They can answer nothing with the slash.
That was a typo.
So right now let's say we want to terminate this connection and we type your cue.
They both terminate the connection.
Just right here it also prints the answer which is not necessary but it doesn't really matter.
They both successfully terminated the connection.
So our simple chat program works.
So this is a simple code that we wrote in order to make a chat program but you might be asking why are
we making a chat program.
Of course our reverse Shell will not be prompted anything for the target to type.
We want to actually execute the commands and not exchange messages between each other.
So this will be similar.
We will not change much to this but this will have to change.
So the user or the target doesn't get prompted with these type messages to send to the server.
We just want to make the target actually execute the message and send the output of that message back
in our case.
Those will be terminal commands or command prompt comments.
So we will do that in the next video and I hope I see you there by.