Welcome back.
Time to write the code that will execute our commands inside of our payload.
So as I already mentioned for this, we're going to need an additional library to go to your back door
program and import subprocess.
This library will allow us to execute any comment that the server sent.
Let's go down here where we added the comment for the command execution.
We can delete it right now.
And to execute the command, we can do something like this.
We can initiate, execute, and we're going to equal that to the subprocess dot p. open.
And this transfer process open, this process open takes a few parameters.
And the first one will be what we want to execute.
In our case, we want to execute our command.
The second parameter we can select to be shall equal Stroope.
And there are some additional parameters such as study out equal subprocess that pipe and make sure
that you type this pipe in the capital letters.
Another parameter study error equals subprocess dot pipe and the last one will be tested in equals subprocess
dot, but these are all the parameters that we need to specify right here.
The most important one is that you specify this command as the first argument.
Once we initiate the process open onto the execute, we can create a variable called result that will
be equal to execute as to the out dot.
Right.
So we want to read the output.
We're also going to concat to this to execute a study error that read.
So these are the two things that will give us an output of the comment.
Then we will store them inside of the result variable.
And this line that I'm going to write right now could be a little bit tricky.
Let me write it first result, dot the code.
You might be wondering why are we decoding this?
Well, if I go up here.
In the reliable scent, we're going to encode our data and this result is something that we are going
to send in the next line, and once we perform these two lines, we already get an encoded data.
So if we don't decode it first and we try to send it straight away, it will throw us an error.
It will not be able to do that because it is going to try to encode and encode the data.
That's why first we must decode it right here.
And then in the next line, we're going to type reliable underscore and we are going to send our result.
Great.
Now that footedness, let us test our program and to test this program, you're going to need a Windows
environment to compile it and you're going to need any version of Python three.
Now, in my case, I'm using Python three point seven, so I would advise you to use the same version.
So just download Python three point seven, because if it works for me, it will most likely work for
you.
After you do that, what we must do is we must copy our back door to our windows and machine.
Why?
Well, we're going to compile it on a Windows machine for this.
You can use of Windows Virtual Machine if you'd like.
Just make sure you download Python three point seven onto that Windows virtual machine.
Once you do that, you can copy the back door.
I am first going to copy it to my desktop.
So, Mr. Hacker, on the desktop and from the desktop, I'm going to copy it.
Onto the Windows 10 desktop, great, now that we copied it, we're going to need a few things in order
to compile this program.
So, first of all, open your command prompt on your Windows machine, navigate to the directory where
your back door is and to compile this program.
We're going to need a PPI installer library.
You can install that library using PIP as usual.
Once you get the points to the library, you want to go to the directory where your back door is and
type installer.
Then the name of the program, in my case, Back-Door, the P y.
And we're going to use two different arguments.
One of them is one file and the other one is no console.
Won't specify all of this press enter.
And this will compile our Python program for us.
Now, one thing to keep in mind is that you must have all the libraries from this program installed
using PIP in order for the compiling of the program to be successful.
So in this case, our backdoor right here if I admitted using notepad.
We only have these three libraries and all of them are already by default in Python, so there is no
libraries that we must install yet.
But in future, if you keep adding onto this program and you add additional libraries that might not
be by default installed in Python, you will need to install them first using PIP and then you can compile
the program successfully.
OK, great.
Now that we compile the program, we're going to have these four folders.
We're going to have the disk folder, this Bikash folder, this backdoor towards Backfill and the build
folder.
These three right here you can delete straight away.
We don't need them.
And this this folder will have our executable.
Here it is.
It is called backdoor that you see.
And you know, what is the cool part if I scan it using the latest version of Windows Defender?
Here it is, zero threats found, so we created an undetectable backdoor that we coded amazing right
now to test it, to see whether it works, first thing that we must make sure is that the IP addresses
and the ports are set correctly.
And that is something that we should have done before actually compiling the program.
But in my case, I remember that I said they wanted to that 168 dot want a 12 to be the IP address of
Linux machine and the Port five five five five to be the port to connect to, which is in my case,
correct.
So what I'm going to do is I'm going to use Python three to start my server.
It will print out listening for the incoming connections.
And if I go right here, execute the backdoor to.
Nothing seems to be happening, but that is good.
We don't want our program to open anything, but if we go back to here and we wait a couple of seconds
because remember that we set time to sleep command to be 20 seconds before actually connecting to our
Kalinda's machine.
And after 20 seconds, here it is.
We get the shell from our Windows 10 machine.
We get shelled written and then the IP address, as well as the port from which the connection is coming
from.
Now, if we try to execute some of the command prompt commands, such as, for example, who am I?
It seems to be stuck.
So there is something wrong with our code.
Let us go and check our server first to see whether everything is good.
So we got a reliable send and if reliable, receive functions.
Everything seems to be good.
But right here, we reliable received the result and then we print it out, so this could be the problem.
Let's check it out inside the other factor code as well, just to make sure that everything is good
here.
And after a few minutes of searching, I managed to find the error, so the error was inside of the
backdoor code.
The first thing that I didn't do is I didn't import this Jason library inside of my backdoor code.
I only copied these two functions from the server code, but I forgot to import the Jason Library.
So that is the first thing that we must do.
I already did it right here.
And the second thing is the typo right here in this line, we typed our step and it should be our strip.
We need to fix that both here and inside of the server code.
So go down here and change the ah, step into R and then strip, say, right here as well.
And we are going to copy the back door that apply to the whole Mr. Hacker.
And then that's the so we're going to recompile it once again.
All of these things we do not need anymore.
So I'm going to delete them if it tells you right this, that the file is currently in use.
That is because we ran it.
And to close it, we can go to task manager, find the back door data ACCE that is running and close
it inside of our task manager.
Then we should be able to delete the disk folder.
Great.
Now that we did that, what I'm going to do is I'm going to once again copy the backdoor way onto my
desktop and I'm going to compile it once again using the command prompt.
So PI installer backdoor dogpile dash dash one file and dash dash no console press enter.
While this compiling letters go to our clinics machine and let us start our server by country server
dogpile, it will listen for the incoming connections and right here we can go to the this directory
and execute Back-Door dot the.
Once again, these other files we do not need, so you can delete them only if this directory with the
backdoor data.
And in just a few seconds, we should receive the connection right here in our Linux machine due to
the time out of 20 seconds that we coded inside of our program.
And if I type, who am I right now?
It works.
I can execute commands on the target machine.
If I type there, it will tell me that the only file in the directory is back 30 ACCE, and that is
because we are currently inside of this, this directory.
If I type IP config, it will tell me my IP address.
I can type in that stat command to get the net state output where it will tell me all of my current
connections on that target machine.
But if I, for example, try to go one step back, this will not work.
I will still be in the test directory.
So it seems that our program works if we can execute the commands, but for now we can't seem to change
the directories into a different directory.
And that is something that we must see how to fix in the next video.
But for now, it is good that it works.
We saw how we can compile the program to Yuxi using Pine.
So once again, just install Python three point seven on a Windows machine installed pine installer
for the python and install all the libraries that you're using inside of your program.
In our case, we are not using any additional libraries outside of the standard Python Library, so
we didn't need to do that.
Or anything we needed to do is to install pine and then use the command installer program, name one
file and no console as options.
And this should compile the program for you.
Once you execute it, it should connect to the server that we are running from our machine and let us
test the quick command.
If I press enter, it closes the program right here in our terminal.
But does it also close the program in task manager?
Let us check it out.
And it indeed does so we also close the program on the target machine with the quick comment.
Great.
In the next video, we're going to see how we can successfully change the rectories using our program.