Welcome back.
Let us see how we can implement the changing of the directory inside of our server and back door.
So in the previous video, we tested our program for the first time and we were able to execute all
of the comments.
But once we tried to change the directory on the target system, we weren't able to do that.
We were stuck in the same directory.
So let us see how we can bypass this and how we can be able to change the directories inside of our
backdoor code.
The first thing that we must do is we must now know our backdoor.
And down in the channel function here, we must add an option if the command starts with CD first.
Python has a library that is called OS Library and with the help of the OS library we can change the
directory with just one single command.
So first thing that we must do is we must import that library, go up here and import OS.
Once you do that down here in the shell function here, we must add the command.
Or the statement which will say else if command.
And then equals equals to the empty space.
Then we will change the directory, but you might notice that there is something wrong with this statement
right here.
For example, we are comparing the command with CD and empty space, but most likely the command will
be something like CD and then desktop.
So if it compares this with this, these two will not be the same, even though they start the same.
So what we must do, instead of comparing the entire command, we must compare just the first three
characters and we can do that by specifying square brackets and then two dots, up to third character.
In other words, all of this just means that we are comparing the first three characters of the command
with KDDI and empty space and empty space is the reason why we're comparing three characters and not
to.
I have to compare this and they do match, then we can use the OS library and function, which is called
C H there, which stands for change directory onto the command.
And then right here, we need to do the quite opposite thing that we did, which is from the third character.
And then till the end, since this function will be something like this, if we ran the command desktop,
then this function will do something like this os c h dear and then desktop.
So what we essentially did is we compared this and then if they did match, we then used this part of
the command to change the directory.
And this is pretty much it.
We don't need to add anything else.
This will change directory for us.
However, this is not everything that we must do.
What else we must do is we must go to the server code and add the same command inside our target communication
function.
So right here we can add another statement of command equals equals to code and this space.
And here, remember that we also must start from the beginning up to third character.
Just in this case, we are not going to do anything.
We're going to just pass because in server we don't want to do anything.
We just want to go back to the beginning where we can send the next command and in the back there code,
we simply just change the directory of our program.
Now, there is one more comment that I want to add in this video, and that is the clear command.
This is not really that useful, but once you have a bunch of commands and outputs on your desktop,
you can use something similar to this.
That for you is right here.
See, for example, type pseudo IV config and it outputs me with the IV configured command.
I can just type clear to clear the screen.
So let us do something similar inside of our code.
First, we're going to go with the server and if we send the command clear, this command will get sent
to the target.
However, we want to execute it right here inside of our server, since there is no point in executing
the clear command inside of our backdoor code on the target system.
So what we are going to do right here is we are going to add another elusive statement, elusive command,
equal sequel's to clear.
We're going to use once again the OS library and we are going to call the system command, which will
execute the clear command.
This system function allows us to specify any command in the brackets, which will then get executed
inside of our terminal.
Of course, since this is inside of a server code, we must import the OS library here as well.
And since the command will get sent to the back door as well, we want to cover that step also inside
of our shell function.
So let us go right here and add else.
If statement command equals equals to clear just in this case, we will pass and not do anything.
OK, simple as that, and these are just two comments that I wanted to cover in this video, which only
this side comment is really important for us right now.
But in the next video, what we are going to do is we are going to see how we can download and upload
files to the target system.
Then at the end, we are going to test our final version of the program and see whether all of these
commands that we imported work or if there is something that we must change.
So for now, and we got execution of the command, changing of the directory, we can clear the screen
if we get too many things happening and we can quit outside of the shelf.
Great.
Let us continue coding in the next lecture.