
OverTheWire:Behemoth0
Over The Wire は 常設のCTF。問題を解きすすむうちに、Linux の操作やコンピュータセキュリティの知識が身につくように工夫されている。
アカウント登録等も一切不要で誰でも無料で利用できるので、このコロナ禍、ステイホームの暇つぶしにはピッタリである。
サイトには幾つかのゲームが置いてあり、難易度順に並んでいる。
筆者はこれまで Bandit 、Leviathan, Natas, Narnia と順にクリアしてきたので、今回は Behemoth をやってみることにする。
遊び方は簡単。
まずは behemoth のページに行き、ssh の接続情報(画面左上)と、接続用のID, パスワードを確認する。
上記で確認した情報をもとに、自分のPCから ssh で接続する。
接続用のコマンドは以下の通り。
ssh behemoth0@behemoth.labs.overthewire.org -p 2221
$ ssh behemoth0@behemoth.labs.overthewire.org -p 2221
This is a OverTheWire game server. More information on http://www.overthewire.org/wargames
behemoth0@behemoth.labs.overthewire.org's password:
Linux behemoth 4.18.12 x86_64 GNU/Linux
,----.. ,----, .---.
/ / \ ,/ .`| /. ./|
/ . : ,` .' : .--'. ' ;
. / ;. \ ; ; / /__./ \ : |
. ; / ` ; .'___,/ ,' .--'. ' \' .
; | ; \ ; | | : | /___/ \ | ' '
| : | ; | ' ; |.'; ; ; \ \; :
. | ' ' ' : `----' | | \ ; ` |
' ; \; / | ' : ; . \ .\ ;
\ \ ', / | | ' \ \ ' \ |
; : / ' : | : ' |--"
\ \ .' ; |.' \ \ ;
www. `---` ver '---' he '---" ire.org
Welcome to OverTheWire!
If you find any problems, please report them to Steven or morla on
irc.overthewire.org.
--[ Playing the games ]--
This machine might hold several wargames.
If you are playing "somegame", then:
* USERNAMES are somegame0, somegame1, ...
* Most LEVELS are stored in /somegame/.
* PASSWORDS for each level are stored in /etc/somegame_pass/.
Write-access to homedirectories is disabled. It is advised to create a
working directory with a hard-to-guess name in /tmp/. You can use the
command "mktemp -d" in order to generate a random and hard to guess
directory in /tmp/. Read-access to both /tmp/ and /proc/ is disabled
so that users can not snoop on eachother. Files and directories with
easily guessable or short names will be periodically deleted!
Please play nice:
* don't leave orphan processes running
* don't leave exploit-files laying around
* don't annoy other players
* don't post passwords or spoilers
* again, DONT POST SPOILERS!
This includes writeups of your solution on your blog or website!
--[ Tips ]--
This machine has a 64bit processor and many security-features enabled
by default, although ASLR has been switched off. The following
compiler flags might be interesting:
-m32 compile for 32bit
-fno-stack-protector disable ProPolice
-Wl,-z,norelro disable relro
In addition, the execstack tool can be used to flag the stack as
executable on ELF binaries.
Finally, network-access is limited for most levels by a local
firewall.
--[ Tools ]--
For your convenience we have installed a few usefull tools which you can find
in the following locations:
* pwndbg (https://github.com/pwndbg/pwndbg) in /usr/local/pwndbg/
* peda (https://github.com/longld/peda.git) in /usr/local/peda/
* gdbinit (https://github.com/gdbinit/Gdbinit) in /usr/local/gdbinit/
* pwntools (https://github.com/Gallopsled/pwntools)
* radare2 (http://www.radare.org/)
* checksec.sh (http://www.trapkit.de/tools/checksec.html) in /usr/local/bin/checksec.sh
--[ More information ]--
For more information regarding individual wargames, visit
http://www.overthewire.org/wargames/
For support, questions or comments, contact us through IRC on
irc.overthewire.org #wargames.
Enjoy your stay!
behemoth0@behemoth:~$
behemoth は level 0 〜 level 7 の全 8レベル。
/behemoth/ に置いてあるプログラムを攻略してシェル(/bin/sh) を起動することで、次レベルへの接続パスワードが判るようになっている。
behemoth0@behemoth:~$ ls -l /behemoth/
total 72
-r-sr-x--- 1 behemoth1 behemoth0 5900 Aug 26 2019 behemoth0
-r-sr-x--- 1 behemoth2 behemoth1 5036 Aug 26 2019 behemoth1
-r-sr-x--- 1 behemoth3 behemoth2 7536 Aug 26 2019 behemoth2
-r-sr-x--- 1 behemoth4 behemoth3 5180 Aug 26 2019 behemoth3
-r-sr-x--- 1 behemoth5 behemoth4 7488 Aug 26 2019 behemoth4
-r-sr-x--- 1 behemoth6 behemoth5 7828 Aug 26 2019 behemoth5
-r-sr-x--- 1 behemoth7 behemoth6 7564 Aug 26 2019 behemoth6
-r-xr-x--- 1 behemoth7 behemoth6 7528 Aug 26 2019 behemoth6_reader
-r-sr-x--- 1 behemoth8 behemoth7 5676 Aug 26 2019 behemoth7
behemoth0@behemoth:~$
とりあえず、やってみよう。
問題のソースコードが提供されていない分、前のゲーム(Narnia)よりも難易度が上がっている。
まずは問題の /behemoth0 がどんなプログラムなのか調べてみよう。
とりあえず実行してみる。
behemoth0@behemoth:~$ /behemoth/behemoth0
Password: abcde
Access denied..
パスワード入力をチェックするだけのようだ。
パスワードがハードコーディングされているかもしれないので、トレースしてみる。
behemoth0@behemoth:~$ ltrace /behemoth/behemoth0
__libc_start_main(0x80485b1, 1, 0xffffd774, 0x8048680 <unfinished ...>
printf("Password: ") = 10
__isoc99_scanf(0x804874c, 0xffffd67b, 0xf7fc5000, 13Password: abcde
) = 1
strlen("OK^GSYBEX^Y") = 11
strcmp("abcde", "eatmyshorts") = -1
puts("Access denied.."Access denied..
) = 16
+++ exited (status 0) +++
予想通り、strcmp でハードコードしたパスワードと比較をしているだけのようだ。再実行して正しいパスワードを入力するとシェルが起動した。
behemoth0@behemoth:~$ /behemoth/behemoth0
Password: eatmyshorts
Access granted..
$ id
uid=13001(behemoth1) gid=13000(behemoth0) groups=13000(behemoth0)
$
最初の問題はまあ、こんなところか。
とりあえずパスワードを見てみよう。
$ cat /etc/behemoth_pass/behemoth1
aesebootiv
$ exit
behemoth0@behemoth:~$
これで、次のレベルにログインできるようになった。
今回はこれでおしまい!