bandit是一个学习linux命令的闯关游戏吧。
地址:http://overthewire.org/wargames/bandit/
bandit0——>bandit1
直接ssh登录就好。
ssh bandit0@bandit.labs.overthewire.org -p 2220
密码:bandit0
查看readme即可得到密码。
bandit1——>bandit2
ls发现一个文件,文件名为-,尝试直接cat失败,-在linux有特殊意义,所以使用./来注明是当前路径下的。
参考:
https://unix.stackexchange.com/questions/16357/usage-of-dash-in-place-of-a-filename
bandit2——>bandit3
根据页面提示:The password for the next level is stored in a file called spaces in this filename located in the home directory
文件名带有空格,可以用双引号将文件名包起来,或者用"\ "(斜杠+一个空格)来代替空格。
参考:
https://superuser.com/questions/606874/cannot-cat-file-which-has-space-in-name-in-linux
bandit3——>bandit4
根据关卡提示:The password for the next level is stored in a hidden file in the inhere directory.
我们需要访问隐藏文件。
ls :显示当前下面的文件及文件夹
ls -a:显示当前目录下的所有文件及文件夹包括隐藏的.和…等
ls -al:显示当前目录下的所有文件及文件夹包括隐藏的.和…等并显示详细信息,详细信息包括大小,属组,创建时间
bandit4——>bandit5
关卡提示:The password for the next level is stored in the only human-readable file in the inhere directory. Tip: if your terminal is messed up, try the “reset” command.
利用file命令查看文件类型。
bandit5——>bandit6
关卡提示:
The password for the next level is stored in a file somewhere under the inhere directory and has all of the following properties:
human-readable
1033 bytes in size
not executable
find -type f -size 1033c
-type f:指定普通文件
-size 1033c:指定为1033字节
其余用法:
-size n[cwbkMG] : 档案大小 为 n 个由后缀决定的数据块。其中后缀含义为:
b: 代表 512 位元组的区块(如果用户没有指定后缀,则默认为 b)
c: 表示字节数
k: 表示 kilo bytes (1024字节)
w: 字 (2字节)
M:兆字节(1048576字节)
G: 千兆字节 (1073741824字节)
-type c : 档案类型是 c 。
d: 目录
c: 字型装置档案
b: 区块装置档案
p: 具名贮列
f: 一般档案
l: 符号连结
s: socket
bandit6——>bandit7
关卡提示:The password for the next level is stored somewhere on the server and has all of the following properties:
owned by user bandit7
owned by group bandit6
33 bytes in size
继续使用find命令:
find / -user bandit7 -group bandit6 -size 32c 2>/dev/null
-user:指定user组
-group: 指定group组
-size:指定大小
后面的2>/dev/null,是因为find命令在根目录下查找会经常有一些权限的报错信息所以通常使用这种方式将错误信息重定位。
bandit7——>bandit8
关卡提示:The password for the next level is stored in the file data.txt next to the word millionth
根据提示,我们可以在data.txt中搜索millionth即可。
bandit8——>bandit9
关卡提示:The password for the next level is stored in the file data.txt and is the only line of text that occurs only once
找到唯一的一行,可以使用uniq命令,但在此之前需要用sort命令对文件进行排序,uniq命令是通过判断上下行是否相等来判断的,所以需要进行排序。
http://www.westwind.com/reference/os-x/commandline/pipes.html
bandit9——>bandit10
关卡提示:The password for the next level is stored in the file data.txt in one of the few human-readable strings, beginning with several ‘=’ characters.
由于使用cat命令会出现乱码,所以选择strings命令,将可打印的字符打印出来,然后和7到8那题一样,查找等号的字符。
bandit10——>bandit11
关卡提示:The password for the next level is stored in the file data.txt, which contains base64 encoded data
根据提示需要base64解码,所以使用base64 -d即可。
bandit11——>bandit12
关卡提示:The password for the next level is stored in the file data.txt, where all lowercase (a-z) and uppercase (A-Z) letters have been rotated by 13 positions
根据提示,字母的顺序旋转了13个位置,相当于26个字符,前13个和后13个的位置交换了,使用tr命令进行转换。
https://en.wikipedia.org/wiki/ROT13
bandit12——>bandit13
关卡提示:The password for the next level is stored in the file data.txt, which is a hexdump of a file that has been repeatedly compressed. For this level it may be useful to create a directory under /tmp in which you can work using mkdir. For example: mkdir /tmp/myname123. Then copy the datafile using cp, and rename it using mv (read the manpages!)
https://en.wikipedia.org/wiki/Hex_dump
先根据提示创建一个文件夹,并使用xxd命令执行反向hashdump,将十六进制转换为二进制文件。
mkdir /tmp/rr
cp data.txt /tmp/rr
cd /tmp/rr
介绍几个指令的作用,之后就是一直解压解压解压。
file test :查看test文件类型
mv test test.gz:将文件名又test修改为test.gz
gzip -d test.gz:解压,对象是*.gz格式的文件
bzip2 -d test.bz2:解压,对象是.bz2文件
tar xvf test.tar:解压,对象是.tar格式文件
思路就是,查看文件是什么类型,然后修改文件命,解压,然后再查看文件类型,如此循环。