为了账号安全,请及时绑定邮箱和手机立即绑定

Linux指令初探之闯关游戏Bandit(上)

标签:
Linux 安全

        开学季,Evan会带领小萌新们一点点接触安全领域,今天要给大家讲的是和Linux有关的一款游戏Bandit,通过Bandit你会学到Linux的一些基础指令,这对今后的学习有很大的帮助,准备好了吗让我们开始今天的闯关。游戏地址:http://overthewire.org/wargames/bandit/bandit0.html

  • Bandit Level 0

Level Goal

The goal of this level is for you to log into the game using SSH. The host to which you need to connect is bandit.labs.overthewire.org, on port 2220. The username is bandit0 and the password is bandit0. Once logged in, go to the Level 1 page to find out how to beat Level 1.

首先我们使用xshell建立连接,题目中已经给出了主机,端口号,用户名以及密码,我们填写进去即可

https://img1.sycdn.imooc.com//5b9b9c9c0001e08806570607.jpg

https://img1.sycdn.imooc.com//5b9b9cb800018c0906640600.jpg

点击确定,连接便可以进入到游戏界面,这个界面中对游戏做了小介绍,接下来开始我们正式的闯关。

https://img1.sycdn.imooc.com//5b9b9d0e0001d99807470374.jpg

  • Bandit Level 0 Level 1

Level Goal

The password for the next level is stored in a file called readme located in the home directory. Use this password to log into bandit1 using SSH. Whenever you find a password for a level, use SSH (on port 2220) to log into that level and continue the game.

首先我们使用ls命令查看当前目录下的文件,可以看到题目中的readme文件,cat它,cat的意思为读取文件,格式为cat filename,这样子我们便可以得到通往下一关的密钥。

https://img1.sycdn.imooc.com//5b9b9e3d0001f34003170091.jpg

  • Bandit Level 1 Level 2

Level Goal

The password for the next level is stored in a file called - located in the home directory

ls,读取到文件名为-,但是要注意在这里我们不能使用形如cat -的命令,因为在bash中只用-来连接命令行参数,如果我们使用./表示当前目录,那-文件就可以表示为./-   当然如果是其他的文件名称,我们可以直接使用cat filename命令,完整命令如下:

https://img1.sycdn.imooc.com//5b9ba1660001cd7405700110.jpg

  • Bandit Level 2 Level 3

Level Goal

The password for the next level is stored in a file called spaces in this filename located in the home directory

题目中说文件名称为spaces in this filename,在这里我们要注意这是一个文件而不是四个文件,所以如果写成cat spaces in this filename则会显示如图所示的效果。

https://img1.sycdn.imooc.com//5b9ba33e00016d4d04650139.jpg

虽然文件名有空格,但是在linux中tab键有自动补全的功能,所以我们输入cat s(tab)就可以,cat它便可以得到通往下一关的密钥。

https://img1.sycdn.imooc.com//5b9ba35f000126da04990031.jpg

完整命令如下:

https://img1.sycdn.imooc.com//5b9ba37f0001702704660079.jpg

  • Bandit Level 3 Level 4

Level Goal

The password for the next level is stored in a hidden file in the inhere directory.

题目中说下一关的密钥藏在了inhere目录下的隐藏文件中,那么我们首先需要切换到inhere目录下

https://img1.sycdn.imooc.com//5b9ba4410001aac102960098.jpg

由于题目中说了password在hidden file里,所以我们使用ls无法查看,此时我们需要使用ll或者ls -a来查看,-a 列出目录下的所有文件,包括以 . 开头的隐含文件,-l 列出文件的详细信息,在这里我使用ll来举例子。

https://img1.sycdn.imooc.com//5b9ba4830001fb0e05270103.jpg

可以看到.hidden文件,为什么我们的ls命令无法查看呢?因为ls 内定将文件名或目录名称开头为 "." 的视为隐藏档,不会列出 ), "." 开头的文件为隐藏文件,故 "ls" 没有列出。

完整命令如下:

https://img1.sycdn.imooc.com//5b9ba5230001124e05390204.jpg

  • Bandit Level 4 Level 5

Level Goal

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.

首先我们来看看都有哪些文件,我们可以看到在inhere目录下有10个文件,那么到底哪个是我们需要的呢?

https://img1.sycdn.imooc.com//5b9ba5cb000110cf05250275.jpg

这一关中我们需要学会使用file命令来辨识文件,其中*是通配符,我们可以看到file07是我们想要的ascii text文件,于是cat ./ -file07便可以得到下一关的密钥。

https://img1.sycdn.imooc.com//5b9ba6b10001a78d03330207.jpg

完整命令如下:

https://img1.sycdn.imooc.com//5b9ba6d3000101bd05870611.jpg

  • Bandit Level 5 Level 6

Level Goal

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命令"find . -type f -size 1033c",其中"." 查找当前目录以及子目录,-type f 指定文件类型为普通文件,-size 1033c 指定文件大小为 1033 bytes,完整命令如下:

https://img1.sycdn.imooc.com//5b9ba95e00010c1305550616.jpg


  • Bandit Level 6 Level 7

Level Goal

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的更高级用法,完整命令如下:

https://img1.sycdn.imooc.com//5b9baa59000108e607210122.jpg

在这段命令中 "2>/dev/null"中"2" 表示错误输出,">" 是重定向符号表示把信息送到哪里,"/dev/null" 则代表 Linux 黑洞。

  • Bandit Level 7 Level 8

Level Goal

The password for the next level is stored in the file data.txt next to the word millionth

在这一关中我们要学会grep指令,grep指令用于查找文件内符合条件的字符串,如果发现要查找的,grep则会将那一行显示出来。完整命令如下:

https://img1.sycdn.imooc.com//5b9bac810001bc2605110050.jpg

Bandit Level 8 Level 9

Level Goal

The password for the next level is stored in the file data.txt and is the only line of text that occurs only once

Helpful Reading Material

The unix commandline: pipes and redirects

这一关给了提示:管道和重定向,并且题目中说内容在文件中仅出现了一行,于是我们可以想到首先使用sort对其进行排序,再使用uniq找出不重复的一行,完整命令如下:

https://img1.sycdn.imooc.com//5b9bae6b000106d103930047.jpg

今天就带领大家玩到这里,希望引发大家的思考,小伙伴们新学期加油,我们下期再见。


点击查看更多内容
1人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
Linux系统工程师
手记
粉丝
7203
获赞与收藏
414

关注作者,订阅最新文章

阅读免费教程

感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消