AWS - S3 Unauthenticated Enum
Reading time: 10 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** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें, PRs को HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में सबमिट करके।
S3 Public Buckets
A bucket is considered “public” if any user can list the contents of the bucket, and “private” if the bucket's contents can only be listed or written by certain users.
कंपनियाँ कभी-कभी buckets की permissions गलत-कॉन्फ़िगर रखती हैं जो access या तो सब कुछ के लिए दे सकती हैं या AWS में किसी भी account में authenticated किसी भी व्यक्ति को दे सकती हैं (यानी किसी भी व्यक्ति को)। ध्यान दें कि ऐसे misconfigurations में भी कुछ actions निष्पादित नहीं हो सकते क्योंकि buckets के अपने access control lists (ACLs) हो सकते हैं।
Learn about AWS-S3 misconfiguration here: http://flaws.cloud and http://flaws2.cloud/
Finding AWS Buckets
विभिन्न तरीके जिनसे पता चलता है कि कोई webpage कुछ resources स्टोर करने के लिए AWS का उपयोग कर रहा है:
Enumeration & OSINT:
- wappalyzer browser plugin का उपयोग
- burp का उपयोग करते हुए (spidering the web) या पेज पर मैन्युअली नेविगेट करके सभी resources जो loaded होते हैं, History में save हो जाएंगे।
- निम्न domains में resources के लिए जाँच करें:
http://s3.amazonaws.com/[bucket_name]/
http://[bucket_name].s3.amazonaws.com/
- CNAMES की जाँच करें क्योंकि
resources.domain.comके पास CNAMEbucket.s3.amazonaws.comहो सकता है - s3dns – एक lightweight DNS server जो DNS ट्रैफ़िक का विश्लेषण करके passive तरीके से cloud storage buckets (S3, GCP, Azure) की पहचान करता है। यह CNAMEs का पता लगाता है, resolution chains का पालन करता है, और bucket patterns से मेल खाता है, brute-force या API-आधारित खोज का एक शांत विकल्प प्रदान करता है। recon और OSINT workflows के लिए उपयुक्त।
- https://buckets.grayhatwarfare.com चेक करें, एक वेब जो पहले से ही discovered open buckets रखता है।
- bucket name और bucket domain name को एक ही होना चाहिए।
- flaws.cloud का IP 52.92.181.107 है और यदि आप वहाँ जाते हैं तो यह आपको https://aws.amazon.com/s3/ पर redirect कर देता है। साथ ही,
dig -x 52.92.181.107s3-website-us-west-2.amazonaws.comदेता है। - यह जाँचने के लिए कि यह एक bucket है, आप https://flaws.cloud.s3.amazonaws.com/ पर भी visit कर सकते हैं।
Brute-Force
आप pentesting कर रहे कंपनी से संबंधित नामों को brute-force करके buckets ढूँढ सकते हैं:
- https://github.com/sa7mon/S3Scanner
- https://github.com/clario-tech/s3-inspector
- https://github.com/jordanpotti/AWSBucketDump (Contains a list with potential bucket names)
- 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
# 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 open buckets मौजूद हों, तो BucketLoot स्वचालित रूप से दिलचस्प जानकारी खोज सकता है।
Find the Region
आप AWS द्वारा सपोर्ट किए गए सभी regions को यहाँ पा सकते हैं: https://docs.aws.amazon.com/general/latest/gr/s3.html
By DNS
आप dig और nslookup से bucket का region प्राप्त कर सकते हैं, इसके लिए खोजे गए IP का DNS request करें:
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.
Check that the resolved domain have the word "website".
आप स्टैटिक वेबसाइट तक पहुँच सकते हैं: flaws.cloud.s3-website-us-west-2.amazonaws.com
या आप bucket को विजिट करके एक्सेस कर सकते हैं: flaws.cloud.s3-us-west-2.amazonaws.com
By Trying
यदि आप किसी bucket तक पहुँचने की कोशिश करते हैं, लेकिन डोमेन नाम में आप किसी दूसरे region का उल्लेख करते हैं (उदाहरण के लिए bucket bucket.s3.amazonaws.com में है पर आप bucket.s3-website-us-west-2.amazonaws.com पर पहुँचने की कोशिश करते हैं), तो आपको सही स्थान दिखा दिया जाएगा:
.png)
Enumerating the bucket
Bucket की openness की जाँच करने के लिए उपयोगकर्ता बस URL को अपने वेब ब्राउज़र में दर्ज कर सकते हैं। एक private bucket "Access Denied" के साथ प्रतिक्रिया करेगा। एक public bucket पहले 1,000 objects को सूचीबद्ध करेगा।
Open to everyone:
.png)
Private:
.png)
You can also check this with the 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]
यदि bucket का कोई डोमेन नाम नहीं है, इसे enumerate करने की कोशिश करते समय, केवल bucket name डालें और पूरे AWSs3 डोमेन को नहीं। उदाहरण: s3://<BUCKETNAME>
सार्वजनिक URL टेम्पलेट
https://{user_provided}.s3.amazonaws.com
public Bucket से Account ID प्राप्त करें
नई S3:ResourceAccount Policy Condition Key का उपयोग करके किसी AWS account का पता लगाया जा सकता है।
यह शर्त उस S3 bucket के आधार पर access को प्रतिबंधित करती है जिसमें account होता है (अन्य account-आधारित नीतियाँ उस account के आधार पर restriction लगाती हैं जिसमें requesting principal होता है)।
और क्योंकि policy में wildcards हो सकते हैं, इसलिए account number को एक समय में सिर्फ एक अंक के आधार पर पाया जा सकता है।
यह tool इस प्रक्रिया को automate करता है:
# 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 data sets के साथ भी काम करती है और tags का value भी प्राप्त करने के लिए इस्तेमाल हो सकती है (यदि आप tag key जानते हैं)। आप इस exploitation को automate करने के लिए अधिक जानकारी original research और tool conditional-love में पा सकते हैं।
किसी bucket का AWS account से संबंधित होना सत्यापित करना
जैसा कि this blog post** में समझाया गया है, यदि आपके पास किसी bucket को list करने की permissions हैं** तो यह संभव है कि आप accountID की पुष्टि कर सकें जिससे वह bucket संबंधित है, इस तरह का request भेजकर:
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” है तो इसका मतलब है कि account ID गलत था।
root account enumeration के लिए इस्तेमाल किए गए Emails
जैसा कि this blog post में समझाया गया है, यह जांचना संभव है कि कोई ईमेल पता किसी AWS account से संबंधित है या नहीं, S3 bucket पर ACLs के माध्यम से किसी ईमेल को permissions देने की कोशिश करके। यदि इससे कोई त्रुटि ट्रिगर नहीं होती, तो इसका मतलब है कि वह ईमेल किसी AWS account का root user है:
s3_client.put_bucket_acl(
Bucket=bucket_name,
AccessControlPolicy={
'Grants': [
{
'Grantee': {
'EmailAddress': 'some@emailtotest.com',
'Type': 'AmazonCustomerByEmail',
},
'Permission': 'READ'
},
],
'Owner': {
'DisplayName': 'Whatever',
'ID': 'c3d78ab5093a9ab8a5184de715d409c2ab5a0e2da66f08c2f6cc5c0bdeadbeef'
}
}
)
संदर्भ
- 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** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें, PRs को HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में सबमिट करके।
HackTricks Cloud