1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

bandit一日目 wslとssh接続

Last updated at Posted at 2025-10-10

初めに

ctfの勉強のためbanditを使ったlinuxコマンドの学習を始めた。本記事はその内容の備忘録である。

wsl

以前wslを用いてlinux環境をつくったが正しく動作しなくなっていたので一度アンインストールして再度入れなおした。

その時参考にしたサイト
wslインストール

検索バーからubuntuを起動して実行

ssh接続方法

ssh接続のコマンドは

ssh username@ipアドレス or hostname

portを指定する場合は

ssh username@ipアドレス or hostname -p port番号

コマンドを実行するとパスワードの入力を求められる。

level 0の場合

ssh bandit0@bandit.labs.overthewire.org -p 2220
password: bandit0

level 0 → level 1

問題文

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.

内容

homedirectoryにあるreadmifileにpasswordがある。それを使ってbandit1にssh接続してね。

使ったコマンド

  • ls ディレクトリの一覧を表示
  • pwm  自分のいるディレクトリを調べる
  • cd  ディレクトリを移動
  • cat ディレクトリを開く

password : ZjLjTmM6FvvyRnrb2rfNWOZOTa6ip5If

コピペの方法

cmd
コピー : ドラッグして範囲選択
ペースト : 右クリック
ubuntu
コピー : ctrl + shift + c
ペースト : ctrl + shift + v

level1 → level 2

問題

homeにある-ファイルにpasswordがある。

課題点

lsを実行したら - があったのでcatをしたがうまくいかない。
このファイル名だとdev/~みたいなファイルと誤認されるらしい。

解決策

cat -

これだとうまくいかないので./などを使って

cat /home/bandit1/-

でうまくいく。
正しくできると

263JGJPfgU6LtdEvgfWU1XP5yac29mFx

が得られる。

https://stackoverflow.com/questions/42187323/how-to-open-a-dashed-filename-using-terminal

level 2 → level 3

課題

  • ファイル名にスペースがある
  • ファイル名の先頭にハイフンがあり、オプションと誤認される

解決策

スペースがある
  • ファイル名を ダブルクォーテーション("") で囲む
  • スペースにバックスラッシュを入れる
    cat "spaces in this filename"    ←ターミナル上はこっちが一般的
    cat spaces\ in\ this\ filename
先頭にハイフンがある
  • ./を付けてカレントディレクトリを明示する
cat ./"--spaces in this filename--"

正しくできた場合

MNk8KNH3Usiio41PRUEoDFPqfxLPlSmx

が得られる

level 3 → level 4

課題

隠れているファイルを見つける

解決策

lsコマンドのオプションを使う

ls -a ファイル名

隠しファイルなどすべてのファイルを表示

password

2WmrDFRmJIq3IPxneAaMGhap0pFhF3NJ

level 4 → level 5

課題

  • 隠しファイル
  • 複数ファイル

解決策

複数ファイル

一つ一つ手動でやってもいい
pythonで自動化してみる

4oQYVPkxZOOEOO5pTW81FB8j8lxXGUQw

pythonで複数ファイルにcatを実行する

1.ubuntuでpythonを実行できるようにする

https://prog-8.com/docs/python-env-win

2.pythonのコード

ターミナル上でコマンドを実行するには subprocess を使う

import subprocess
subprocess.run(['コマンド','オプション'])

とりあえず一つのファイルをcatできるようにする

subprocess.run(['cat','./-file00'])

今回はファイル名が「-file00」で最後の数字が違うファイルが複数あるので数字を変数にして置き換わるようにする

for num in range(10)
    subprocess.run(['cat','./-file0{num}'])

コード自体はいいと思うけどssh先にコピーできず断念
コマンドでファイルの行数見てチェックできるらしい

level 5 → level 6

課題

  • 人が読める
  • 1033byet
  • 実行不可能
    この条件に合うものを探す

解法

find -size 1033c

findは検索ができる
-size 1033cでサイズを指定(c= バイト)

password

HWasnPhtq9AVKe0dmk45nxy20cvUa6EG

level 6→ level 7

課題

条件に合うファイルを見つける

  • 所有者がbandit7
  • 所有グループがbandit6
  • サイズが33byet

解決策

find / -user bandit7 -group bandit6 -size 33c

これを実行するとエラーが大量に…
この中にあるはずなのでエラーを取り除く必要がある
さっきのコードに 2>/dev/null を付ける

find / -user bandit7 -group bandit6 -size 33c 2>/dev/null
2>
エラーを「>」の後に記述した場所にリダイレクトできる 
/dev/null
この中身はシステムが消去する

password

morbNTDkSW6jIlUc0ymOdMaLnOlFVAaj
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?