邪恶先生闯关实验

实验环境和准备

我用的kali Linux,你们用其他版本Linux也可以。
需要用wget命令下载一个压缩文件,文件地:https://www.cs.cmu.edu/~213/bootcampslab1_handout.tar
然后用tar -xvf 命令解压缩

1
tar -xvf lab1_handout.tar

解压后进入lab1_handout目录,可以看到三个文件
bomb , lab1_handout.tar, start
其中第二个不用管,第一个bomb是一个可执行文件,开始游戏需要执行他,start 目录使我们游戏过程中要进行操作的目录。
建议开两个tty(用户终端),一个用来看游戏信息和提交答案,一个用来进行对应操作,游戏一共七关,我们在命令行输入 ./bomb 即可开始游戏。在Please enter your answer:下输入答案,当你输入错误答案时他也会给你提示信息,下面我将带大家过一遍这个游戏,本人英语不好,有翻译错误见谅。
***别忘了在start目录外创建一个文件把每一关的答案记录下来

第一关

原内容信息

Welcome to my evil plan directories. You have 7 phases to solve!

Your first task is to free the UC stones. We’ve noticed that the
/university_center/stones.txt file is captured (It seems like it’s stuck in the captured directory).
Maybe you could read the directory
names to help you free_the/university_center/stones.txt? It might
be beneficial to first look at stones.txt ;)

Please enter your answer:

大概意思让我们把一个困在captured目录的stones.txt文件解救到free_the目录下,先让我们找到并查看stones.txt文件,我们打开操作终端,查看stone文件,里面的内容告诉我们要把他和他的父目录一起移动到free_the目录下,并且用pwd命令,显示出解救后的路径并提交。
这里我们用到mv命令移动university_center目录,然后转到free_the目录用pwd命令显示路径:

1
2
3
4
5
6
(kali㉿kali)-[~/lab1_handout/start/capture_the]
└─$ mv university_center ../free_the

(kali㉿kali)-[~/lab1_handout/start/free_the/university_center]
└─$ pwd
/home/kali/lab1_handout/start/free_the/university_center

之后我们把路径复制下来,回到作答终端,ctrl+shift+v粘贴答案即可。

第二关

原内容信息

Good job on freeing the stones, however there’s still much work that
needs to be done! Your next step is to prevent any stones from EVER ending
up in ~/capture_the/ directory. Make sure to tell Mr. evil the
command you will use!

Please enter your answer:

第二关的大致内容是让stones永远不会出现在capture_the目录里,然后问我们用什么命令,永远不会出现在这里,那我们把capture_the目录删除就好了,这里用到rm -r命令,-r代表删除目录。

1
2
┌──(kali㉿kali)-[~/lab1_handout/start]
└─$ rm -r capture_the

然后我们把rm -r capture_the这行命令复制下来,回到作答终端,粘贴回车即可进入下一关。

第三关

原内容信息

The best solution to defusing Mr. Evil’s plans to
capture the UC Stones is to understand what his evil plan is.
Mr. Evil tried to make it difficult to find his evil plans by
littering many of them in the evil_plans directory. We need to
find the plan that contains the phrase “secret message:”.
Think about which command would be helpful to find a phrase in a file.
What is the secret message?

Please enter your answer:

第三关大致内容是我们要了解邪恶先生的邪恶计划,但是他为了不让我们知道,创建了许多文件来迷惑我们,我们需要根据提示,在evil_plans目录下找到包含字符串‘secret message:’的文件,(冒号别落下了),这里我们用到grep搜索命令,进入操作终端,在对应目录下使用grep命令:

1
2
┌──(kali㉿kali)-[~/lab1_handout/start/evil_plans]
└─$ grep 'secret message:' *

中间要搜索的字符串用单引号括起来,*号代代表搜索所有包含该字段的内容。
搜索完毕后我们会找到一个结果:
evil24.txt:21 secret message: pineapple
然后我们把pineapple这个字符串复制粘贴到终端1的作答区即可。

第四关

原内容信息

We’re trying to discover what the rest of his plans say, but if
we try to open an editor with the file, Mr. Evil will receive a
notification. The best practice is to sneakily view it in the
command line. What command will you use to view evil24.txt?

Please enter your answer:

