AWS - EBS Snapshot Dump

HackTricksをサポートする

スナップショットをローカルで確認する

# Install dependencies
pip install 'dsnap[cli]'
brew install vagrant
brew install virtualbox

# Get snapshot from image
mkdir snap_wordir; cd snap_workdir
dsnap init
## Download a snapshot of the volume of that instance
## If no snapshot existed it will try to create one
dsnap get <instance-id>
dsnap --profile default --region eu-west-1 get i-0d706e33814c1ef9a
## Other way to get a snapshot
dsnap list #List snapshots
dsnap get snap-0dbb0347f47e38b96 #Download snapshot directly

# Run with vagrant
IMAGE="<download_file>.img" vagrant up #Run image with vagrant+virtuabox
IMAGE="<download_file>.img" vagrant ssh #Access the VM
vagrant destroy #To destoy

# Run with docker
git clone https://github.com/RhinoSecurityLabs/dsnap.git
cd dsnap
make docker/build
IMAGE="<download_file>.img" make docker/run #With the snapshot downloaded

注意 dsnap は公開スナップショットをダウンロードすることを許可しません。これを回避するために、スナップショットをあなたの個人アカウントにコピーし、それをダウンロードすることができます:

# Copy the snapshot
aws ec2 copy-snapshot --source-region us-east-2 --source-snapshot-id snap-09cf5d9801f231c57 --destination-region us-east-2 --description "copy of snap-09cf5d9801f231c57"

# View the snapshot info
aws ec2 describe-snapshots --owner-ids self --region us-east-2

# Download the snapshot. The ID is the copy from your account
dsnap --region us-east-2 get snap-027da41be451109da

# Delete the snapshot after downloading
aws ec2 delete-snapshot --snapshot-id snap-027da41be451109da --region us-east-2

この技術に関する詳細は、https://rhinosecuritylabs.com/aws/exploring-aws-ebs-snapshots/の元の研究を確認してください。

Pacuを使用して、モジュールebs__download_snapshotsでこれを行うことができます。

AWSでのスナップショットの確認

aws ec2 create-volume --availability-zone us-west-2a --region us-west-2  --snapshot-id snap-0b49342abd1bdcb89

あなたの管理下にあるEC2 VMにマウントする(バックアップのコピーと同じリージョンにある必要があります):

ステップ1:EC2 –> ボリュームに移動して、好みのサイズとタイプの新しいボリュームを作成します。

このアクションを実行するには、次のコマンドに従ってください:

  • EC2インスタンスにアタッチするEBSボリュームを作成します。

  • EBSボリュームとインスタンスが同じゾーンにあることを確認します。

ステップ2:作成したボリュームを右クリックして「ボリュームをアタッチ」オプションを選択します。

ステップ3:インスタンステキストボックスからインスタンスを選択します。

このアクションを実行するには、次のコマンドを使用します:

  • EBSボリュームをアタッチします。

ステップ4:EC2インスタンスにログインし、コマンドlsblkを使用して利用可能なディスクをリストします。

ステップ5:コマンドsudo file -s /dev/xvdfを使用して、ボリュームにデータがあるかどうかを確認します。

上記のコマンドの出力が「/dev/xvdf: data」と表示される場合、ボリュームは空です。

ステップ6:コマンドsudo mkfs -t ext4 /dev/xvdfを使用して、ボリュームをext4ファイルシステムにフォーマットします。代わりに、コマンドsudo mkfs -t xfs /dev/xvdfを使用してxfsフォーマットを使用することもできます。ext4またはxfsのいずれかを使用する必要があることに注意してください。

ステップ7:新しいext4ボリュームをマウントするための任意のディレクトリを作成します。たとえば、「newvolume」という名前を使用できます。

このアクションを実行するには、コマンドsudo mkdir /newvolumeを使用します。

ステップ8:コマンドsudo mount /dev/xvdf /newvolume/を使用して、ボリュームを「newvolume」ディレクトリにマウントします。

ステップ9:「newvolume」ディレクトリに移動し、ボリュームマウントを検証するためにディスクスペースを確認します。

このアクションを実行するには、次のコマンドを使用します:

  • ディレクトリを/newvolumeに変更します。

  • コマンドdf -h .を使用してディスクスペースを確認します。このコマンドの出力は、「newvolume」ディレクトリの空きスペースを表示する必要があります。

これをPacuを使用して、モジュールebs__explore_snapshotsで行うことができます。

AWSでのスナップショットの確認(cliを使用)

aws ec2 create-volume --availability-zone us-west-2a --region us-west-2 --snapshot-id <snap-0b49342abd1bdcb89>

# Attach new volume to instance
aws ec2 attach-volume --device /dev/sdh --instance-id <INSTANCE-ID> --volume-id <VOLUME-ID>

# mount the snapshot from within the VM

sudo file -s /dev/sdh
/dev/sdh: symbolic link to `xvdh'

sudo file -s /dev/xvdh
/dev/xvdh: x86 boot sector; partition 1: ID=0xee, starthead 0, startsector 1, 16777215 sectors, extended partition table (last)\011, code offset 0x63

lsblk /dev/xvdh
NAME     MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvdh     202:112  0    8G  0 disk
├─xvdh1  202:113  0  7.9G  0 part
├─xvdh14 202:126  0    4M  0 part
└─xvdh15 202:127  0  106M  0 part

sudo mount /dev/xvdh1 /mnt

ls /mnt

シャドウコピー

EC2:CreateSnapshot 権限を持つ任意のAWSユーザーは、ドメインコントローラーのスナップショットを作成し、それを自分が制御するインスタンスにマウントして、NTDS.ditおよびSYSTEMレジストリハイブファイルをエクスポートすることによって、すべてのドメインユーザーのハッシュを盗むことができます。

このツールを使用して攻撃を自動化できます: https://github.com/Static-Flow/CloudCopy またはスナップショットを作成した後に以前の技術の1つを使用することもできます。

参考文献

HackTricksをサポートする

Last updated