Tech with Tyler
LinkedInGitHubYouTube
  • 👋Welcome!
    • whoami
    • !!! Disclaimer !!!
  • 🎓Academy
    • AWS Security Cookbook by Tyler
      • AWS Control Tower
        • Lab: Deploying AWS Control Tower via Terraform
      • AWS CloudTrail
      • AWS GuardDuty
        • Lab: Deploying AWS GuardDuty via Terraform
        • Lab: Logging GuardDuty Findings to S3
        • Lab: Adversary Simulation Detection with Stratus Red Team and GuardDuty
      • AWS Organizations
        • Lab: Deploying AWS Organizations via Terraform
      • AWS Root Account Management
        • Lab: Deploying AWS Root Account Management via Terraform
      • AWS Service Control Policies (SCPs)
        • Lab: Deploying AWS Service Control Policies (SCPs) via Terraform
      • TBD - Coming Soon!
        • [TBD] AWS Account Factory
        • [TBD] AWS Identity Center
    • My content on Cybr
      • Course - Terraform on AWS: From Zero to Cloud Infrastructure
      • Lab - Create Static AWS S3 Website with Terraform
      • Lab - Secure EC2 Access with SSM Session Manager and KMS
      • Lab - Encrypt and Decrypt Data with KMS and Data Encryption Keys
    • My content on PwnedLabs
      • Cyber Range - Electra
      • Lab - Abusing Identity Providers in AWS
      • Lab - Prowler and AWS Security Hub
      • Blog - Abusing Identity Providers in AWS
      • Blog - Building Security Guardrails with AWS Resource Control Policies
      • Blog - Defending Against the whoAMI Attack with AWS Declarative Policies
    • My content on YouTube
      • AWS Security Engineering
      • Linux in 60 Seconds!
  • ☁️Cloud Security
    • AWS Attacks and Techniques
      • Enumerate AWS Account IDs
      • Enumerate AWS IAM Users
      • Enumerate (Unauthenticated) IAM Users and Roles
      • Enumerate AWS Public Resources
      • Enumerate Secrets in AWS
      • Generate AWS Console Session
      • Generate IAM Access Keys from CloudShell
      • Password Spraying AWS IAM Users
      • Subdomain Takeovers
    • AWS Privilege Escalation
      • Identity Access Management (IAM)
      • IAM Trust Policies
      • Key Management Service (KMS)
      • Lightsail
      • OpenID Connect (OIDC)
      • S3
      • Secrets Manager
      • Security Token Service (STS)
    • AWS General Info
      • Amazon Bedrock
      • EC2
      • KMS
      • S3
      • SNS Topic
    • AWS CLI Cheat Sheet
    • Capture the Flags (CTFs)
      • Flaws.Cloud
        • Level 1
        • Level 2
        • Level 3
        • Level 4
        • Level 5
        • Level 6
      • PwnedLabs
        • Escalate Privileges by IAM Policy Rollback
        • Exploiting Weak S3 Bucket Policies
        • Leveraging S3 Bucket Versioning
        • S3 Enumeration Basics
        • Pillage Exposed RDS Instances
        • EC2 SSRF Attack
        • Hunt for Secrets in Git Repos
      • Cybr
        • Challenge - Secrets Unleashed
    • Tools
      • Tooling Index
      • dsnap
      • Pacu
      • s3-account-search
      • GoAWSConsoleSpray
      • aws_consoler
      • cloudenum
  • 📦Containers & Orchestration
    • Kubernetes
  • 👨‍💻Coding & CLI Tooling
    • CLI Tools
      • AWS CLI
      • Git
      • GitHub Copilot (CLI)
      • Homebrew
      • jq
      • ngrok
      • ssh
    • Coding and Scripting
      • Bash
      • Python
    • Terminal Customization
  • ⚙️DevSecOps
    • CI/CD
      • GitLab
    • Hashicorp Terraform
    • Hashicorp Vault
    • IAC Scanning
      • tfsec
    • Secrets Scanning
      • Trufflehog
  • 🎁Miscellaneous
    • Jenkins
  • 💻Operating Systems
    • Linux
      • APT Package Manager
      • CLI Tools Cheat Sheet
      • Man Pages
      • Services
      • Users and Groups
  • 🏗️Projects
    • Active Directory Homelab Automation
    • AWS Cloud Resume Challenge
    • Proxmox Homelab as Code
  • 📌Other
    • Useful Resources
Powered by GitBook
On this page
  • Install
  • Enumerating Snapshots
  • Downloading Snapshots
  • With Access to the AWS Account
  • Without Access to the AWS Account
  • Mounting the Snapshot for Local Inspection
  • Running the Snapshot in a Local Docker Container
  • Resources

Was this helpful?

  1. Cloud Security
  2. Tools

dsnap

A tool for enumerating and downloading EBS snapshots

Install

# with apt package manager
sudo apt install python3-dsnap

# with pipx
pipx install dnsap 

Enumerating Snapshots

You need the AWS action ebs:ListSnapshotBlocks

# list all snapshots available in an account you have valid credentials for
dsnap --profile <profileName> --region <awsRegion> list

           Id          |   Owneer ID   | Description
snap-11111111111111111   123456789012    mysnapshot

Downloading Snapshots

You need the AWS action ebs:GetSnapshotBlock