大致内容是我们试图发现他的计划其余说了什么,但是打开编辑器查看会被发现,问我们在命令行用什么命令查看evil24.txt文件,这里我们用的是cat命令来查看,然后我们在作答区输入cat即可。

第五关

原内容信息

If we examine the evil text file with the secret message closely,
there might be some important information for how to understand
Mr. Evil’s next steps. What is the last instruction that the evil24.txt
file tells you to do? Now execute it! Try doing this with pipes!

Please enter your answer:
大致内容是,让我们查看evil24.txt文件的最后一行的信息,还提示我们用管道。
我们找到evil24文件用cat命令查看后找到最后一行信息,
发现他让我们查看前几行信息,我们翻上去找到前几行,上面写着该文件未排序,还让我们用-n flag,并且删除重复项,
这里我们用到sort命令和uniq命令,然后用管道把他们连起来

1
2
┌──(kali㉿kali)-[~/lab1_handout/start/evil_plans]
└─$ sort -n evil24.txt | uniq

执行后我们就得到了有序无重复的文本,阅读前几行得知,让我们创建一个叫release.txt的文件在we_tried_to/目录下,然后提交我们创建文件的命令,这里我们用touch命令,

1
2
┌──(kali㉿kali)-[~/lab1_handout/start/we_tried_to]
└─$ touch release.txt

然后我们把该命令内容粘贴到作答区即可进入下一关

第六关

原内容信息

Make sure you remove the evil_plans directory and all of its contents!
Mr. Evil has a tendency to hide information in the outputs of different files.
But, the information in start/we_tried_to/them/one/listened.c seems to be missing information for it to run properly.
Read the TODO’s in listened.c Make sure to NOT delete the comments!

Please enter your answer:
大致意思是先让我们删除evil_plans目录,然后让我们查看start/we_tried_to/them/one/listened.c这个文件,但这个.c文件似乎缺少一部分东西导致不能运行,让我们查看文件内的提示。我们找到并打开listened.c文件,查看提示我们得知,答案是一个魔法数字,然后缺失的代码在start/we_tried_to/them/no.txt文件中,这里我们用vim命令同时分屏编辑no.txt和listened.c文件代码如下

1
2
┌──(root㉿kali)-[~/…/start/we_tried_to/them/one]
└─# vim -O listened.c ../no.txt

然后把no.txt文件内容全部复制粘贴到listened.c文件中的相应位置。根据提示,再用gcc命令编译该程序,然后用./a.out输出文件再定向到start/we_tried_to/them/but.txt中,具体操作如下

1
2
3
4
5
┌──(root㉿kali)-[~/…/start/we_tried_to/them/one]
└─# gcc listened.c

┌──(root㉿kali)-[~/…/start/we_tried_to/them/one]
└─# ./a.out >> ../but.txt

然后根据后序提示让我们把but文件里边的输出结果进行数字排序并用head命令查看第一行内容,而且要利用管道
这里我们根据提示使用如下命令:

1
2
┌──(root㉿kali)-[~/lab1_handout/start/we_tried_to/them]
└─# sort -n but.txt | head -n 1

就可以得到一行信息,最前面的数字42就是我们的答案,把它输入到作答区即可进入最后一关。

第七关

原内容信息

Students have been trying to understand what Mr. Evil’s secret message is.
Mr. Evil has a tendency to save hints in file names and directory names.
Maybe Mr. Evil has organized the file names and directories to include
his secret message. We want to see all the names of the directories and files.
You should execute this Earth friendly command from the start/ directory.
Please type the secret message. Make sure you remove
the evil_plans directory and all of its contents! (You’ll probably want to
remove the a.out file from phase 6 too!)

Please enter your answer:
大致内容是邪恶先生喜欢把计划藏在文件名和目录名中,让我们用一个对地球友好的命令来查看start目录框架并找出邪恶计划,而且让我们先删除第六步的a.out文件和确保evil_plans目录已经删除,然后我们随便输入一个答案,看看提示信息
Try using tree on the start directory. Do not include ‘/‘ and have all lowercase letters. You might want to delete
the evil_plans directory, or just ignore them. You also probably want to replace the _ with spaces!
他让我们用tree命令不包含/和小写字母,然后用空格代替’‘。
我们在start目录下用输入tree命令查看文件架构,然后把所有文件名从头到尾连成一句话,用空格代替’
‘,得到这句话就是最终答案,粘贴到作答区即可通关。