plasticglass

information security and technology

im plasticglass. i write about the sh*t i do.

"bandit" part 1: navigating the LFS

1.1 - examining and navigating directories

as previously discussed, the LFS is made up of nested directories, like folders-within-folders. users navigate through the LFS by moving up, down, and laterally through the levels of directories. to do so, the user executes the cd command, which stands for "change directory". though most directories have text-based names, there are 3 shorthand names that act as placeholders to aid in navigation.

the first is "~", which stands in for the "/home" directory. executing cd ~ will change the current working directory to /home.

the second is ".", which means "the current working directory". executing cd . will have no effect, as the current working directory will not change.

the third is ".." which means "the parent directory of the current working directory". executing cd .. will change the working directory to the parent directory of the current directory, effectively moving the user "up a level".

to move into a directory within the current working directory ("down a level"), the user executes cd directoryname.


to examine the contents of a directory, the ls command is used, which is a shortening of the word "list". on its own, the command will list the contents of the current working directory, with no information other than the filenames. however, there are multiple modifications that can be made:

    ls -l: long format. displays file type, permissions, owner, group, number of hard links, size, and date-time of last modification.
    ls -a: show all files, including hidden files.
    ls directoryfullpath: list contents of a directory without having to be in that directory.


1.2 - accessing and reading files

there are multiple ways to display the contents of a file in the linux command line. the first, and likely easiest to use, is cat, which is short for "concatenate". there are a few ways to use it:

  • cat filename: outputs the contents of filename to the terminal.
  • cat file1 file2 file3 ...: outputs the contents of each file to the terminal in the same order they were specified in the command.
  • cat filename > outputfile: writes the contents of filename to outputfile.
  • cat filename >> outputfile: appends the contents of filename to the end of outputfile.

another method of reading files is the more command. this command will output the contents of a file one page at a time. between pages, the command waits for the user to prompt it to continue. because the command waits for user input, the user can also execute certain commands at these breaks.

a similar command is less, which is very similar to more. the difference is that less allows the user to scroll backwards through the text. it pages the same way, though.

the page size used by both more and less is determined by the number of lines available in the terminal, which is just another way to say it depends how big the terminal window is.


1.3 - filenames

in the LFS, the format of a filename can change how it behaves, and what must be done to access it.

  • filename: a normal filename, which will be displayed in a directory normally.
  • .filename: a hidden file, which will normally not be displayed. it can be shown by adding the -a option to ls.
  • file name: this file will be displayed normally, but the name must be put in quotes to reference it in a command.
  • file-name: this file will be dsiplayed like any normal filename.
  • -filename: the filename must be preceded by "./" to reference it in a command. it is not recommended to begin filenames with "-".

hidden files play a big role in linux systems. not for security reasons, as it is trivial to expose them. however, many config files are hidden so they don't get in the way.


1.4 - file information and readability

certain file types and data types are classified as "human readable" or "machine readable". for example, text in a .txt file is "human readable", while binary data in an executable file is "machine readable".

the file command can be used to gather useful information about the files in a directory.

  • file filename: returns the file/data type of filename.
  • file *: returns the file/data type of all files in the current working directory.

1.5 - searching for files

if certain attributes of a file are known, then the find command can be used to locate any file matching those specifications. the command will search a specified directory, which need not be the current working directory. if no directory is specified, the current directory will be searched. bear in mind that the command will return a "permission denied" error for every match it finds for which the user doesn't have sufficient permissions.

attributes searchable with find include, but are not limited to: owner, group, size, and type.



walkthroughs

bandit levels 0-6

bandit 0:

the goal of this level is to connect to the game. read the page for level 0 at overthewire.org/wargames/bandit/bandit0.html, and then format the following command with the correct values:

ssh username@host -p port

make sure to use man ssh to ensure you are using the right syntax.

once you are connected, examine the current working directory. read the contents of the "readme" file to find the password for level 1.

relevant sections: 0.3 1.2 1.3


bandit 1:

the next password is stored in a file whose name begins with a "-" (in fact, it's name is just "-"). read the contents of this file to find the password for level 2.

relevant sections: 1.3


bandit 2:

examine the current working directory. the file containing the next password has spaces in its filename. modify your chosen command to read it and get the password for level 3.

relevant sections: 1.3


bandit 3:

examine the current working directory, and change directories to the "inhere" directory. examine that directory thoroughly to find the password file. once you have found the file, read it to get the password for level 4.

relevant sections: 1.3


bandit 4:

there are several files in the "inhere" directory, but only one of them is human-readable. identify that file, and read it to get the password for level 5.

relevant sections: 1.4


bandit 5:

the password file is located somewhere under the "inhere" directory. it is 1033 bytes in size, human-readable, and not executable. find it and get the password for bandit 6.

relevant sections: 1.4

hint: if you are stuck, run man find for a clue.


bandit 6:

the password file is not necessarily under the /home directory, but is somewhere on the server. it is owned by user bandit7, belongs to group bandit6, and is 33 bytes in size. find it and read it to get the password for level 7.

relevant sections: 1.5

hint: for this level, it will likely be necessary to find a way to exclude certain things from a command's output. read up on the "/dev/null" directory.


part 2 - working with files in the LFS