AWS - S3 Unauthenticated Enum

Support HackTricks

S3 Public Buckets

버킷은 모든 사용자가 버킷의 내용을 나열할 수 있는 경우 **“공개”**로 간주되며, 버킷의 내용이 특정 사용자만 나열하거나 작성할 수 있는 경우 **“비공개”**로 간주됩니다.

회사는 버킷 권한을 잘못 구성하여 모든 것 또는 AWS의 모든 계정에서 인증된 모든 사용자에게 액세스를 제공할 수 있습니다(따라서 누구에게나). 이러한 잘못된 구성에도 불구하고 버킷에 자체 액세스 제어 목록(ACL)이 있을 수 있으므로 일부 작업을 수행할 수 없을 수도 있습니다.

AWS-S3 잘못된 구성에 대해 알아보세요: http://flaws.cloud http://flaws2.cloud/

Finding AWS Buckets

웹페이지가 AWS를 사용하여 일부 리소스를 저장할 때 찾는 다양한 방법:

Enumeration & OSINT:

  • wappalyzer 브라우저 플러그인 사용

  • burp를 사용하여(웹을 크롤링하여) 또는 페이지를 수동으로 탐색하여 로드된 모든 리소스가 기록됩니다.

  • 다음과 같은 도메인에서 리소스 확인:

http://s3.amazonaws.com/[bucket_name]/
http://[bucket_name].s3.amazonaws.com/
  • resources.domain.com과 같은 CNAMES 확인, 이는 bucket.s3.amazonaws.com일 수 있습니다.

  • 이미 발견된 공개 버킷이 있는 웹 https://buckets.grayhatwarfare.com 확인.

  • 버킷 이름버킷 도메인 이름동일해야 합니다.

  • flaws.cloudIP 52.92.181.107에 있으며, 해당 IP로 이동하면 https://aws.amazon.com/s3/로 리디렉션됩니다. 또한, dig -x 52.92.181.107s3-website-us-west-2.amazonaws.com을 반환합니다.

  • 버킷인지 확인하려면 https://flaws.cloud.s3.amazonaws.com/을 방문할 수도 있습니다.

Brute-Force

테스트 중인 회사와 관련된 이름을 무차별 대입하여 버킷을 찾을 수 있습니다:

# Generate a wordlist to create permutations
curl -s https://raw.githubusercontent.com/cujanovic/goaltdns/master/words.txt > /tmp/words-s3.txt.temp
curl -s https://raw.githubusercontent.com/jordanpotti/AWSBucketDump/master/BucketNames.txt >>/tmp/words-s3.txt.temp
cat /tmp/words-s3.txt.temp | sort -u > /tmp/words-s3.txt

# Generate a wordlist based on the domains and subdomains to test
## Write those domains and subdomains in subdomains.txt
cat subdomains.txt > /tmp/words-hosts-s3.txt
cat subdomains.txt | tr "." "-" >> /tmp/words-hosts-s3.txt
cat subdomains.txt | tr "." "\n" | sort -u >> /tmp/words-hosts-s3.txt

# Create permutations based in a list with the domains and subdomains to attack
goaltdns -l /tmp/words-hosts-s3.txt -w /tmp/words-s3.txt -o /tmp/final-words-s3.txt.temp
## The previous tool is specialized increating permutations for subdomains, lets filter that list
### Remove lines ending with "."
cat /tmp/final-words-s3.txt.temp | grep -Ev "\.$" > /tmp/final-words-s3.txt.temp2
### Create list without TLD
cat /tmp/final-words-s3.txt.temp2 | sed -E 's/\.[a-zA-Z0-9]+$//' > /tmp/final-words-s3.txt.temp3
### Create list without dots
cat /tmp/final-words-s3.txt.temp3 | tr -d "." > /tmp/final-words-s3.txt.temp4http://phantom.s3.amazonaws.com/
### Create list without hyphens
cat /tmp/final-words-s3.txt.temp3 | tr "." "-" > /tmp/final-words-s3.txt.temp5

## Generate the final wordlist
cat /tmp/final-words-s3.txt.temp2 /tmp/final-words-s3.txt.temp3 /tmp/final-words-s3.txt.temp4 /tmp/final-words-s3.txt.temp5 | grep -v -- "-\." | awk '{print tolower($0)}' | sort -u > /tmp/final-words-s3.txt

## Call s3scanner
s3scanner --threads 100 scan --buckets-file /tmp/final-words-s3.txt  | grep bucket_exists

Loot S3 Buckets

S3 공개 버킷이 주어지면, BucketLoot은 자동으로 흥미로운 정보를 검색할 수 있습니다.

Find the Region

AWS에서 지원하는 모든 지역은 https://docs.aws.amazon.com/general/latest/gr/s3.html에서 찾을 수 있습니다.

By DNS