With Access to the AWS Account

  • So long as the snapshot exists in an AWS account you have access to, you can download it

dsnap --profile <profileName> --region <awsRegion> get snap-11111111111111111
Selected snapshot with id snap-11111111111111111

Output Path: /home/parallels/snap-11111111111111111.img
Truncating file to 8.0 GB

Without Access to the AWS Account

  • If you don't have credentials for an AWS account where the public snapshot is, you can't download it

dsnap --profile <profileName> --region <awsRegion> get snap-22222222222222222

Selected snapshot with id snap-22222222222222222
[snip]
botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the ListSnapshotBlocks operation: Public snapshots are not supported
  • To resolve this, first copy the snapshot from the target account to your account

aws --profile <profileName> --region <awsRegion> ec2 copy-snapshot --source-snapshot-id snap-22222222222222222 --source-region <awsRegion> --destination-region <awsRegion> --description "Copy of ABC's public snapshot"

{
    "SnapshotId": "snap-11111111111111111"
}
  • Then you can download it locally with dsnap

  • Alternatively, you can create an ec2 in your account and use this snapshot which may be beneficial depending on the snapshot size / your download speeds

dsnap --profile <profileName> --region <awsRegion> get snap-11111111111111111
Selected snapshot with id snap-11111111111111111

Output Path: /home/parallels/snap-11111111111111111.img
Truncating file to 8.0 GB

Mounting the Snapshot for Local Inspection

  • If you decide to download the snapshot locally (rather than run it on an EC2) then we need to mount it

Mounting the snapshot is like attaching a USB drive to your computer. You have access to all the files on the drive but it's not running the operating system.

parted snap-11111111111111111.img unit s print

# output
WARNING: You are not superuser.  Watch out for permissions.
Model:  (file)
Disk /home/parallels/snap-11111111111111111.img: 16777216s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start    End        Size       File system  Name  Flags
14      2048s    10239s     8192s                         bios_grub
15      10240s   227327s    217088s    fat32              boot, esp
 1      227328s  16777182s  16549855s  ext4
  • We take the start point of the ext4 partition (227328) and multiply it by the sector size (512 bytes), which gives us an offset value of 116391936. This offset tells the operating system where to begin reading the partition within the disk image. Without specifying the correct offset, the operating system might attempt to read from the wrong location—such as the partition table or unallocated space—causing errors or preventing access to the file system.

# make a directory to mount the snapshot
sudo mkdir /mnt/snapshot

# mount the snapshot
sudo mount -o loop,offset=116391936 snap-11111111111111111.img /mnt/snapshot
  • Now we can access the snapshot

ls -alh /mnt/snapshot

# output
total 88K
drwxr-xr-x 19 root root 4.0K Dec 21  2023 .
drwxr-xr-x  3 root root 4.0K Jan  4 13:06 ..
lrwxrwxrwx  1 root root    7 Dec  6  2023 bin -> usr/bin
drwxr-xr-x  4 root root 4.0K Dec  6  2023 boot
drwxr-xr-x  4 root root 4.0K Dec  6  2023 dev
drwxr-xr-x 93 root root 4.0K Dec 21  2023 etc
drwxr-xr-x  3 root root 4.0K Dec 21  2023 home
lrwxrwxrwx  1 root root    7 Dec  6  2023 lib -> usr/lib
[snip]
  • You'll notice the files and directories are all owned by root since we had to use sudo to mount this

  • We have a few options, the easiest being to switch to the root user

ls root/    

#output
ls: cannot open directory 'root': Permission denied

sudo su
ls root/ 

# output 
root_file1 root_file2
  • Or you can change ownership of the mount directory to our current user (parallels for me)

sudo chown -R $USER:$USER /mnt/snapshot
ls -alh /mnt/snapshot

# output
total 88K
drwxr-xr-x 19 parallels parallels 4.0K Dec 21  2023 .
drwxr-xr-x  3 root      root      4.0K Jan  4 13:06 ..
lrwxrwxrwx  1 parallels parallels    7 Dec  6  2023 bin -> usr/bin
drwxr-xr-x  4 parallels parallels 4.0K Dec  6  2023 boot
drwxr-xr-x  4 parallels parallels 4.0K Dec  6  2023 dev
[snip]
  • Change it back to root if you want

sudo chown -R root:root /mnt/snapshot
ls -alh /mnt/snapshot

# output
total 88K
drwxr-xr-x 19 root root 4.0K Dec 21  2023 .
drwxr-xr-x  3 root root 4.0K Jan  4 13:06 ..
lrwxrwxrwx  1 root root    7 Dec  6  2023 bin -> usr/bin
drwxr-xr-x  4 root root 4.0K Dec  6  2023 boot
drwxr-xr-x  4 root root 4.0K Dec  6  2023 dev

Running the Snapshot in a Local Docker Container

  • Dsnap can spin up a local docker container to run the snapshot from but I haven't had luck getting this to work on an Apple Silicon mac (though I haven't tried for over a year)

Resources

PreviousTooling IndexNextPacu

Last updated 5 months ago

Was this helpful?

☁️
https://github.com/RhinoSecurityLabs/dsnap?tab=readme-ov-file#mounting-with-docker
https://github.com/RhinoSecurityLabs/dsnap