mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-14 05:46:25 -08:00
Translated ['src/README.md', 'src/banners/hacktricks-training.md', 'src/
This commit is contained in:
@@ -6,38 +6,37 @@
|
||||
|
||||
### Basic Information
|
||||
|
||||
AWS API Gateway is a comprehensive service offered by Amazon Web Services (AWS) designed for developers to **create, publish, and oversee APIs on a large scale**. It functions as an entry point to an application, permitting developers to establish a framework of rules and procedures. This framework governs the access external users have to certain data or functionalities within the application.
|
||||
AWS API Gateway एक व्यापक सेवा है जो Amazon Web Services (AWS) द्वारा पेश की गई है, जिसे डेवलपर्स को **बड़े पैमाने पर APIs बनाने, प्रकाशित करने और देखरेख करने** के लिए डिज़ाइन किया गया है। यह एक एप्लिकेशन के लिए एक प्रवेश बिंदु के रूप में कार्य करता है, जिससे डेवलपर्स को नियमों और प्रक्रियाओं का एक ढांचा स्थापित करने की अनुमति मिलती है। यह ढांचा बाहरी उपयोगकर्ताओं को एप्लिकेशन के भीतर कुछ डेटा या कार्यक्षमताओं तक पहुँचने को नियंत्रित करता है।
|
||||
|
||||
API Gateway enables you to define **how requests to your APIs should be handled**, and it can create custom API endpoints with specific methods (e.g., GET, POST, PUT, DELETE) and resources. It can also generate client SDKs (Software Development Kits) to make it easier for developers to call your APIs from their applications.
|
||||
API Gateway आपको **यह परिभाषित करने की अनुमति देता है कि आपके APIs के लिए अनुरोधों को कैसे संभाला जाना चाहिए**, और यह विशिष्ट विधियों (जैसे, GET, POST, PUT, DELETE) और संसाधनों के साथ कस्टम API एंडपॉइंट बनाने में सक्षम है। यह डेवलपर्स के लिए आपके APIs को उनके एप्लिकेशनों से कॉल करना आसान बनाने के लिए क्लाइंट SDKs (सॉफ़्टवेयर विकास किट) भी उत्पन्न कर सकता है।
|
||||
|
||||
### API Gateways Types
|
||||
|
||||
- **HTTP API**: Build low-latency and cost-effective REST APIs with built-in features such as OIDC and OAuth2, and native CORS support. Works with the following: Lambda, HTTP backends.
|
||||
- **WebSocket API**: Build a WebSocket API using persistent connections for real-time use cases such as chat applications or dashboards. Works with the following: Lambda, HTTP, AWS Services.
|
||||
- **REST API**: Develop a REST API where you gain complete control over the request and response along with API management capabilities. Works with the following: Lambda, HTTP, AWS Services.
|
||||
- **REST API Private**: Create a REST API that is only accessible from within a VPC.
|
||||
- **HTTP API**: OIDC और OAuth2 जैसी अंतर्निहित सुविधाओं के साथ कम विलंबता और लागत प्रभावी REST APIs बनाएं, और मूल CORS समर्थन। निम्नलिखित के साथ काम करता है: Lambda, HTTP बैकएंड।
|
||||
- **WebSocket API**: चैट एप्लिकेशन या डैशबोर्ड जैसे वास्तविक समय के उपयोग के मामलों के लिए स्थायी कनेक्शनों का उपयोग करके एक WebSocket API बनाएं। निम्नलिखित के साथ काम करता है: Lambda, HTTP, AWS सेवाएँ।
|
||||
- **REST API**: एक REST API विकसित करें जहाँ आप अनुरोध और प्रतिक्रिया पर पूर्ण नियंत्रण प्राप्त करते हैं साथ ही API प्रबंधन क्षमताएँ। निम्नलिखित के साथ काम करता है: Lambda, HTTP, AWS सेवाएँ।
|
||||
- **REST API Private**: एक REST API बनाएं जो केवल एक VPC के भीतर से सुलभ हो।
|
||||
|
||||
### API Gateway Main Components
|
||||
|
||||
1. **Resources**: In API Gateway, resources are the components that **make up the structure of your API**. They represent **the different paths or endpoints** of your API and correspond to the various actions that your API supports. A resource is each method (e.g., GET, POST, PUT, DELETE) **inside each path** (/, or /users, or /user/{id}.
|
||||
2. **Stages**: Stages in API Gateway represent **different versions or environments** of your API, such as development, staging, or production. You can use stages to manage and deploy **multiple versions of your API simultaneousl**y, allowing you to test new features or bug fixes without affecting the production environment. Stages also **support stage variables**, which are key-value pairs that can be used to configure the behavior of your API based on the current stage. For example, you could use stage variables to direct API requests to different Lambda functions or other backend services depending on the stage.
|
||||
- The stage is indicated at the beggining of the URL of the API Gateway endpoint.
|
||||
3. **Authorizers**: Authorizers in API Gateway are responsible for **controlling access to your API** by verifying the identity of the caller before allowing the request to proceed. You can use **AWS Lambda functions** as custom authorizers, which allows you to implement your own authentication and authorization logic. When a request comes in, API Gateway passes the request's authorization token to the Lambda authorizer, which processes the token and returns an IAM policy that determines what actions the caller is allowed to perform. API Gateway also supports **built-in authorizers**, such as **AWS Identity and Access Management (IAM)** and **Amazon Cognito**.
|
||||
4. **Resource Policy**: A resource policy in API Gateway is a JSON document that **defines the permissions for accessing your API**. It is similar to an IAM policy but specifically tailored for API Gateway. You can use a resource policy to control who can access your API, which methods they can call, and from which IP addresses or VPCs they can connect. **Resource policies can be used in combination with authorizers** to provide fine-grained access control for your API.
|
||||
- In order to make effect the API needs to be **deployed again after** the resource policy is modified.
|
||||
1. **Resources**: API Gateway में, संसाधन वे घटक हैं जो **आपके API की संरचना बनाते हैं**। वे **आपके API के विभिन्न पथों या एंडपॉइंट्स** का प्रतिनिधित्व करते हैं और आपके API द्वारा समर्थित विभिन्न क्रियाओं के अनुरूप होते हैं। एक संसाधन प्रत्येक विधि है (जैसे, GET, POST, PUT, DELETE) **प्रत्येक पथ के भीतर** (/, या /users, या /user/{id}).
|
||||
2. **Stages**: API Gateway में स्टेज आपके API के **विभिन्न संस्करणों या वातावरणों** का प्रतिनिधित्व करते हैं, जैसे विकास, स्टेजिंग, या उत्पादन। आप स्टेज का उपयोग करके **आपके API के कई संस्करणों का प्रबंधन और तैनाती** कर सकते हैं, जिससे आप नए फीचर्स या बग फिक्स का परीक्षण कर सकते हैं बिना उत्पादन वातावरण को प्रभावित किए। स्टेज **स्टेज वेरिएबल्स** का भी समर्थन करते हैं, जो कुंजी-मूल्य जोड़े होते हैं जिन्हें वर्तमान स्टेज के आधार पर आपके API के व्यवहार को कॉन्फ़िगर करने के लिए उपयोग किया जा सकता है। उदाहरण के लिए, आप स्टेज वेरिएबल्स का उपयोग API अनुरोधों को विभिन्न Lambda कार्यों या अन्य बैकएंड सेवाओं की ओर निर्देशित करने के लिए कर सकते हैं।
|
||||
- स्टेज API Gateway एंडपॉइंट के URL की शुरुआत में संकेतित होता है।
|
||||
3. **Authorizers**: API Gateway में ऑथराइजर्स आपके API तक पहुँच को **नियंत्रित करने** के लिए जिम्मेदार होते हैं, कॉलर की पहचान को सत्यापित करके अनुरोध को आगे बढ़ाने की अनुमति देने से पहले। आप **AWS Lambda कार्यों** का उपयोग कस्टम ऑथराइजर्स के रूप में कर सकते हैं, जो आपको अपनी स्वयं की प्रमाणीकरण और प्राधिकरण लॉजिक लागू करने की अनुमति देता है। जब एक अनुरोध आता है, API Gateway अनुरोध के प्रमाणीकरण टोकन को Lambda ऑथराइज़र को पास करता है, जो टोकन को संसाधित करता है और एक IAM नीति लौटाता है जो निर्धारित करती है कि कॉलर को कौन सी क्रियाएँ करने की अनुमति है। API Gateway **निर्मित ऑथराइजर्स** का भी समर्थन करता है, जैसे **AWS पहचान और पहुँच प्रबंधन (IAM)** और **Amazon Cognito**।
|
||||
4. **Resource Policy**: API Gateway में एक संसाधन नीति एक JSON दस्तावेज़ है जो **आपके API तक पहुँचने के लिए अनुमतियों को परिभाषित करता है**। यह एक IAM नीति के समान है लेकिन विशेष रूप से API Gateway के लिए तैयार की गई है। आप एक संसाधन नीति का उपयोग यह नियंत्रित करने के लिए कर सकते हैं कि कौन आपके API तक पहुँच सकता है, वे कौन सी विधियाँ कॉल कर सकते हैं, और वे किन IP पते या VPCs से कनेक्ट कर सकते हैं। **संसाधन नीतियों का उपयोग ऑथराइजर्स के साथ संयोजन में किया जा सकता है** ताकि आपके API के लिए बारीक पहुँच नियंत्रण प्रदान किया जा सके।
|
||||
- प्रभाव डालने के लिए API को **संसाधन नीति में संशोधन के बाद फिर से तैनात** करने की आवश्यकता होती है।
|
||||
|
||||
### Logging
|
||||
|
||||
By default, **CloudWatch Logs** are **off**, **Access Logging** is **off**, and **X-Ray tracing** is also **off**.
|
||||
डिफ़ॉल्ट रूप से, **CloudWatch Logs** **बंद** हैं, **Access Logging** **बंद** है, और **X-Ray ट्रेसिंग** भी **बंद** है।
|
||||
|
||||
### Enumeration
|
||||
|
||||
> [!TIP]
|
||||
> Note that in both AWS apis to enumerate resources (**`apigateway`** and **`apigatewayv2`**) the only permission you need and the only read permission grantable is **`apigateway:GET`**, with that you can **enumerate everything.**
|
||||
> ध्यान दें कि संसाधनों को सूचीबद्ध करने के लिए AWS APIs (**`apigateway`** और **`apigatewayv2`**) में आपको केवल एक अनुमति की आवश्यकता है और केवल पढ़ने की अनुमति जो दी जा सकती है वह है **`apigateway:GET`**, इसके साथ आप **सब कुछ सूचीबद्ध कर सकते हैं।**
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="apigateway" }}
|
||||
|
||||
```bash
|
||||
# Generic info
|
||||
aws apigateway get-account
|
||||
@@ -78,11 +77,9 @@ aws apigateway get-usage-plan-key --usage-plan-id <plan_id> --key-id <key_id>
|
||||
###Already consumed
|
||||
aws apigateway get-usage --usage-plan-id <plan_id> --start-date 2023-07-01 --end-date 2023-07-12
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="apigatewayv2" }}
|
||||
|
||||
```bash
|
||||
# Generic info
|
||||
aws apigatewayv2 get-domain-names
|
||||
@@ -124,49 +121,43 @@ aws apigatewayv2 get-models --api-id <id>
|
||||
## Call API
|
||||
https://<api-id>.execute-api.<region>.amazonaws.com/<stage>/<resource>
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
## Different Authorizations to access API Gateway endpoints
|
||||
## API गेटवे एंडपॉइंट्स तक पहुँचने के लिए विभिन्न प्राधिकरण
|
||||
|
||||
### Resource Policy
|
||||
### संसाधन नीति
|
||||
|
||||
It's possible to use resource policies to define who could call the API endpoints.\
|
||||
In the following example you can see that the **indicated IP cannot call** the endpoint `/resource_policy` via GET.
|
||||
यह संभव है कि संसाधन नीतियों का उपयोग करके यह परिभाषित किया जा सके कि कौन API एंडपॉइंट्स को कॉल कर सकता है।\
|
||||
निम्नलिखित उदाहरण में आप देख सकते हैं कि **संकेतित IP कॉल नहीं कर सकता** एंडपॉइंट `/resource_policy` को GET के माध्यम से।
|
||||
|
||||
<figure><img src="../../../images/image (256).png" alt=""><figcaption></figcaption></figure>
|
||||
|
||||
### IAM Authorizer
|
||||
### IAM प्राधिकर्ता
|
||||
|
||||
It's possible to set that a methods inside a path (a resource) requires IAM authentication to call it.
|
||||
यह संभव है कि एक पथ (एक संसाधन) के अंदर एक विधि को कॉल करने के लिए IAM प्रमाणीकरण की आवश्यकता हो।
|
||||
|
||||
<figure><img src="https://lh3.googleusercontent.com/GGx-kfqNXu6zMqGidnO8_eR88fYPpJG-wNuBBnedAJntiRUEPTEScl7OvWthGYRiI_msYCdC6oBFvJc827Tb4-4UogxpOyrEXyst-8IDzP9DC2NOtXSY7w58L0baCAcBQjSyvBhJREvWWCtiboNYPSKuEw=s2048" alt=""><figcaption></figcaption></figure>
|
||||
|
||||
When this is set you will receive the error `{"message":"Missing Authentication Token"}` when you try to reach the endpoint without any authorization.
|
||||
|
||||
One easy way to generate the expected token by the application is to use **curl**.
|
||||
जब यह सेट किया जाता है, तो आप जब किसी भी प्राधिकरण के बिना एंडपॉइंट तक पहुँचने की कोशिश करते हैं, तो आपको त्रुटि `{"message":"Missing Authentication Token"}` प्राप्त होगी।
|
||||
|
||||
ऐप द्वारा अपेक्षित टोकन उत्पन्न करने का एक आसान तरीका **curl** का उपयोग करना है।
|
||||
```bash
|
||||
$ curl -X <method> https://<api-id>.execute-api.<region>.amazonaws.com/<stage>/<resource> --user <AWS_ACCESS_KEY>:<AWS_SECRET_KEY> --aws-sigv4 "aws:amz:<region>:execute-api"
|
||||
```
|
||||
|
||||
Another way is to use the **`Authorization`** type **`AWS Signature`** inside **Postman**.
|
||||
एक और तरीका है कि **Postman** के अंदर **`Authorization`** प्रकार **`AWS Signature`** का उपयोग करें।
|
||||
|
||||
<figure><img src="../../../images/image (168).png" alt=""><figcaption></figcaption></figure>
|
||||
|
||||
Set the accessKey and the SecretKey of the account you want to use and you can know authenticate against the API endpoint.
|
||||
|
||||
Both methods will generate an **Authorization** **header** such as:
|
||||
जिस खाते का आप उपयोग करना चाहते हैं, उसका accessKey और SecretKey सेट करें और आप API endpoint के खिलाफ प्रमाणित कर सकते हैं।
|
||||
|
||||
दोनों विधियाँ एक **Authorization** **header** उत्पन्न करेंगी जैसे:
|
||||
```
|
||||
AWS4-HMAC-SHA256 Credential=AKIAYY7XU6ECUDOTWB7W/20220726/us-east-1/execute-api/aws4_request, SignedHeaders=host;x-amz-date, Signature=9f35579fa85c0d089c5a939e3d711362e92641e8c14cc571df8c71b4bc62a5c2
|
||||
```
|
||||
|
||||
Note that in other cases the **Authorizer** might have been **bad coded** and just sending **anything** inside the **Authorization header** will **allow to see the hidden content**.
|
||||
ध्यान दें कि अन्य मामलों में **Authorizer** को **खराब कोडित** किया गया हो सकता है और **Authorization header** के अंदर **कुछ भी** भेजने से **छिपी हुई सामग्री** को **देखने की अनुमति** मिलेगी।
|
||||
|
||||
### Request Signing Using Python
|
||||
|
||||
```python
|
||||
|
||||
pip install requests
|
||||
@@ -193,111 +184,104 @@ response = requests.get(url, auth=awsauth)
|
||||
print(response.text)
|
||||
|
||||
```
|
||||
|
||||
### Custom Lambda Authorizer
|
||||
|
||||
It's possible to use a lambda that based in a given token will **return an IAM policy** indicating if the user is **authorized to call the API endpoint**.\
|
||||
You can set each resource method that will be using the authoriser.
|
||||
यह संभव है कि एक लैम्ब्डा का उपयोग किया जाए जो एक दिए गए टोकन के आधार पर **IAM नीति** लौटाएगा जो यह दर्शाती है कि क्या उपयोगकर्ता **API एंडपॉइंट को कॉल करने के लिए अधिकृत है**।\
|
||||
आप प्रत्येक संसाधन विधि को सेट कर सकते हैं जो लेखक का उपयोग करेगी।
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Lambda Authorizer Code Example</summary>
|
||||
|
||||
```python
|
||||
import json
|
||||
|
||||
def lambda_handler(event, context):
|
||||
token = event['authorizationToken']
|
||||
method_arn = event['methodArn']
|
||||
token = event['authorizationToken']
|
||||
method_arn = event['methodArn']
|
||||
|
||||
if not token:
|
||||
return {
|
||||
'statusCode': 401,
|
||||
'body': 'Unauthorized'
|
||||
}
|
||||
if not token:
|
||||
return {
|
||||
'statusCode': 401,
|
||||
'body': 'Unauthorized'
|
||||
}
|
||||
|
||||
try:
|
||||
# Replace this with your own token validation logic
|
||||
if token == "your-secret-token":
|
||||
return generate_policy('user', 'Allow', method_arn)
|
||||
else:
|
||||
return generate_policy('user', 'Deny', method_arn)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return {
|
||||
'statusCode': 500,
|
||||
'body': 'Internal Server Error'
|
||||
}
|
||||
try:
|
||||
# Replace this with your own token validation logic
|
||||
if token == "your-secret-token":
|
||||
return generate_policy('user', 'Allow', method_arn)
|
||||
else:
|
||||
return generate_policy('user', 'Deny', method_arn)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return {
|
||||
'statusCode': 500,
|
||||
'body': 'Internal Server Error'
|
||||
}
|
||||
|
||||
def generate_policy(principal_id, effect, resource):
|
||||
policy = {
|
||||
'principalId': principal_id,
|
||||
'policyDocument': {
|
||||
'Version': '2012-10-17',
|
||||
'Statement': [
|
||||
{
|
||||
'Action': 'execute-api:Invoke',
|
||||
'Effect': effect,
|
||||
'Resource': resource
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
return policy
|
||||
policy = {
|
||||
'principalId': principal_id,
|
||||
'policyDocument': {
|
||||
'Version': '2012-10-17',
|
||||
'Statement': [
|
||||
{
|
||||
'Action': 'execute-api:Invoke',
|
||||
'Effect': effect,
|
||||
'Resource': resource
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
return policy
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
Call it with something like:
|
||||
इसे कुछ इस तरह कॉल करें:
|
||||
|
||||
<pre class="language-bash" data-overflow="wrap"><code class="lang-bash"><strong>curl "https://jhhqafgh6f.execute-api.eu-west-1.amazonaws.com/prod/custom_auth" -H 'Authorization: your-secret-token'
|
||||
</strong></code></pre>
|
||||
|
||||
> [!WARNING]
|
||||
> Depending on the Lambda code, this authorization might be vulnerable
|
||||
> Lambda कोड के आधार पर, यह प्राधिकरण कमजोर हो सकता है
|
||||
|
||||
Note that if a **deny policy is generated and returned** the error returned by API Gateway is: `{"Message":"User is not authorized to access this resource with an explicit deny"}`
|
||||
ध्यान दें कि यदि एक **deny policy उत्पन्न और लौटाई जाती है** तो API Gateway द्वारा लौटाई गई त्रुटि है: `{"Message":"User is not authorized to access this resource with an explicit deny"}`
|
||||
|
||||
This way you could **identify this authorization** being in place.
|
||||
इस तरह आप **इस प्राधिकरण** की पहचान कर सकते हैं।
|
||||
|
||||
### Required API Key
|
||||
### आवश्यक API कुंजी
|
||||
|
||||
It's possible to set API endpoints that **require a valid API key** to contact it.
|
||||
यह संभव है कि API अंत बिंदुओं को सेट किया जाए जो **एक मान्य API कुंजी** की आवश्यकता हो।
|
||||
|
||||
<figure><img src="../../../images/image (88).png" alt=""><figcaption></figcaption></figure>
|
||||
|
||||
It's possible to generate API keys in the API Gateway portal and even set how much it can be used (in terms of requests per second and in terms of requests per month).
|
||||
API Gateway पोर्टल में API कुंजी उत्पन्न करना संभव है और यहां तक कि यह भी सेट करना कि इसे कितनी बार उपयोग किया जा सकता है (प्रति सेकंड अनुरोधों और प्रति माह अनुरोधों के संदर्भ में)।
|
||||
|
||||
To make an API key work, you need to add it to a **Usage Plan**, this usage plan mus be added to the **API Stage** and the associated API stage needs to have a configured a **method throttling** to the **endpoint** requiring the API key:
|
||||
API कुंजी को काम करने के लिए, आपको इसे एक **Usage Plan** में जोड़ना होगा, यह उपयोग योजना **API Stage** में जोड़ी जानी चाहिए और संबंधित API स्टेज को **endpoint** के लिए एक **method throttling** कॉन्फ़िगर किया जाना चाहिए जो API कुंजी की आवश्यकता करता है:
|
||||
|
||||
<figure><img src="../../../images/image (198).png" alt=""><figcaption></figcaption></figure>
|
||||
|
||||
## Unauthenticated Access
|
||||
## अनधिकृत पहुंच
|
||||
|
||||
{{#ref}}
|
||||
../aws-unauthenticated-enum-access/aws-api-gateway-unauthenticated-enum.md
|
||||
{{#endref}}
|
||||
|
||||
## Privesc
|
||||
## प्रिवेस्क
|
||||
|
||||
{{#ref}}
|
||||
../aws-privilege-escalation/aws-apigateway-privesc.md
|
||||
{{#endref}}
|
||||
|
||||
## Post Exploitation
|
||||
## पोस्ट एक्सप्लोइटेशन
|
||||
|
||||
{{#ref}}
|
||||
../aws-post-exploitation/aws-api-gateway-post-exploitation.md
|
||||
{{#endref}}
|
||||
|
||||
## Persistence
|
||||
## स्थिरता
|
||||
|
||||
{{#ref}}
|
||||
../aws-persistence/aws-api-gateway-persistence.md
|
||||
{{#endref}}
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user