> For the complete documentation index, see [llms.txt](https://www.pentestwiki.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pentestwiki.com/cloud/aws/undefined/account-id-enumeration.md).

# Account ID Enumeration

<figure><img src="/files/drwDogokHDsPsSDoBxa9" alt=""><figcaption><p>S3 버킷 기본 생성 설정</p></figcaption></figure>

[AWS](/cloud/aws.md#s3-bucket)은 생성할 때 기본적으로 프라이빗 상태이지만, e커머스와 같이 웹 자산을 제공하기 위해 의도적으로 퍼블릭으로 사용하기도 합니다.

퍼블릭 버킷을 하는 주 목적인 파일 다운로드(웹 자산 배포)를 위해서는 s3:GetObject 권한이 필요합니다. 반면 s3:ListBucket 권한이 같이 활성화 되어 있을 경우에만 Account ID 열거 공격이 가능합니다.

## Setting

열거 공격을 위해서 공격자 AWS에서 몇가지 설정을 해줘야 합니다. `IAM > 사용자 > 사용자 생성 > 권한 추가 > 인라인 정책 생성`을 통해 json 형식의 정책을 생성합니다.

```json
{
	"Version": "2012-10-17",
	"Statement": {
		"Effect": "Allow",
		"Action": "sts:AssumeRole",
		"Resource": "arn:aws:iam::'<account-id>':role/pentest"
	}
}
```

사용자 정책 생성 이후 역할을 생성해야 합니다. `IAM > 역할 > 역할 생성 > 사용자 지정 신뢰 정책` 를 통해 json 형식의 신뢰 정책을 생성합니다.

```json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::'<account-id>':user/mick3y"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}
```

마지막으로 `IAM > 역할 > 생성한 역할 > 권한 정책 > 권한 추가 > 인라인 정책 생성` 에서 json 형식의 권한 정책을 추가합니다.

```json
{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Effect": "Allow",
			"Action": [
				"s3:ListAllMyBuckets",
				"s3:ListBucket",
				"s3:GetBucketLocation",
				"s3:GetObject"
			],
			"Resource": "*"
		}
	]
}
```

## Abuse

<pre class="language-bash"><code class="lang-bash"><strong># s3-account-search 설치 및 환경변수 등록
</strong>python3 -m pipx install s3-account-search 
pipx ensurepath

<strong># 대상 Account ID 열거
</strong>s3-account-search '&#x3C;role-arn>' '&#x3C;target-s3-name>' --profile '&#x3C;aws-profile>'
</code></pre>
