Hello everybody and welcome back.
And in the previous two videos we actually created a simple server and reversal.
And right now we want to be able to send some messages back and forth between these two programs.
So we want to make a connection a little bit longer.
We want to actually send some information from one program to another program and see if that will work.
So let's start off with the server.
So let us open server not be white as we can see we opened everything right here.
Let's see any other video or let's actually open in the first video server and then the second video
we will openly reverse shall not be white.
So what we want to do right now is basically first of all we want to delete the as close for now so
delete this.
We want to delete that in the next one as well.
We will perform the closing of connections at the end.
And right now let us try to actually send something with the send and receive comments as we can see
right here they send and receive is something that we didn't code yet.
So these two comments both of these are both server and client have to have them.
So one can receive and some.
So both of them can both receive and send the information or the commands in our case.
So let's see how we can actually implement that.
Let us start off by implementing it in the server.
So what we want to do is use the command call dot.
Use the function in the socket library called sent it as simple as that.
So what we want to do right here after the target has connected let us see what we can do.
We want to actually get an output from which IP address the target is coming.
So let us see how we can actually give us our command line tool that will be able to give a user that
is using the server.
Our command line that will where they specify a command and it sends that command to deliver shell which
will execute it in Iran on the target machine.
So let us actually make a variable called command so simple as that command is something that we will
send and we want to get the user input for the command so raw input.
We covered all of this.
We know what your input is.
It basically prompts user for an input.
In our case a string input and we want to specify what the user will see.
So double quotes.
Let's start with something like this.
So Star shell and then let's try to create some something simple as our routed terminal shell.
So hash tag I believe something like that and this sign right here then the.
Percent as the percent S is actually the part of the string of the IP that we will attach to the string.
We covered all of this in the python basics.
This is just before this this shell and then hash tag is basically something that you can specify anything
you want.
It doesn't really matter.
I decided to specify that and then we closed this as a string.
After that we need to do to attach loops the string of IP and we can see first of all close the double
parentheses and we can see that the IP is something that we got with these as Dot accept command.
So we will get prompted this string right here just instead of the percent s we will get have written
the IP address of our target machine.
So that would be that for the command then we type any command that we want to run on the target system
and then the target system should execute that command.
So for now on we want to send that command right after we receive it.
So we will do since we specified here we will do socket dot send I believe or not socket since we specify
the target to connect we want to send to the target.
So we want to specify here target dot sent and then the command.
I believe this is the syntax we'll have to check it out but it should be this.
So this is something that for this is a function that will send the input for this command to the target
server.
So let us see if we can actually receive something from the target server after we want to after we
specify the send command option.
We want to actually receive a received data from the target system and how we do that.
We do that with the DOT receive function.
So we will do something like this.
So after that terror target not receive and indeed parentheses in target dot receive we need to specify
the number of bytes.
It will allow us to receive back.
So here will specify thousand and twenty four since we will not really be needing much more than that.
And that would be it for the server.
Now this is a code for only executing a simple command and one command.
So we will send the command that target will execute it.
It will send back the output of that command.
We will print the output of that command and we will close the connection.
So what we want to type right here is basically put this in.
First of all we need to put this in r in a variable so let's call it let's call it result equals target
that receive.
And then after that we want to print the result.
So this parenthesis right here is something from Python 3 so in python 2 you can use the print function
both with or without the parentheses I will use it with in my case.
And after that what I want to do is close the connection.
So this should be it for the servers or server part of code.
So let's double check.
We got target connected we got prompted to input the command we send the command we receive the results
of the command we print the results and we close the connection.
So let us code the part of the client command all of the reverse shall computer code.
So let us do that.
It should be rather simple and similar to the server.
But right now we first want to receive the command and then execute it now to execute the command.
We need to use another library.
So for now on we will not execute command we will just try to send a simple string message.
And later on I will show you how you can send a command and make target executed for now on let's just
say exchange some simple messages.
So how we do that.
Well basically right here we will or Let's for now and so you don't get confused rename this to message.
So it's not a command.
It's just a message simple message for now.
So we have to rename it everywhere.
Message and that should be about it.
And the result we will rename to the answer.
Print answer.
And here we want to first receive the message.
So the message right here will equal the SOC dot receive.
Here we receive the input message of our server.
So we want to receive 1024 bytes and we want to actually
what we want to do is actually send the answer so SOC dot send.
And we want to send.
Well let's actually put it in a variable so answer equals
shallow back
so this is something that the client will send back to the server and we will print it in the answer
as we can see right here.
So now we want to in our client we want to send this answer so we do that we talked not send and we
sent answer.
And after that what we want to do is close the connection.
So SOC that close and I believe this should work.
Let us check it out so let us double check.
We get the command we send the command.
The target receives the command.
It should print the command as well so print message then it they then the target answer will be hello
back.
And then we set the target sends the answer we receive it and put it in an answer variable.
Then we print the answer then recall the connection then the target is what closes the connection.
So in I believe this should work.
So let the safe control all control acts to exit and then control and then control access to exit.
We first run the server listening for incoming connections.
Good.
Then we run the reverse shell connection established the server and we can see that our string input
actually works.
So we get the connection from 127 to 0 0 1 1 port for 4 5 2 0 6.
Here we will send.
Let me just move this a little bit so we can see it.
Oh good.
Just a little bit more.
OK good.
And here we send hello and we can see everything worked perfectly.
The shell the our server got an input of a message where we typed hello we sent that message to the
client which printed that message in its terminal and we can see it does match.
So it is the same message then send the answer back which recorded in the reverse shell which was hello
back and we'd send it send that to our server which printed the answer in our terminal and then they
both terminated the connection afterwards so we got yellow back printed and here we go.
Hello printed.
So that would be about it for the story all we managed to send a simple message.
We will try to make a code which will send infinite messages are not infinite but basically we can send
messages back and forth as long as we want and then we will implement it to be commands that can be
executed on target server or pardon me on target machine.
So that voted for this story well I hope you enjoyed it and I hope I see you in the next one.
Bye.