
Photo by
yrs_12_4
OverTheWire:Behemoth3
お天気のいい日曜日だけど、コロナは流行っているし、このところ毎日暑くて出歩く気がしない。。
ということで、今週も Over The Wireの問題で遊んでみよう。
今回はレベル3 ( Behemoth3 ) である。
前回の記事で取得したパスワードで接続。
ssh behemoth3@behemoth.labs.overthewire.org -p 2221
今回はレベル 3 なので、問題となるプログラムは behemoth3 。
behemoth3@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
とりあえず実行してみる。
behemoth3@behemoth:~$ /behemoth/behemoth3
Identify yourself: abc
Welcome, abc
aaaand goodbye again.
なにか入力文字列をチェックしているのだろうか?
トレースして調べてみる。
behemoth3@behemoth:~$ ltrace /behemoth/behemoth3
__libc_start_main(0x804847b, 1, 0xffffd724, 0x80484e0 <unfinished ...>
printf("Identify yourself: ") = 19
fgets(Identify yourself: abc
"abc\n", 200, 0xf7fc55a0) = 0xffffd5c0
printf("Welcome, ") = 9
printf("abc\n"Welcome, abc
) = 4
puts("\naaaand goodbye again."
aaaand goodbye again.
) = 23
+++ exited (status 0) +++
入力した文字列 "abc" をそのまま printf に渡していることが判った。
つまり 「書式文字列攻撃」(詳細はこちらを参照)が可能、ということだ。
確かめてみよう。名前を入力するときに %p を入力してみる。
ここから先は
4,396字
/
2画像
¥ 500

この記事が気に入ったらチップで応援してみませんか?