Everybody looking to Part 5 of the Linux command line main module.
So in this video we're going to be going over Linux file permissions.
So follow permissions and ownership.
So Linux has a concept of file owners as well.
Our ownership as well as permissions.
So a user group and then the permissions for each one.
Now again it's essential to understand that there are a lot of mis configurations and environments around
permissions and owners and groups.
So understanding how this all works and what the permissions are on a particular file or folder is very
important to a red team or because if you're able to identify misc configurations or search widely for
something like World editable and world readable Files world executable files which go over later you're
able to find out and manipulate things to be able to gain more access to the machine so less dash l.
And this is we've we've seen this used before in different videos and we've we've seen the output but
we've really just been focusing on the file name so we're going to what we're gonna do is gonna break
this down.
So we have the first sets permissions and then we have owner the group the file size the last modified
timestamp and then the actual file or directory name whatever the case might be.
Now we're going to be focusing on in this part is the permissions and the owner group.
Now what does the permissions class look like so permissions classes the permissions part the very front
their permissions classes broken up into four sections.
So it's got the type of file the user permissions the group permissions and then the other permissions
and then each permission is broken down into three different bits which is the read write an executable.
Now we're going to hit each one of these in just a second.
So at the beginning of the very first character if it's a D It's a directory if it's a dash it's for
file.
So if we go back up to our example we see the very first characters a dash and we know that this is
the data file that we work with in previous videos.
But if it's a directory you'll see a D.
Keep that in mind.
You can tell based on the color but in case the color actually doesn't matter.
Just look for the D in the front the permissions so a permissions class.
There are three sections.
We've got the user which is the owner of the file.
Think of this as in windows the shared ownership in windows when we've added a user to a file permissions
and gave it like read write etc. so that when you add that user think of that as the user here then
we've got the groups.
Now these are the groups the the file has access to.
So it's not quite the same as the windows groups.
However users can be part of groups.
However you can assign group permissions to just the file and you can do that in windows too.
But it's normally done in an active directory stands which will be going over in a future module.
Now other.
Now this is anybody else that does not match the same group and is not the owner of the file.
So if you are logged in as Bob and you're trying to access Brandon's data you are considered other as
long as your groups aren't the same.
Now the symbolic permissions which is actually the read write next.
Q Now the read permission is indicated by R which we've seen up here already so the read write execute.
Then we have the right which is Reidel or modifiable permissions for the file or folder which is indicated
with a W and then execute.
So be able to execute the file as an executable is an X. Now the X can change to an S which we're gonna
go over and a little bit.
Just know that in most cases that's going to be an X.
Now here are some examples.
So if we want the owner to be the only one able to access the file we would do rewrite in the first
spot leave executable out and blank out the rest.
So a dash in this case means that there's no permission for that user group or other available.
So if we wanted to be executed by every user on the system which is a world executable file which is
important from an engagement or assessment standpoint it's very useful file to find you're gonna see
an X in every single set of three so we can see here we've got the one two three one two three one two
three and make sure it executable by everybody.
Now modifiable by every user on the system so read write read write read write across all three sets.
So user groups other.
And then if you want the directory that every user can read and access you can do read write read and
read for everybody else so the groups and everybody else gets read and then the owner gets read and
write.
Which is fine if we want the directory to be modifiable and the contents of the.
Only by the contents of the owner and its group then we're going to do read write execute read write
execute and then these that should be three dashes.
This is PowerPoint.
Dumping them into one.
Thanks Microsoft.
So this is the other section and then directory only accessible by its own group.
So rewrite execute.
Course the owner has to have its access as well.
And then we have our read and execute for the group only.
Everything else is blank.
So these are just a few examples of how you can do it.
The world readable world executable and also World readable which is not an example here.
However it's exactly the same as all right I'll just remove the W Now it's important to understand those
three because it's very useful on a red team engagement.
So if you've got a world readable file inside of root that's being used by software maybe it's a an
h t h TTP or a web web file you can modify to inject code on that'll run as root because a web server
might be running his root.
There's a lot of different instances where this could play just.
It's always good to double check those and understand what those permissions look like right away.
Now most of the time permissions are done or set with C H mod as the command.
And then some sort of digit.
Now you can use my to do plus X for adding executable to it.
However in most cases people are going to use the binary representation now the way this works is you
have c h mod and then you've got three digits so that each one of those digits corresponds to the first
one of the first seven here being the user or the owner.
The second 7 being the group and then the zero being other.
The way this works is you have your your three your three options here.
So Reid is equal to four rightist to execute as one.
So if you wanted to give somebody read write and execute to leak to the owner you would add four plus
two plus one is seven.
Same thing for the group.
If we wanted to give the group full access we would do four plus two plus one is seven.
Now if we wanted to give everybody else just read access it would be we would change the zero to a four
and then leave everything else.
So this is an example of what the permission would look like.
Now this is a very common way to do it.
And if just as a quick note you probably you may have seen if you've worked with Linux terminals before
or somebody does see mod 7 7 7.
That means give everybody access and readable readable executable to everybody on the system.
That's common when you're troubleshooting something but normally you want to give it as smaller a small
permissions as possible for what you're trying to do.
Now sticky bit is the last bit that we're gonna go over in this video a sticky bit is the replacement
of X with s on the permissions class.
Now the reason this is important sticky bit allows the executable to be ran in the context in space
of its owner.
So if you have an executable that's world executable as an example but it's had it's a sticky bit so
the S is there for the owner.
That means anybody on the system can run that executable in the context of the owner and if the owner's
root and let's say it's V.I. for the file or the file Ed..
Right.
So if you were able to V.I. in V I had a sticky bit on it and it was owned by root and you could run
it as a standard user.
There is a way to spawn a web or a shell off of the eye and that would give you immediate root access
to the machine from your standard user.
It's very important that sticky bits are used carefully and all permissions around it around the file
are set correctly because this can lead to a complete compromise of the system.
Understanding this.
The permissions how they work is very important to looking for those mis configurations so take time.
Go through this play around with the system that you have installed and try try different things out
change permissions you see a mod and change it to where you can't access it then use sudo to change
it up so change it to use sudo just be sudo s you d o space and then c h mod 7 7 7 as an example.
We're not going to go over changing users in groups in this particular video but just understand the
permissions aspect around it.