Linux指令初探之闖關遊戲Bandit(上)
開學季,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
首先我們使用xshell建立連線,題目中已經給出了主機,埠號,使用者名稱以及密碼,我們填寫進去即可
點選確定,連線便可以進入到遊戲介面,這個介面中對遊戲做了小介紹,接下來開始我們正式的闖關。
-
Bandit Level 0 Level 1
Level Goal
The password for the next level is stored in a file called readme
首先我們使用ls命令檢視當前目錄下的檔案,可以看到題目中的readme檔案,cat它,cat的意思為讀取檔案,格式為cat filename,這樣子我們便可以得到通往下一關的金鑰。
-
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命令,完整命令如下:
-
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則會顯示如圖所示的效果。
雖然檔名有空格,但是在linux中tab鍵有自動補全的功能,所以我們輸入cat s(tab)就可以,cat它便可以得到通往下一關的金鑰。
完整命令如下:
-
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目錄下
由於題目中說了password在hidden file裡,所以我們使用ls無法檢視,此時我們需要使用ll或者ls -a來檢視,-a 列出目錄下的所有檔案,包括以 . 開頭的隱含檔案,-l 列出檔案的詳細資訊,在這裡我使用ll來舉例子。
可以看到.hidden檔案,為什麼我們的ls命令無法檢視呢?因為ls 內定將檔名或目錄名稱開頭為 "." 的視為隱藏檔,不會列出 ), "." 開頭的檔案為隱藏檔案,故 "ls" 沒有列出。
完整命令如下:
-
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個檔案,那麼到底哪個是我們需要的呢?
這一關中我們需要學會使用file命令來辨識檔案,其中*是萬用字元,我們可以看到file07是我們想要的ascii text檔案,於是cat ./ -file07便可以得到下一關的金鑰。
完整命令如下:
-
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,完整命令如下:
-
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的更高階用法,完整命令如下:
在這段命令中 "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則會將那一行顯示出來。完整命令如下:
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
這一關給了提示:管道和重定向,並且題目中說內容在檔案中僅出現了一行,於是我們可以想到首先使用sort對其進行排序,再使用uniq找出不重複的一行,完整命令如下:
今天就帶領大家玩到這裡,希望引發大家的思考,小夥伴們新學期加油,我們下期再見。
作者:Evan_hui 連結:https://www.imooc.com/article/78992 來源:慕課網