Hack Like a Pro: Linux Basics for the Aspiring Hacker, Part 7 (Managing Permissions) « Null Byte :: WonderHowTo

Welcome back, my greenhorn hackers!I've been writingthese Linux tutorialsin an attempt to fill the void in the education of some aspiring hackers into the Linux operating system. There is a lot to know, and in this tutorial, we'll look at Linux file permissions.Step 1: Checking PermissionsWhen we want to find the permissions on a file, we can simply use thelscommand with the-lorlong switch. Let's use that command in thepentest/wireless/aircrack-ngdirectory and see what it tells us about the files there.If we look at each line, we can see quite a bit of info on the file including whether it's a file or directory, the permissions on the file, the number of links, the owner of the file, the group owner of the file, the size of the file, when it was created or modified, and finally, the name of the file. Let's examine each of these.Identifying a File or DirectoryThe very first character of the line tells us whether it's a file or directory. If the line begins with ad, it's a directory. If it begins with a-, it's a file.Identifying the PermissionsThe next section of characters defines the permissions on the file. There are three sets ofrwxthat stands forread,writeandexecute. This determines whether there is the permission to read the file, write to the file, or execute the file. Each set ofrwxrepresents the permissions of the owner, group, and then all others.So, if we look at the second line for the ChangeLog file...We can see that it begins with:-rw-r--r--This means that it's a file (-) where the owner has read (r) and write (w) permissions, but not execute permission (-).The next set of permissions represents those of the group. Here we can see that the group has read permissions (r), but not write (-) or execute permission (-).Finally, the last set of permissions are for all others. We can see that all others have only the read (r) permission on the ChangeLog file.Step 2: Changing PermissionsLet's imagine a case where we wanted the group to be able to both write and execute the ChangeLog file. Linux has a command calledchmodthat allows us to change the permissions on a file as long as we're root or the owner of the file. These permissions are represented by their binary equivalents in the operating system.The NumbersRemember that everything is simply zeros and ones in the underlying operating system, and these permissions are represented by on and off switches in the system. So, if we could imagine the permissions as three on/off switches and these switches are in the base two-number system, the far right switch represents 1 when it's on, the middle switch represents 2 when it's on, and finally, the far left switch represents 4 when on.So, the three permissions look like this when they are all on:r w x4 2 1 = 7If you sum these three, you get seven, right? In Linux, when all the permission switches are on, we can represent it with the decimal numerical equivalent of 7. So, if we wanted to represent that the owner (7) and the group (7) and all users (7) had all permissions, we could represent it as:777Now, lets go back to our ChangeLog file. Remember its permissions? They wererw-r--r--, so we could represent that numerically like:r w - r - - r - -4 2 0 4 0 0 4 0 0This can be represented by644.Changing the Actual Permissions of ChangeLogNow, if we wanted to give the group write (2) and execute (1) privilege, we can use thechmodcommand to do it. We need to add the write (2) privilege and the execute (1) privilege to the ChangeLog file. We do that by:chmod 7 7 4 ChangeLogThis statements says give the owner all permissions (4+2+1=7), the group the same (4+2+1=7). and give everyone else simply read permission (4+0+0=4). When we now do als -l, we can see that the permissions for ChangeLog are now:r w x r w x r - -Simple, right?Step 3: Changing Permissions with UGOAlthough the numeric method is probably the most common method for changing permissions in Linux (every self-respecting Linux guru can use it), there's another method that some people are more comfortable with. It's often referred to as theUGO syntax. UGO stands forU=user or owner,G=group andO=others. UGO has three operators:+foradda permission-forsubtracta permission=toseta permissionSo, if I wanted to subtract the write permission to the group that ChangeLog belongs to, I could write:chmod g-w ChangeLogThis command says "for the group (g) subtract (-) the write (w) permission to ChangeLog."You can see that when I now check file permissions by typingls -l, that the ChangeLog file no longer has write permission for the group.If I wanted to give both the user and group execute permission, I could type:chmod u+x, g+x ChangeLogThis command says "for the user add the execute permission, for the group add the execute permission to the file ChangeLog."Step 4: Giving Ourselves Execute Permission on a New Hacking ToolVery often as a hacker, we'll need to download new hacking tools. After we download, extract, unzip, make, and install them, we'll very often need to give ourselves permission to execute it. If we don't, we will usually get a message that we don't have adequate permission to execute.We can see in the screenshot above that ournewhackertooldoes not have execute permission for anyone.We can give ourselves permission to execute on a newhackertool by writing:chmod 766 newhackertoolAs you now know, this would give us, the owner, all permissions including execute, and the group and everyone else just read and write permissions (4+2=6). You can see in the screenshot above that after running thechmodcommand, that's exactly what we get!In my next Linux tutorial, we will look at managing running processes, so make sure to come back. If you haven't already, make sure to check outthe first six parts of this series, and if you have any questions, ask them in the comments below or in theNull Byte forum.Want to start making money as a white hat hacker?Jump-start your hacking career with our2020 Premium Ethical Hacking Certification Training Bundlefrom the newNull Byte Shopand get over 60 hours of training from cybersecurity professionals.Buy Now (90% off) >Other worthwhile deals to check out:97% off The Ultimate 2021 White Hat Hacker Certification Bundle99% off The 2021 All-in-One Data Scientist Mega Bundle98% off The 2021 Premium Learn To Code Certification Bundle62% off MindMaster Mind Mapping Software: Perpetual LicensePhotos byJoe Shlabotnik,bazzat2003RelatedHack Like a Pro:Linux Basics for the Aspiring Hacker, Part 11 (Apache Web Servers)News:How to Study for the White Hat Hacker Associate Certification (CWA)How To:The Essential Skills to Becoming a Master HackerHack Like a Pro:Linux Basics for the Aspiring Hacker, Part 6 (Networking Basics)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 2 (Creating Directories & Files)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 1 (Getting Started)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 12 (Loadable Kernel Modules)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 9 (Managing Environmental Variables)Hack Like a Pro:Finding Potential SUID/SGID Vulnerabilities on Linux & Unix SystemsHack Like a Pro:Perl Scripting for the Aspiring Hacker, Part 1How to Hack Like a Pro:Getting Started with MetasploitHack Like a Pro:Linux Basics for the Aspiring Hacker, Part 13 (Mounting Drives & Devices)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 25 (Inetd, the Super Daemon)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 21 (GRUB Bootloader)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 5 (Installing New Software)How To:Linux Basics for the Aspiring Hacker: Managing Hard DrivesHack Like a Pro:Linux Basics for the Aspiring Hacker, Part 17 (Client DNS)Goodnight Byte:HackThisSite Walkthrough, Part 6 - Legal Hacker TrainingGoodnight Byte:HackThisSite Walkthrough, Part 8 - Legal Hacker TrainingGoodnight Byte:HackThisSite Walkthrough, Part 10 - Legal Hacker TrainingCommunity Byte:HackThisSite Walkthrough, Part 6 - Legal Hacker TrainingGoodnight Byte:HackThisSite Walkthrough, Part 9 - Legal Hacker TrainingCommunity Byte:HackThisSite Walkthrough, Part 2 - Legal Hacker TrainingGoodnight Byte:HackThisSite Walkthrough, Part 4 - Legal Hacker TrainingGoodnight Byte:HackThisSite, Realistic 3 - Real Hacking SimulationsGoodnight Byte:HackThisSite Walkthrough, Part 7 - Legal HackerCommunity Byte:HackThisSite Walkthrough, Part 10 - Legal Hacker TrainingCommunity Byte:HackThisSite, Realistic 2 - Real Hacking SimulationsCommunity Byte:HackThisSite Walkthrough, Part 9 - Legal Hacker TrainingCommunity Byte:HackThisSite Walkthrough, Part 5 - Legal Hacker TrainingCommunity Byte:HackThisSite Walkthrough, Part 1 - Legal Hacker TrainingCommunity Byte:HackThisSite, Realistic 3 - Real Hacking SimulationsHack Like a Pro:Hacking Samba on Ubuntu and Installing the MeterpreterGoodnight Byte:HackThisSite, Realistic 4 - Real Hacking SimulationsGoodnight Byte:HackThisSite Walkthrough, Part 5 - Legal Hacker TrainingCommunity Byte:HackThisSite, Realistic 5 - Real Hacking SimulationsCommunity Byte:HackThisSite, Realistic 4 - Real Hacking SimulationsCommunity Byte:HackThisSite, Realistic 1 - Real Hacking SimulationsNews:Let Me Introduce Myself