발견된 IP에 대해 DNS 요청을 수행하여 dig 및 **nslookup**으로 버킷의 지역을 얻을 수 있습니다:

dig flaws.cloud
;; ANSWER SECTION:
flaws.cloud.    5    IN    A    52.218.192.11

nslookup 52.218.192.11
Non-authoritative answer:
11.192.218.52.in-addr.arpa name = s3-website-us-west-2.amazonaws.com.

해결된 도메인에 "website" 단어가 있는지 확인하십시오. 정적 웹사이트에 접근하려면: flaws.cloud.s3-website-us-west-2.amazonaws.com 또는 버킷에 접근하려면: flaws.cloud.s3-us-west-2.amazonaws.com를 방문하십시오.

시도해보기

버킷에 접근하려고 하지만 도메인 이름에 다른 지역을 지정한 경우 (예: 버킷이 bucket.s3.amazonaws.com에 있지만 bucket.s3-website-us-west-2.amazonaws.com에 접근하려고 시도하는 경우), 올바른 위치로 안내됩니다:

버킷 열거

버킷의 개방성을 테스트하기 위해 사용자는 웹 브라우저에 URL을 입력할 수 있습니다. 비공개 버킷은 "Access Denied"로 응답합니다. 공개 버킷은 저장된 첫 1,000개의 객체를 나열합니다.

모두에게 공개:

비공개:

cli로도 확인할 수 있습니다:

#Use --no-sign-request for check Everyones permissions
#Use --profile <PROFILE_NAME> to indicate the AWS profile(keys) that youwant to use: Check for "Any Authenticated AWS User" permissions
#--recursive if you want list recursivelyls
#Opcionally you can select the region if you now it
aws s3 ls s3://flaws.cloud/ [--no-sign-request] [--profile <PROFILE_NAME>] [ --recursive] [--region us-west-2]

버킷에 도메인 이름이 없는 경우, 열거를 시도할 때 버킷 이름만 입력하고 전체 AWSs3 도메인을 입력하지 마십시오. 예: s3://<BUCKETNAME>

Public URL template

https://{user_provided}.s3.amazonaws.com

Get Account ID from public Bucket

공개 Bucket을 통해 AWS 계정을 식별하는 것이 가능합니다. 이는 새로운 S3:ResourceAccount Policy Condition Key를 이용하는 것입니다. 이 조건은 S3 버킷에 있는 계정을 기반으로 접근을 제한합니다 (다른 계정 기반 정책은 요청하는 주체가 속한 계정을 기반으로 제한합니다). 그리고 정책에 와일드카드를 포함할 수 있기 때문에 한 번에 한 숫자씩 계정 번호를 찾는 것이 가능합니다.

이 도구는 이 과정을 자동화합니다:

# Installation
pipx install s3-account-search
pip install s3-account-search
# With a bucket
s3-account-search arn:aws:iam::123456789012:role/s3_read s3://my-bucket
# With an object
s3-account-search arn:aws:iam::123456789012:role/s3_read s3://my-bucket/path/to/object.ext

이 기술은 API Gateway URLs, Lambda URLs, Data Exchange 데이터 세트와 태그의 값을 얻는 데도 사용할 수 있습니다(태그 키를 알고 있는 경우). 더 많은 정보는 original research와 이 익스플로잇을 자동화하는 도구 conditional-love에서 찾을 수 있습니다.

버킷이 AWS 계정에 속하는지 확인하기

이 블로그 게시물에서 설명한 것처럼, 버킷을 나열할 수 있는 권한이 있는 경우 다음과 같은 요청을 보내어 버킷이 속한 accountID를 확인할 수 있습니다:

curl -X GET "[bucketname].amazonaws.com/" \
-H "x-amz-expected-bucket-owner: [correct-account-id]"

<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">...</ListBucketResult>

오류가 "Access Denied"인 경우 계정 ID가 잘못된 것입니다.

루트 계정 열거로 사용된 이메일

이 블로그 게시물에서 설명한 것처럼, 이메일 주소가 AWS 계정과 관련이 있는지 확인하는 것이 가능합니다. ACL을 통해 이메일 권한을 S3 버킷에 부여하려고 시도함으로써 확인할 수 있습니다. 오류가 발생하지 않으면 해당 이메일이 어떤 AWS 계정의 루트 사용자임을 의미합니다:

s3_client.put_bucket_acl(
Bucket=bucket_name,
AccessControlPolicy={
'Grants': [
{
'Grantee': {
'EmailAddress': 'some@emailtotest.com',
'Type': 'AmazonCustomerByEmail',
},
'Permission': 'READ'
},
],
'Owner': {
'DisplayName': 'Whatever',
'ID': 'c3d78ab5093a9ab8a5184de715d409c2ab5a0e2da66f08c2f6cc5c0bdeadbeef'
}
}
)

참고 자료

HackTricks 지원하기

Last updated