All right.
So welcome back everyone.
So now we have everything set up.
So let's get into coding.
The first thing we will learn is how to execute commands on the system.
So if you are a hacker you will often need to execute commands on the system whether it is your honor
system our victim machine.
So what you would want to do is to execute commands go has a certain package that enables you to execute
system commands.
So before we go into creating our code let's first set up our directory structure that will help us
as we move along.
So in order to set it first I am currently in my home directory.
So what you would want to do is go to this go for that.
And then inside this go for that go to the source where we will code everything and here create a new
for load called Go landscaping.
So we will develop all our projects inside this for that.
Once you have built this the next step you would want to do is just open this and create a new form
that can't execute commands.
So this is the first module that we will cover in which we will learn how to execute system commands.
So what our system go on system commands are basically nothing but whatever we write in our next test
or two home.
So whatever we write in our terminal.
This is our command and it has an associated output.
So let's say you want to check which files are present in our directory.
So we will write the list command unless and you can see that it lists out all the directories and files
that are present in this current directory.
So our goal is to create something like that a program that will run commands according to our wishes.
So in order to create it we will develop this program at the moment just for Linux where the procedure
will be exactly the same for Windows as well except for a few minor changes which we will look into
later.
OK.
So the first thing we need is a module on a package that will help us to execute commands.
So Gore has a very important module called OS which has a sub package called execute and this package
helps us to execute system commands.
So the faster we would want to do is to import it so we can say import.
And then we can give the name of the package to the name of the package would be OS.
So it is a part of all.
So whenever you write or as if you're using Google and you will see that you will see suggestions for
different sub packages.
So currently I am interested in this package which is always slash execute.
So I'm going to double take it.
So now you can see that it says an error because it is not used to at the moment.
So now I will go ahead and first we will define which command we want to use.
So let's say we want to find out.
Actually let's just try that unless command which you list out the directory are files in our current
directory so we can name this variable as the command to execute just command is fine.
And then we will set it to list and then we will use this package to execute it.
So in order to execute it we can simply call this package execute and you can see that it has several
methods.
So the method we are industrial then is gone.
Come on.
And it requires the strings and arguments of that string.
So I can write I can use this function and then you can see that it requires the actual command.
So we can put the command here and then if you go to the documentation you will see that commander does
the command stopped to execute the command and the named will go given arguments.
So basically what this function does is that it executes go on and returns an object which is not the
output but a command especial type in galling.
So I'm going to call this as command object
and now at the moment we have an object.
But what we are interested in is the standard output.
So what this command outputs.
So in order to access the output what we can do is we can either say within the variable or we can displayed
on the screen.
So what I would like to do in this section is to display the output on screen.
So what we have to do is we have to set the command object output so you can use this command object.
And if you want to access its methods and fields you can simply pass DOT.
And now you can see you have different options so you can see we have an option called standard error
and standard output.
So at the moment we are interested in output of this command.
So you can write as to the out and the next thing you like to do is we would want to set this output
to our standard output which is the output of this terminal.
So we would like to output to be displayed on this tone.
So we can sadly do or start STV out.
So it will take in the output from this come on and it will printed on the screen because we are setting
it to the output value.
And then similarly we can do the same for error.
So if we do see an error we can do the same process again.
So he can say command object that is to be error is equal to all start as to the error.
Now that you can see that I did not I just thought oh I start STV out and Galant automatically imported
this OS module.
So this may not be the same for you idea if you are using a different idea.
So you may have to import this OS manually.
Now you have set all the parameters of this command object that that are relevant to us.
The next step we would want to do is to simply call a method called Run virtual actually run this.
Come on.
So we can say come on object outrun and this will return this.
Come on and if there is an error in turning this Come on it already done an error object.
So if you go to the documentation and you can see that one starts a specific command and waits for it
to complete and if you check here you can see that Commander Andrew Denton at at we can simply check
for the error.
So if error is not equal to nil we can simply print out this error so we can say logged on freedom and
then it.
So I'm using logged on Twitter because this will exit the program if there is an error in turning this
program.
So now we have our program complete.
So let's just run it so in order to run this file which is mean that go I have to use a certain command
which is go run mean that go
so if I press enter you will see that we let's just clear the screen and try again
and now you can see that we have an output card may not go so in this directory which is B1 underscored
execute underscored commands.
We only have one file which is men that go so it lists only one file here.
So let's say we change the command and set the command to the present day.
Let's say we want to check the date.
So currently five I did in my terminal you will see that I get the date but if I run this fighting so
go on mean that go.
And now you can see we get the same output.
So we can see that our program is working perfectly.
We can also check if it can handle add up properly as well.
So let's say we misspell it we instead of date rewrite it three and rerun go on mean that go.
And now you can see that it is date executable file not found in part.
So this is handling the error because the shell version is thinking that this data is a fly instead
of an actual Come on.
So let's go back to it and try it again and you can see that it runs perfectly.
So now you know how to run cute commands on the system.
This will help us in creating our programs for example creating our ERP spoof program which we will
develop later.
And also when we build a vessel in which we will run commands on Windows machine from our own P.C. so
this is the basic of executing commands.
So I'm going to stop here in next section.
We will proceed further.