Skip to content
Default image

OVERTHEWIRE – BANDIT LEVEL 8 -> LEVEL 9

ssh bandit8@localhost
cvX2JJa4CFALtqS87jk27qwqGhBM9plV

or if you are no longer logged in as bandit7:

ssh bandit8@bandit.labs.overthewire.org -p 2220
cvX2JJa4CFALtqS87jk27qwqGhBM9plV

Ok, new level. things become more complex. We need to find the password stored in the data.txt document and it’s the only line that only occurs once.

The file data.txt is found in the current working directory

Based on the info we’ve got at the beginning of the level, we could assume that the file has hundreds if not thousands of lines. I will use two methods to show you how you can see the number of lines in a file, but keep in mind that there are more ways to do this.

First method

We use the wc command (Count Number of Lines, Words, and Characters). You can find more info about this command on the man page or by using the man wc command in your terminal.

The syntax is wc OPTION [FILE] , in our case we will use the -l option which will print the line count.

Second method

Another way to find out how many lines are in that document is using the grep command ( I have partially covered this topic here, part two to follow. Also, here is the link to the man page ).

The -c operator will print the number of matches and not the match itself. “.*” is used as a wildcard, as we don’t know the pattern of characters we are looking for.

Now back to our game:)

We have found the file and the number of line, going line by line and looking for the line that only occurs once would be a waste of time.

We will use the sort command and pipe the results to the uniq command which will print the password.

sort data.txt | uniq -u

sort -> will sort the line of the file (data.txt in our case) numerically and alphabetically

| -> sending data from a program to another (or one command to another) it's called piping and the operator is "|". it will take the result from the first command and send it to the next command

uniq -u -> we use it to filter out the repeating lines in a file. the -u operator will print the unique lines.

NOTE: the uniq command will not detect repeated lines unless they are adjacent. this is why we have used the sort command and after that we sent the data to the uniq command to filter out the repeating lines.