見出し画像

OverTheWire:Behemoth6

Behemoth もこの問題を入れて、残り2問になる。今回はレベル 6 。
レベル7にログインするためのパスワードを入手するのがゴールである。
さあ、始めよう。

前回の記事で入手したパスワードを使用して問題のサーバーに接続する。
ssh behemoth6@behemoth.labs.overthewire.org -p 2221

今回、解析するプログラムは  behemoth6  と behemoth6_reader の2つ。

behemoth6@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

とりあえず実行してみる。

behemoth6@behemoth:~$ /behemoth/behemoth6
Incorrect output.
behemoth6@behemoth:~$ ltrace /behemoth/behemoth6
__libc_start_main(0x80485db, 1, 0xffffd764, 0x80486d0 <unfinished ...>
popen("/behemoth/behemoth6_reader", "r")        = 0x804b008
malloc(10)                                      = 0x804b0b8
fread(0x804b0b8, 10, 1, 0x804b008)              = 1
pclose(0x804b008 <no return ...>
--- SIGCHLD (Child exited) ---
<... pclose resumed> )                          = 0
strcmp("Couldn't o", "HelloKitty")              = -1
puts("Incorrect output."Incorrect output.
)                       = 18
+++ exited (status 0) +++

トレースの結果から判るのは、以下の2点。

<トレース結果から判明した動作>
1)  behemoth6 から behemoth6_reader が起動されている。
2)  behemoth6_reader の実行結果が "HelloKitty" かどうかチェックしている

behemoth6_reader の方はどんな動作をするプログラムだろう?
とりあえず、実行してみる。

behemoth6@behemoth:~$ ltrace /behemoth/behemoth6_reader 
__libc_start_main(0x80485ab, 1, 0xffffd754, 0x80486b0 <unfinished ...>
fopen("shellcode.txt", "r")                     = 0
puts("Couldn't open shellcode.txt!"Couldn't open shellcode.txt!
)            = 29
+++ exited (status 0) +++

shellcode.txt というファイルを読み込もうとしてエラーになった。
behemoth6_reader の動作を解析するため、逆アセンブルして調べてみる。

<逆アセンブル>
objdump -d -M intel /behemoth/behemoth6_reader

80485ab <main>:
80485ab:       8d 4c 24 04             lea    ecx,[esp+0x4]
80485af:       83 e4 f0                and    esp,0xfffffff0
80485b2:       ff 71 fc                push   DWORD PTR [ecx-0x4]
80485b5:       55                      push   ebp
80485b6:       89 e5                   mov    ebp,esp
80485b8:       51                      push   ecx
80485b9:       83 ec 24                sub    esp,0x24
80485bc:       83 ec 08                sub    esp,0x8
80485bf:       68 30 87 04 08          push   0x8048730
80485c4:       68 32 87 04 08          push   0x8048732
80485c9:       e8 c2 fe ff ff          call   8048490 <fopen@plt>
80485ce:       83 c4 10                add    esp,0x10

#---------------( 中略 )--------------------------

804868a:       8b 45 f4                mov    eax,DWORD PTR [ebp-0xc]
804868d:       3b 45 ec                cmp    eax,DWORD PTR [ebp-0x14]
8048690:       7c cb                   jl     804865d <main+0xb2>
8048692:       8b 45 e8                mov    eax,DWORD PTR [ebp-0x18]
8048695:       89 45 e4                mov    DWORD PTR [ebp-0x1c],eax
8048698:       8b 45 e4                mov    eax,DWORD PTR [ebp-0x1c]
804869b:       ff d0                   call   eax
804869d:       b8 00 00 00 00          mov    eax,0x0
80486a2:       8b 4d fc                mov    ecx,DWORD PTR [ebp-0x4]
80486a5:       c9                      leave  

アセンブラのコードを眺めてみて、大体の動作が判った

ここから先は

3,951字

¥ 500

この記事が気に入ったらサポートをしてみませんか?