In this lecture, we will be creating functions to return enumerated information.
To do so, we will set keywords for specific information.
For example, if the given command is hostname, the commandparser function will call gethostname function.
We will be doing it for every information in generalinfo class.
Let's start coding.
Inside your operations class
we will be creating new statements for new keywords.
For example, if the command contains
hostname.
Commandparser, will call a function.
Let's check the information in generalinfo class.
We have
operating system version, username, essetra-essetra, we will be creating methods for returning
all of those information one by one.
Let's start with operating system or hostname.
We already started with hostname, let's keep it continue.
And if your command contains osinfo, you can select your own keywords.
And for the username, if your command contains username.
And if command contains what else we got.
The processname.
processname
Or if command contains processid.
Actually, we can combine
two of them.
Let's do it in this way, will be combining processname and processid information.
one string value.
So let's go to.
If the command contains pwd (print Working Directory) we will be calling getcurrentdirectory method.
And what else we have?
Let's call.
If command contains
IP address, we will be returning IP version four address and if command contains.
privileges we will be returning if our current users, administrator or not.
What else?
We don't need to get the executable path, but let's do it anyway.
And if our command
contains the exepath we will returning the executable path
So let's start creating functions.
All of them will returning a string value.
So our first function will be gethostname.
And it will be returning
the hostname information in generalinfo class.
We have already created an instance of the generalinfo class inside the operations class
by using our constructor, so we can access all of the information inside the general info class
using this instance.
And for the let's call it get.
username, return the value ninstance.
ninstance.username
and for
IP Version four address, let's create a function called GetIPv4Address, and it will be returning.
Let's remove one line here.
And for
Get process information, we will be returning process name and process id lets call it
processinfo
We'll be returning
process name and a space and processid so processname and processid separated by space.
processId
And for privileges, I will call it a function called getprivileges, and it will be returning if our
current users, administrator or not, and it will be actually a boolean, but we can turn it into a
string by using tostring method.
You can do it this way isadmin.tostring().
And what else you need to do is the exepath and pwd.
For the current working directory, we will set a function called getworkingdirectory sometimes I
pronounce directory as directory
sorry about it.
I'm not a native speaker, so please don't mind me.
return ninstance.cdirectory
and for exepath, create a function called getexepath and it will be returning the executable path.
So let's make the function calls inside the else/if statements.
If the command is hostinfo
we will be calling gethostname.
No arguments needed if the command contains osinfo keyword, oops we need to define it first.
Let's call it public string, gethostinfo our function to return the operating system info.
Operating system info and if our command contains username we will be calling getusername methods and
for the process name.
Let's call it processinfo, actually.
We'll be calling
getprocessinfo method or function, whatever you call, and for the pwd, we will be calling
getworkingdirectory function and for the IP address, we will be calling getIPv4address and for privileges
we will be calling getprivileges.
We will be sending all of those information to attacker server
So we will define one more class and function to send all of those return values to attacker
server.
And for the exepath, we will call it getexecutablepath.
Yep, we are ready.
And from the last lecture, we have printed out the working directorie's files and folders so
just removed that Console.writeline function
Everything seems OK, let's try to compile and execute our program to see if there's any errors.
It seems OK, in the next lecture, we will be executing commands via cmd, so thats it for this lecture.
See you in the next one.