Notes from Overthewire Bandit
I solved the Bandit wargame by Overthewire over the last few days, and noted down anything new // interesting I learned. This is not a writeup in any way, you’re not likely to find solutions to specific questions here. This is more like study notes, mostly for me to come back to it later. That being said, I’m hoping it’ll help you in some way too.
Stuff I learnt
- man page vs the help command —
helpis a feature of bash shell, it documents somebashcommands, and is available in bash only. Whereasmanis more general, and is a native feature of all Unix or Unix-like operating systems. -
We can use dash (-) in Linux as an alias of
stdinorstdout, whereas the standard way to do it would be using/dev/stdinand/dev/stdout. To use files named dash, either of the following can be used.- Specify the filename relative to current directory.
$ cat ./- - Bash redirection.
$ cat < -
- Specify the filename relative to current directory.
-
Some interesting Unix commands.
file,find,xargs,grepand piping between them to look for interesting files.sortanduniq, for getting unique lines in a text file.stringsfor searching for strings in binary files.base64to encode or decode Base64.tr 'A-Za-z' 'N-ZA-Mn-za-m'for ROT13, or any suitable variation of the command for any form of the ROT encryption. Obviously, it can be used for other sorts of substitution, such astr '[:upper:]' '[:lower:]will convert uppercase to lowercase.gzip,bzip2and thetarare the standard compression formats used in Linux, and there are corresponding programs with the same names.xxdfor creating hexdumps and reverse hexdumps.nc host portfor arbitrary TCP // UDP connection.openssl s_client -connect host:portfor connecting to SSL services.nmapfor port scanning.difffor diffing, obviously.scpto copy stuff over the SSH protocol.- Unix job control —
jobs,fg,bgandCTRL+Z - Listen on a port using netcat —
nc -l -p port - Split by space and take first element from each line —
cut -d ' ' -f 1 md5sumfor MD5 checksum (duh!)- More commands! —
seqandtee.Seqproduces a sequence of numbers, which can in turn be used in for loops in bash. Format strings can be used with withseq, like%04g. Tee can be used to put data fromstdininto a file. echo -eis to be used when we’d want bash to interpret escaped characters as they are.getent passwd— for checking/etc/passwdfile.- Immensely useful for checking the history of a git repository —
git log --graph --decorate --all --oneline
- You have to have
400as the permission for the SSH private key. setuid,setgid,stickyand the correspondingchmodcommands. These bits control which user the executable would be run as. Kind of similar to setting the “Run as administrator” flag in Windows, only here in Linux it’s much more flexible and versatile.crontabs are in the/etc/cron.d/directory, and cronjobs are run as the user that owns that crontab file.- Sometimes you can’t
lsorcdinto a directory, but still can write inside that directory…. strange but useful. - There should be no spaces around the equal sign while assigning variables in Bash.
- You can trigger
moreto go into a command mode by making the terminal small enough. And while you’re in that mode, pressing v will open up and editor, by default vim. And then you can use vim commands to access the files, such as:e filenameto open a file and:set shell=/bin/bashand then:shellto open a shell. - Finding info leak in git repos.
- Check
git logandgit tagsand look for any interesting commit // tag. And then checkout to it usinggit checkout commitand grab that info. - Check
.git/packed-refsfor all refs. And then, if checking out to a ref doesn’t work, usegit show reforgit cat-file -p refon it to directly read the contents.
- Check