はじめに
本記事は「HackTheBox:Three」のwriteupです。
問題
リバースシェルに関する問題です。
回答
ポートスキャンします。
結果ssh(tcp/22)
、http(tcp/80)
が公開されていることがわかりました。
┌──(kali㉿kali)-[~]
└─$ nmap -sV -p- --min-rate 5000 10.129.50.135
Starting Nmap 7.93 ( https://nmap.org ) at 2023-04-30 14:53 JST
Nmap scan report for 10.129.50.135
Host is up (0.19s latency).
Not shown: 65456 filtered tcp ports (no-response), 77 closed tcp ports (conn-refused)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0)
80/tcp open http Apache httpd 2.4.29 ((Ubuntu))
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 35.47 seconds
ブラウザからhttpでアクセスするとサイトが表示されました。
サイトを探索するとthetoppers.htb
というドメインが見つかります。
/etc/hosts
にこのドメインとIPアドレスの紐付けを追記します。
以下余談
ffufを使用し、サブドメインを探します。
例えば以下のコマンドを実行するとwordlistに記載された文字列がFUZZ
部分に置換されて、リクエストをしてくれます。
ffuf -w /usr/share/wordlists/wfuzz/general/common.txt -u http://10.129.50.135 -H "Host: FUZZ.thetoppers.htb"
メタですが解答欄のプレースホルダーは**.thetoppers.htb
で、サードレベルドメインは2文字です。
wordlistは2文字の総当たりができるものを作成、使用した方がよさそうです。
kaliにはcrunch
コマンドというパスワードリストを生成するコマンドがあります。
例えば以下のコマンドを実行すると1字のアルファベットすべてから3字のアルファベットすべてのパターンで生成します。
crunch 1 3
今回は2文字の英数字でwordlistを作成しました。
┌──(kali㉿kali)-[~]
└─$ crunch 2 2 0123456789abcdefghijklmnopqrstuvwxyz -o third_domain.txt
Crunch will now generate the following amount of data: 3888 bytes
0 MB
0 GB
0 TB
0 PB
Crunch will now generate the following number of lines: 1296
crunch: 100% completed generating output
色々出力されましたが、目ぼしい情報をに見つけることができませんでした。
┌──(kali㉿kali)-[~]
└─$ ffuf -w third_domain.txt -u http://10.129.50.135 -H "Host: FUZZ.thetoppers.htb"
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v2.0.0-dev
________________________________________________
:: Method : GET
:: URL : http://10.129.50.135
:: Wordlist : FUZZ: /home/kali/third_domain.txt
:: Header : Host: FUZZ.thetoppers.htb
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 40
:: Matcher : Response status: 200,204,301,302,307,401,403,405,500
________________________________________________
[Status: 200, Size: 11952, Words: 1832, Lines: 235, Duration: 431ms]
* FUZZ: 0o
.
.
.
余談終わり
gobusterにはvhostを探索する機能があり、こちらを使用してみます。指定するwordlistはこちらからダウンロードして使用しました。
--append-domain
をつけないと-u
に指定したURLの末尾?に指定した形で検索してしまうため、目的のものを見つけることができませんでした。
結果s3.thetoppers.htb
というそれらしいサブドメインを見つけることができました。
┌──(kali㉿kali)-[/usr/share/seclists/discovery/dns]
└─$ gobuster vhost -w /usr/share/seclists/discovery/dns/subdomains-top1million-5000.txt -u http://thetoppers.htb --append-domain
===============================================================
Gobuster v3.5
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://thetoppers.htb
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /usr/share/seclists/discovery/dns/subdomains-top1million-5000.txt
[+] User Agent: gobuster/3.5
[+] Timeout: 10s
[+] Append Domain: true
===============================================================
2023/04/30 17:09:24 Starting gobuster in VHOST enumeration mode
===============================================================
Found: s3.thetoppers.htb Status: 404 [Size: 21]
Found: gc._msdcs.thetoppers.htb Status: 400 [Size: 306]
Progress: 4978 / 4990 (99.76%)
===============================================================
2023/04/30 17:10:59 Finished
===============================================================
/etc/hosts
にs3.thetoppers.htb
とIPアドレスの紐付けを追記します。
試しにブラウザでs3.thetoppers.htb
にアクセスするとJson形式のレスポンスが表示されました。
S3へのアクセスにはAWS CLIを使用します。
┌──(kali㉿kali)-[/usr/share/seclists/discovery/dns]
└─$ aws --version
aws-cli/2.9.19 Python/3.11.2 Linux/6.1.0-kali5-amd64 source/x86_64.kali.2023 prompt/off
aws configure
でアクセスキーなどを入力します。値は適当で良いです。
┌──(kali㉿kali)-[/usr/share/seclists/discovery/dns]
└─$ aws configure
AWS Access Key ID [None]: hoge
AWS Secret Access Key [None]: hoge
Default region name [None]: hoge
Default output format [None]: hoge
aws s3 ls
でS3バケットの一覧を取得できます。
また、--endpoint-url
にリクエストを送信するURLを指定します。
結果thetoppers.htb
というS3バケットがあることがわかりました。
┌──(kali㉿kali)-[/usr/share/seclists/discovery/dns]
└─$ aws --endpoint-url=http://s3.thetoppers.htb s3 ls
2023-04-30 14:54:37 thetoppers.htb
次にバケットに何が保存されているか確認します。
aws --endpoint-url=<エンドポイントURL> s3 ls s3://<S3バケット名>
でS3バケット直下に保存されているオブジェクトの一覧を取得できます。
┌──(kali㉿kali)-[/usr/share/seclists/discovery/dns]
└─$ aws --endpoint-url=http://s3.thetoppers.htb s3 ls s3://thetoppers.htb
PRE images/
2023-04-30 14:54:37 0 .htaccess
2023-04-30 14:54:37 11952 index.php
ここから先はWalkthroughを見ながらなんとかやりました。
やっていることはリバースシェルです。
以下の記事を読むことで何をしているか理解できました。
nc
コマンドに指定しているオプションについては以下を参照。
php-reverse-shell.php
も使えそう