397 字
2 分鐘
[OverTheWire] Bandit Level 31 → Level 32

Level Goal#

There is a git repository at ssh://bandit31-git@localhost/home/bandit31-git/repo via the port 2220. The password for the user bandit31-git is the same as for the user bandit31.

Clone the repository and find the password for the next level.

Commands you may need to solve this level#

  • git

My Answer (Step by step)#

  1. 連線到伺服器並登入
Terminal window
ssh bandit31@bandit.labs.overthewire.org -p 2220
  1. 透過 mktemp 指令產生暫存資料夾,並透過 cd 指令進入它,以便稍後 clone git repo
Terminal window
mktemp -d
cd /tmp/tmp.Tc5YfqLCbF
  1. 透過 git 指令將 repo clone 下來
Terminal window
git clone ssh://bandit31-git@localhost:2220/home/bandit31-git/repo
  1. 透過 cd 指令進入 repo 資料夾,並透過 ls 指令查看資料夾內容
Terminal window
cd repo
ls
# README.md
  1. 透過 cat 指令讀取 README.md 檔案,發現沒有密碼,但有要求我們將一個檔案推到遠程 repo
Terminal window
cat README.md
# This time your task is to push a file to the remote repository.
# Details:
# File name: key.txt
# Content: 'May I come in?'
# Branch: master
  1. 透過 touch 指令建立檔案 key.txt,並透過 vim, vi, nano 等指令編輯該檔案
Terminal window
touch key.txt
nano key.txt
  1. 透過 git status 指令查看 repo 情況,發現 git 沒有偵測到有新檔案,透過 ls 指令發現目錄還有一個 .gitignore
Terminal window
git status
ls -al
  1. 透過 cat 指令讀取 .gitignore 內容,發現忽略所有 .txt 檔。
Terminal window
cat .gitignore
# *.txt
  1. 透過 rm 指令將其刪除,並重新透過 git status 指令查看情況,發現 git 有偵測到 repo 發生變化
Terminal window
rm .gitignore
git status
  1. 透過 git add 指令將所有變化從工作目錄移至暫存區,並透過 git commit 指令把暫存區的內容移至儲存庫(repo)
Terminal window
git add .
git commit -m "add key.txt"
  1. 透過 git push 指令將本地 repo 與遠程 repo 同步,即可獲取 Level 32 密碼!
Terminal window
git push

第 32 篇,共 34 篇本文屬於系列

[OverTheWire] Bandit Level 31 → Level 32
https://m21248074.github.io/blog/posts/2025-01-25-post094916/
作者
Cavey (凱維)
發佈於
2025-01-25
許可協議
CC BY-NC-SA 4.0

分享文章

生成精美分享圖或複製連結,與更多人分享本文。

繼續閱讀

沿著主題讀

基於共同的標籤與分類

換條路線

從其他文章中穩定抽取

最後更新於 ,距今已過 630 天

部分內容可能已過時