AWS - EBS Snapshot Dump

Support 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

Note that dsnap will not allow you to download public snapshots. To circumvent this, you can make a copy of the snapshot in your personal account, and download that:

# 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 –> Volumesに移動し、希望のサイズとタイプの新しいボリュームを作成します。

このアクションを実行するには、以下のコマンドに従います:

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

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

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

ステップ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

Shadow Copy

EC2:CreateSnapshot 権限を持つ任意のAWSユーザーは、ドメインコントローラーのスナップショットを作成し、それを自分が管理するインスタンスにマウントし、NTDS.ditとSYSTEMレジストリハイブファイルをエクスポートすることで、すべてのドメインユーザーのハッシュを盗むことができます。この攻撃を自動化するためのツールを使用できます: https://github.com/Static-Flow/CloudCopy または、スナップショットを作成した後に以前の技術のいずれかを使用することができます。

References

HackTricksをサポートする

Last updated