Lab 2: Linux Permissions

Linux Permissions

Soon we will be discussing access control in greater depth, and understanding how permissions work in Linux serves as a nice precursor to what we will be covering, as well as some of the labs you will be doing next weeks.

Some helpful resources:

Bash Shenanigans

If you couldn’t tell, you’ll be using the pwn.college platform a lot this semester, and it would be good to understand a little more about the Linux terminal environment that you complete challenges in.

When you open a terminal, the program that provides the user interface is called a “shell” and you issue commands in the Shell Command Language (sh) or a variant of it. One of the most popular shell programs, and the shell being used in pwn.college, is called bash (Bourne Again Shell), and while there are subtle differences between /bin/bash and /bin/sh, we won’t concern ourselves with them here.

We can write automated scripts for a shell by creating an executable text file that start with a “shebang” that indicates the program used to run the script (e.g. #!/bin/bash). For a refresher on bash syntax, refer to this demo script.

The challenges you will be completing have to do with manipulating a user’s .bashrc profile file. When you open a terminal connection/application, typically, you are automatically logged in as a registered user on the system. The .bashrc profile is a special bash script and is a way for the user to customize their experience while using bash. When a user starts a bash session, their .bashrc file is executed before any user commands are accepted. Bash also looks at a number of other special scripts to run for user customizations, but we need not consider these here.

You will also need to know about your environment’s PATH variable. When you execute a program in bash, say for example ls, grep, or echo, bash must first figure out which program you are attempting to execute. Unless you explicitly specify the path to an executable, (e.g. /usr/bin/python) bash will look for the program using the PATH variable. The PATH variable is a list of absolute paths to directories that contain executables. Bash will search through the directories in PATH one at a time until it finds a matching name. If it cannot find the program, it will error.

The exact details of how the PATH variable is set are a bit messy, but the important thing to note is that you can modify your PATH variable at any time, just as you would any other environment variable, using the export command.

For instance, to tell bash to look in the directory /home/hacker/scripts for a program first, before any other location, you would modify the PATH variable like so:

export PATH=/home/hacker/scripts:$PATH

Note that the elements of the list are separated with a colon :.

You will likely need to write scripts and get them onto the VM instance. If you do not know how to use vim or another in-terminal text editor like nano or emacs (it would make things much quicker if you learned just the basics of one), you should still be able to use the desktop version of the challenges.

Post-Lab