Hey everybody welcome to the next video.
So in this video we're going to be going over how to work with configuration files or config.
So the first thing we're going to want to do is generate a base config file squared and create one called
config that I and I will throw in some basic information that we might use.
So we'll give this a general tab and we'll say the name is Brandon do age 26 again.
Company Red Team nation.
All right.
So config files are used for a lot of various reasons this can be holding api keys usernames passwords
any type of parameters that might need to be passed.
So it's important to keep an eye on your config files from a red team's perspective as well.
But you might end up using him for some code you need to run.
Now the general rule of config files as you can kind of build it in any way you want.
However what we're going to be doing is using a python parser module for can fix.
So the format has to be like this.
We have our block quotes which has the name of some sort of section.
So this in this case we're claiming as General then we have the value or the key and then the value
should look very similar to a dictionary and that's how it's going to be used.
And then we're going to make another one here called secret.
All right we'll do secret Heidi and we'll do one two three four five.
Right.
Go and save that file now.
The way we use the config parser in Python is we're going to do using something called a config parser
so if we do import config parser that's going to go ahead and import the module for us now to use this
we need to create a config object so config that's equal to config parser
config parser that generates our object force then we're going to have to read in a configuration file
so big that read and then since this happens to be in the same directory we're going to do a config
I and I.
You may have to put this into you know you've got that slash or you know config slash config I and I
if you had a config folder here.
So in this case we write in the config.
So now it understands what it is.
Now there's a few ways we can go about this if you want to get just the sections of the config you use
the dot sections function.
Right.
So we want to print here sections of config and format that way you work.
This is config sections let's go ahead and load this
so we can hear you.
See here are sections of the config is general and secret which corresponds to exactly what we see here.
However it doesn't show us the data itself.
So order we're going to want to do is show the data.
So how do we access this data.
We access this data with the DOD get parameter to config not get.
Then this takes two parameters.
The first one is the section sold holding general and then it's the key.
So we're gonna do.
We're gonna get the name.
No we don't pay for it.
So this should just print out Brandon come thick make sure we spelled that right.
Yeah.
We can see Brandon right there.
Glenn closes So you see Brandon there.
So if we do changes to H
actually 26 now we try to change this to secret I.D. We're not going to be able to get it.
There's no option secret I.D. in Section general.
So we have to make sure we change this to secret because our secret happens to be right there.
Perfect.
So this is how you work with configuration files.
Now it's important to do this when you have any type of parameter that doesn't make sense to necessarily
be passed from a command line such as passwords you don't want to show up in any history so you can
lock down configuration files and the python files pretty hard on a file system.
So golden player Alex changed some of the things around even go back and use some of the previous examples
that we've gone through such as loading up a dictionary which you can do so go and test that out.