# Attacking AWS RDS

### What is AWS RDS ?

AWS RDS stands for Amazon Web Services Relational Database Service. It is a managed database service offered by Amazon that makes it easier to set up, operate, and scale a relational database in the cloud. With AWS RDS, you can choose from several popular relational database engines, such as MySQL, PostgreSQL, SQL Server, MariaDB, and Oracle, and Amazon takes care of the underlying infrastructure, including database patching, backups, and maintenance tasks.

AWS RDS provides features like automated backups, high availability, and the ability to easily scale your database resources up or down as your application’s needs change. This service is designed to simplify database management tasks, reduce administrative overhead, and improve the overall reliability and performance of your relational databases in an AWS environment.

### What is RDS Snapshot ?

An RDS snapshot in Amazon Relational Database Service captures a point-in-time copy of a database instance, including data, schema, and settings. Used for backup and recovery, it ensures data consistency and flexibility. Snapshots support cloning, migration, and instance creation, aiding in development, testing, and disaster recovery. With a specified retention period, users can manage storage costs effectively. Encryption adds an extra layer of security, and automated backups simplify regular snapshot creation. Sharing options facilitate collaboration, making RDS snapshots a versatile tool for maintaining data integrity and managing relational databases on AWS.

### Understanding Scenario

In this particular scenario, we are going to look at how we can exploit and exfiltrate data from the public snapshot which is an AWS RDS misconfiguration which many people do to share the database with different accounts but rather than sharing it with particular AWS account they made the snapshot public without even enabling the encryption for the respective RDS Database. This allows the attackers to gain access to data inside the database without any hurdles like the crossing encryption layers and access controls layers because by default when you create the database from the public snapshot you can easily change the master password for that particular RDS Database.

### Lab

Navigate to the Public Snapshot section in the AWS RDS Service and search for the specific string that can be the company name or anything else to check for the public RDS instance for that specific string.

<figure><img src="https://1846927083-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mj9GKP_mf1AnaApJEIA%2Fuploads%2FKLPIB6MfJnvmCCsLA8ii%2Fimage.png?alt=media&#x26;token=d9c47e69-9522-4be0-90ea-92f1c9fb8a42" alt=""><figcaption></figcaption></figure>

Now open the Snapshot in the new tab and from the actions tab select “Restore Snapshot“ for making the new db in your account with the public snapshot.

<figure><img src="https://1846927083-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mj9GKP_mf1AnaApJEIA%2Fuploads%2FT5LuCExs5XRDX64xdPrR%2Fimage.png?alt=media&#x26;token=02a5acde-715c-4b70-af17-ae8cef2bbb17" alt=""><figcaption></figcaption></figure>

Now while configuring the database from the snapshot make sure to select “Yes“ to enable public access on the database.

<figure><img src="https://1846927083-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mj9GKP_mf1AnaApJEIA%2Fuploads%2F7DSuJgR7cNl05Lu6RH6n%2Fimage.png?alt=media&#x26;token=f066aa5c-4512-492a-8dd5-8065cc6db889" alt=""><figcaption></figcaption></figure>

Now once the database status is “avalaible” click on the “Modify” tab for creating the master password of the database.

<figure><img src="https://1846927083-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mj9GKP_mf1AnaApJEIA%2Fuploads%2FgnDiopa98PbkNGD4HwCj%2Fimage.png?alt=media&#x26;token=e2102c77-e78a-4c5e-99d3-9fe3e8974269" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1846927083-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mj9GKP_mf1AnaApJEIA%2Fuploads%2F3oTT2UhHr1JSszBnr4H2%2Fimage.png?alt=media&#x26;token=1ae1e8b0-dad2-4693-8ca6-1ea6526c5985" alt=""><figcaption></figcaption></figure>

Now configure the security group for the database and open the port 3306 for your particular IP so that we can access the database.

<figure><img src="https://1846927083-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mj9GKP_mf1AnaApJEIA%2Fuploads%2F45T5EFvA5I83zdvqNMrQ%2Fimage.png?alt=media&#x26;token=2b970907-00cc-477b-abe4-e825fab1f6e9" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1846927083-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mj9GKP_mf1AnaApJEIA%2Fuploads%2FXnlJ0pbYLfXVAzMrIEbH%2Fimage.png?alt=media&#x26;token=ff6ce545-ee98-4877-bbfa-5b08347eb924" alt=""><figcaption></figcaption></figure>

Now copy the endpoint from the database section of the respective database.

<figure><img src="https://1846927083-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mj9GKP_mf1AnaApJEIA%2Fuploads%2FHLYPDWfAGdJnNYhhj96g%2Fimage.png?alt=media&#x26;token=198ad0db-feca-4916-8483-ed294be90691" alt=""><figcaption></figcaption></figure>

Now connect with the database using mysql client in linux with the below command.

`mysql -u <username> -p -h <databaseendpoint>`
