Absolute vs Relative Paths
In this section,
we’ll learn the difference between absolute and relative paths.
To successfully exploit the vulnerabilities
we’ll face later in this Topic,
we need to specify paths to files we want to display,
upload, include, or execute.
Depending on the web application and vulnerability,
we’ll use either absolute or relative paths.
It’s vital for us to understand the difference between these
and how we can use them to specify file paths.
To reference an absolute path,
we specify the full file system path including all subdirectories.
We can refer to an absolute path from any location in the filesystem.
Absolute paths start with a forward slash specifying the root file system.
From there, we can navigate through the file system.
Let’s use absolute pathing to show the contents of a file.
Beginning with the /home/kali/ path,
let’s display the contents of /etc/passwd.
We’ll begin in the home directory of the kali user with the pwd command.
Our second command,
ls /,
lists all files and directories in the root file system.
The output showing etc is located there.
By specifying the / before etc,
we use an absolute path originating from the root file system.
This means we can use /etc/passwd from any location in the filesystem.
If we were to omit the leading slash,
the terminal would search for the etc directory
in the home directory of the kali user,
since this is our current directory in the terminal.
Next, let’s use relative pathing to achieve the same goal.
We’ll display the contents of /etc/passwd
using relative paths from the home directory of the kali user.
To move back one directory, we can use ../.
To move more than one directory backwards,
we can combine multiple ../ sequences.
We can use the ls command combined with one ../ sequence
to list the contents of the /home directory,
since ../ specifies one directory back.
Let’s use two ../ sequences to list the contents of the root file system,
which contains the etc directory.
From this point, we can navigate as usual through the file system.
We can add etc to two ../ sequences
to list all files and directories in the absolute path /etc.
In the last command,
we use cat to display the contents of the passwd file
by combining the relative path.
We can achieve the same results using extra ../ sequences.
The number of ../ sequences
is only relevant until we reach the root file system.
Theoretically, we can add as many of them as we want,
since there is nowhere further back to go.
This can be useful in certain situations,
such as when we don’t know our current working directory.
In this case, we could specify a large number of ../ sequences
to ensure we reach the root file system from a relative pathing perspective.