Bandit Level 17 → Level 18

Level Goal

There are 2 files in the homedirectory: passwords.old and passwords.new. The password for the next level is in passwords.new and is the only line that has been changed between passwords.old and passwords.new

Commands you may need to solve this level

cat, grep, ls


Since the command diff will output all the lines that are different between two files, this was a lot easier than I expected.

diff passwords.new passwords.old
42c42
< kfBf3eYk5BPBRzwjqutbbfE887SVc5Yd
---
> PRjrhDcANrVM6em57fPnFp4Tcq8gvwzK

The top line is from passwords.new and it is the next password. However, I want to find out how to do this with grep. Looking at grep options, Our goal is to use one file as a list of pattern to match the other file and find out which line is not matched. From man page, -f will read one or more newline separated pattern from file. -v will invert the match. We put the passwords.new after passwords.old to use passwords.old as the pattern and anything different in passwords.new will be output and the result are the same.

grep -vf passwords.old passwords.new
kfBf3eYk5BPBRzwjqutbbfE887SVc5Yd
Advertisements