AWS - S3 인증되지 않은 열거
Reading time: 8 minutes
tip
AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE)
Azure 해킹 배우기 및 연습하기:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks 지원하기
- 구독 계획 확인하기!
- **💬 Discord 그룹 또는 텔레그램 그룹에 참여하거나 Twitter 🐦 @hacktricks_live를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.
S3 공개 버킷
버킷은 **“공개”**로 간주되며, 모든 사용자가 버킷의 내용을 나열할 수 있는 경우이고, **“비공개”**는 버킷의 내용이 특정 사용자만 나열하거나 쓸 수 있는 경우입니다.
회사는 버킷 권한이 잘못 구성되어 모든 것 또는 AWS의 모든 계정에 인증된 모든 사용자에게 접근을 허용할 수 있습니다(즉, 누구에게나). 이러한 잘못된 구성에서도 일부 작업은 수행할 수 없을 수 있으며, 버킷은 자체 접근 제어 목록(ACL)을 가질 수 있습니다.
AWS-S3 잘못 구성에 대해 알아보세요: http://flaws.cloud 및 http://flaws2.cloud/
AWS 버킷 찾기
웹페이지가 AWS를 사용하여 일부 리소스를 저장할 때 찾는 다양한 방법:
열거 및 OSINT:
- wappalyzer 브라우저 플러그인 사용
- burp 사용(웹 스파이더링) 또는 페이지를 수동으로 탐색하여 모든 리소스 로드된 내용이 기록에 저장됩니다.
- 다음과 같은 도메인에서 리소스 확인:
http://s3.amazonaws.com/[bucket_name]/
http://[bucket_name].s3.amazonaws.com/
- CNAMES 확인:
resources.domain.com
은bucket.s3.amazonaws.com
의 CNAME을 가질 수 있습니다. - s3dns – DNS 트래픽을 분석하여 클라우드 스토리지 버킷(S3, GCP, Azure)을 수동으로 식별하는 경량 DNS 서버입니다. CNAME을 감지하고, 해상도 체인을 따르며, 버킷 패턴을 일치시켜 브루트 포스 또는 API 기반 발견의 조용한 대안을 제공합니다. 정찰 및 OSINT 워크플로에 적합합니다.
- https://buckets.grayhatwarfare.com, 이미 발견된 공개 버킷이 있는 웹사이트입니다.
- 버킷 이름과 버킷 도메인 이름은 같아야 합니다.
- flaws.cloud는 IP 52.92.181.107에 있으며, 해당 주소로 가면 https://aws.amazon.com/s3/로 리디렉션됩니다. 또한,
dig -x 52.92.181.107
는s3-website-us-west-2.amazonaws.com
을 반환합니다. - 버킷인지 확인하려면 https://flaws.cloud.s3.amazonaws.com/를 방문할 수도 있습니다.
브루트 포스
회사를 대상으로 이름을 브루트 포스하여 버킷을 찾을 수 있습니다:
- https://github.com/sa7mon/S3Scanner
- https://github.com/clario-tech/s3-inspector
- https://github.com/jordanpotti/AWSBucketDump (잠재적인 버킷 이름 목록 포함)
- https://github.com/fellchase/flumberboozle/tree/master/flumberbuckets
- https://github.com/smaranchand/bucky
- https://github.com/tomdev/teh_s3_bucketeers
- https://github.com/RhinoSecurityLabs/Security-Research/tree/master/tools/aws-pentest-tools/s3
- https://github.com/Eilonh/s3crets_scanner
- https://github.com/belane/CloudHunter
# 생성된 단어 목록으로 변형 생성
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
# 테스트할 도메인 및 서브도메인 기반의 단어 목록 생성
## 해당 도메인 및 서브도메인을 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
# 공격할 도메인 및 서브도메인 목록을 기반으로 변형 생성
goaltdns -l /tmp/words-hosts-s3.txt -w /tmp/words-s3.txt -o /tmp/final-words-s3.txt.temp
## 이전 도구는 서브도메인에 대한 변형 생성을 전문으로 하므로 해당 목록을 필터링합니다.
### "."로 끝나는 줄 제거
cat /tmp/final-words-s3.txt.temp | grep -Ev "\.$" > /tmp/final-words-s3.txt.temp2
### TLD 없는 목록 생성
cat /tmp/final-words-s3.txt.temp2 | sed -E 's/\.[a-zA-Z0-9]+$//' > /tmp/final-words-s3.txt.temp3
### 점 없는 목록 생성
cat /tmp/final-words-s3.txt.temp3 | tr -d "." > /tmp/final-words-s3.txt.temp4http://phantom.s3.amazonaws.com/
### 하이픈 없는 목록 생성
cat /tmp/final-words-s3.txt.temp3 | tr "." "-" > /tmp/final-words-s3.txt.temp5
## 최종 단어 목록 생성
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
## s3scanner 호출
s3scanner --threads 100 scan --buckets-file /tmp/final-words-s3.txt | grep bucket_exists
S3 버킷 약탈
S3 공개 버킷이 주어지면, BucketLoot는 자동으로 흥미로운 정보를 검색할 수 있습니다.
지역 찾기
AWS에서 지원하는 모든 지역은 https://docs.aws.amazon.com/general/latest/gr/s3.html에서 확인할 수 있습니다.
DNS로
dig
및 **nslookup
**을 사용하여 발견된 IP의 DNS 요청을 수행하여 버킷의 지역을 확인할 수 있습니다:
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>
공개 URL 템플릿
https://{user_provided}.s3.amazonaws.com
공개 버킷에서 계정 ID 가져오기
새로운 S3:ResourceAccount
정책 조건 키를 활용하여 AWS 계정을 확인할 수 있습니다. 이 조건은 계정이 있는 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 URL, Lambda URL, Data Exchange 데이터 세트와 태그 값을 가져오는 데에도 작동합니다(태그 키를 알고 있는 경우). 더 많은 정보는 원본 연구와 이 취약점을 자동화하는 도구 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가 잘못되었다는 의미입니다.
루트 계정 열거를 위한 사용된 이메일
이 블로그 게시물에서 설명한 바와 같이, S3 버킷에 대한 ACL을 통해 이메일 주소에 권한을 부여하려고 시도함으로써 해당 이메일 주소가 AWS 계정과 관련이 있는지 확인할 수 있습니다. 오류가 발생하지 않으면, 해당 이메일이 일부 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'
}
}
)
References
- https://www.youtube.com/watch?v=8ZXRw4Ry3mQ
- https://cloudar.be/awsblog/finding-the-account-id-of-any-public-s3-bucket/
tip
AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE)
Azure 해킹 배우기 및 연습하기:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks 지원하기
- 구독 계획 확인하기!
- **💬 Discord 그룹 또는 텔레그램 그룹에 참여하거나 Twitter 🐦 @hacktricks_live를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.