mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-08 19:30:51 -08:00
Translated ['src/README.md', 'src/banners/hacktricks-training.md', 'src/
This commit is contained in:
@@ -4,40 +4,39 @@
|
||||
|
||||
## API Gateway
|
||||
|
||||
### Basic Information
|
||||
### Grundlegende Informationen
|
||||
|
||||
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 ist ein umfassender Dienst, der von Amazon Web Services (AWS) angeboten wird und für Entwickler konzipiert ist, um **APIs in großem Maßstab zu erstellen, zu veröffentlichen und zu überwachen**. Es fungiert als Einstiegspunkt zu einer Anwendung und ermöglicht es Entwicklern, einen Rahmen von Regeln und Verfahren festzulegen. Dieser Rahmen regelt den Zugriff externer Benutzer auf bestimmte Daten oder Funktionen innerhalb der Anwendung.
|
||||
|
||||
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 ermöglicht es Ihnen, **zu definieren, wie Anfragen an Ihre APIs behandelt werden sollen**, und es kann benutzerdefinierte API-Endpunkte mit spezifischen Methoden (z. B. GET, POST, PUT, DELETE) und Ressourcen erstellen. Es kann auch Client-SDKs (Software Development Kits) generieren, um es Entwicklern zu erleichtern, Ihre APIs aus ihren Anwendungen heraus aufzurufen.
|
||||
|
||||
### API Gateways Types
|
||||
### API Gateway-Typen
|
||||
|
||||
- **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**: Erstellen Sie latenzarme und kostengünstige REST-APIs mit integrierten Funktionen wie OIDC und OAuth2 sowie nativer CORS-Unterstützung. Funktioniert mit: Lambda, HTTP-Backends.
|
||||
- **WebSocket API**: Erstellen Sie eine WebSocket-API mit persistenten Verbindungen für Echtzeitanwendungen wie Chat-Anwendungen oder Dashboards. Funktioniert mit: Lambda, HTTP, AWS-Diensten.
|
||||
- **REST API**: Entwickeln Sie eine REST-API, bei der Sie die vollständige Kontrolle über die Anfrage und die Antwort sowie über die API-Verwaltungsmöglichkeiten haben. Funktioniert mit: Lambda, HTTP, AWS-Diensten.
|
||||
- **REST API Privat**: Erstellen Sie eine REST-API, die nur von innerhalb eines VPC zugänglich ist.
|
||||
|
||||
### API Gateway Main Components
|
||||
### Hauptkomponenten des API Gateway
|
||||
|
||||
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. **Ressourcen**: In API Gateway sind Ressourcen die Komponenten, die **die Struktur Ihrer API bilden**. Sie repräsentieren **die verschiedenen Pfade oder Endpunkte** Ihrer API und entsprechen den verschiedenen Aktionen, die Ihre API unterstützt. Eine Ressource ist jede Methode (z. B. GET, POST, PUT, DELETE) **innerhalb jedes Pfades** (/, oder /users, oder /user/{id}).
|
||||
2. **Stufen**: Stufen in API Gateway repräsentieren **verschiedene Versionen oder Umgebungen** Ihrer API, wie Entwicklung, Staging oder Produktion. Sie können Stufen verwenden, um **mehrere Versionen Ihrer API gleichzeitig zu verwalten und bereitzustellen**, sodass Sie neue Funktionen oder Fehlerbehebungen testen können, ohne die Produktionsumgebung zu beeinträchtigen. Stufen unterstützen auch **Stufenvariablen**, die Schlüssel-Wert-Paare sind, die verwendet werden können, um das Verhalten Ihrer API basierend auf der aktuellen Stufe zu konfigurieren. Zum Beispiel könnten Sie Stufenvariablen verwenden, um API-Anfragen je nach Stufe an verschiedene Lambda-Funktionen oder andere Backend-Dienste weiterzuleiten.
|
||||
- Die Stufe wird am Anfang der URL des API Gateway-Endpunkts angezeigt.
|
||||
3. **Autorisierer**: Autorisierer in API Gateway sind verantwortlich für **die Kontrolle des Zugriffs auf Ihre API**, indem sie die Identität des Anrufers überprüfen, bevor sie die Anfrage zulassen. Sie können **AWS Lambda-Funktionen** als benutzerdefinierte Autorisierer verwenden, was es Ihnen ermöglicht, Ihre eigene Authentifizierungs- und Autorisierungslogik zu implementieren. Wenn eine Anfrage eingeht, übergibt API Gateway das Autorisierungstoken der Anfrage an den Lambda-Autorisierer, der das Token verarbeitet und eine IAM-Richtlinie zurückgibt, die bestimmt, welche Aktionen der Anrufer ausführen darf. API Gateway unterstützt auch **eingebaute Autorisierer**, wie **AWS Identity and Access Management (IAM)** und **Amazon Cognito**.
|
||||
4. **Ressourcenrichtlinie**: Eine Ressourcenrichtlinie in API Gateway ist ein JSON-Dokument, das **die Berechtigungen für den Zugriff auf Ihre API definiert**. Sie ähnelt einer IAM-Richtlinie, ist jedoch speziell auf API Gateway zugeschnitten. Sie können eine Ressourcenrichtlinie verwenden, um zu steuern, wer auf Ihre API zugreifen kann, welche Methoden sie aufrufen können und von welchen IP-Adressen oder VPCs sie sich verbinden können. **Ressourcenrichtlinien können in Kombination mit Autorisierern verwendet werden**, um eine feingranulare Zugriffskontrolle für Ihre API bereitzustellen.
|
||||
- Um die Wirkung zu erzielen, muss die API **nach der Änderung der Ressourcenrichtlinie erneut bereitgestellt werden**.
|
||||
|
||||
### Logging
|
||||
### Protokollierung
|
||||
|
||||
By default, **CloudWatch Logs** are **off**, **Access Logging** is **off**, and **X-Ray tracing** is also **off**.
|
||||
Standardmäßig sind **CloudWatch Logs** **deaktiviert**, **Zugriffsprotokollierung** ist **deaktiviert**, und **X-Ray-Tracking** ist ebenfalls **deaktiviert**.
|
||||
|
||||
### 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.**
|
||||
> Beachten Sie, dass in beiden AWS-APIs zur Auflistung von Ressourcen (**`apigateway`** und **`apigatewayv2`**) die einzige Berechtigung, die Sie benötigen, und die einzige lesbare Berechtigung, die gewährt werden kann, **`apigateway:GET`** ist. Damit können Sie **alles auflisten.**
|
||||
|
||||
{{#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
|
||||
## Verschiedene Berechtigungen zum Zugriff auf API Gateway-Endpunkte
|
||||
|
||||
### Resource Policy
|
||||
### Ressourcenrichtlinie
|
||||
|
||||
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.
|
||||
Es ist möglich, Ressourcenrichtlinien zu verwenden, um festzulegen, wer die API-Endpunkte aufrufen kann.\
|
||||
Im folgenden Beispiel sehen Sie, dass die **angegebene IP nicht aufrufen kann** den Endpunkt `/resource_policy` über GET.
|
||||
|
||||
<figure><img src="../../../images/image (256).png" alt=""><figcaption></figcaption></figure>
|
||||
|
||||
### IAM Authorizer
|
||||
### IAM-Authorizer
|
||||
|
||||
It's possible to set that a methods inside a path (a resource) requires IAM authentication to call it.
|
||||
Es ist möglich festzulegen, dass eine Methode innerhalb eines Pfades (einer Ressource) IAM-Authentifizierung erfordert, um sie aufzurufen.
|
||||
|
||||
<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**.
|
||||
Wenn dies festgelegt ist, erhalten Sie den Fehler `{"message":"Missing Authentication Token"}`, wenn Sie versuchen, den Endpunkt ohne Autorisierung zu erreichen.
|
||||
|
||||
Eine einfache Möglichkeit, das von der Anwendung erwartete Token zu generieren, ist die Verwendung von **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**.
|
||||
Eine andere Möglichkeit besteht darin, den **`Authorization`**-Typ **`AWS Signature`** in **Postman** zu verwenden.
|
||||
|
||||
<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:
|
||||
Setzen Sie den accessKey und den SecretKey des Kontos, das Sie verwenden möchten, und Sie können sich gegen den API-Endpunkt authentifizieren.
|
||||
|
||||
Beide Methoden generieren einen **Authorization**-**header** wie:
|
||||
```
|
||||
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**.
|
||||
Beachten Sie, dass in anderen Fällen der **Authorizer** möglicherweise **schlecht codiert** wurde und das Senden von **irgendetwas** im **Authorization-Header** **erlaubt, den versteckten Inhalt zu sehen**.
|
||||
|
||||
### Request Signing Using Python
|
||||
|
||||
```python
|
||||
|
||||
pip install requests
|
||||
@@ -193,86 +184,83 @@ 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.
|
||||
Es ist möglich, eine Lambda zu verwenden, die basierend auf einem gegebenen Token eine **IAM-Richtlinie zurückgibt**, die angibt, ob der Benutzer **berechtigt ist, den API-Endpunkt aufzurufen**.\
|
||||
Sie können jede Ressourcenmethode festlegen, die den Authorizer verwenden wird.
|
||||
|
||||
<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:
|
||||
Rufen Sie es mit etwas wie auf:
|
||||
|
||||
<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
|
||||
> Abhängig vom Lambda-Code könnte diese Autorisierung anfällig sein
|
||||
|
||||
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"}`
|
||||
Beachten Sie, dass wenn eine **deny policy generiert und zurückgegeben wird**, die von API Gateway zurückgegebene Fehlermeldung lautet: `{"Message":"User is not authorized to access this resource with an explicit deny"}`
|
||||
|
||||
This way you could **identify this authorization** being in place.
|
||||
Auf diese Weise könnten Sie **diese Autorisierung** identifizieren.
|
||||
|
||||
### Required API Key
|
||||
### Erforderlicher API-Schlüssel
|
||||
|
||||
It's possible to set API endpoints that **require a valid API key** to contact it.
|
||||
Es ist möglich, API-Endpunkte festzulegen, die **einen gültigen API-Schlüssel** benötigen, um kontaktiert zu werden.
|
||||
|
||||
<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).
|
||||
Es ist möglich, API-Schlüssel im API Gateway-Portal zu generieren und sogar festzulegen, wie oft sie verwendet werden können (in Bezug auf Anfragen pro Sekunde und in Bezug auf Anfragen pro Monat).
|
||||
|
||||
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:
|
||||
Um einen API-Schlüssel funktionsfähig zu machen, müssen Sie ihn zu einem **Nutzungsplan** hinzufügen, dieser Nutzungsplan muss zur **API-Stufe** hinzugefügt werden und die zugehörige API-Stufe muss eine konfigurierte **Methoden-Drosselung** für den **Endpunkt** haben, der den API-Schlüssel benötigt:
|
||||
|
||||
<figure><img src="../../../images/image (198).png" alt=""><figcaption></figcaption></figure>
|
||||
|
||||
## Unauthenticated Access
|
||||
## Unauthentifizierter Zugriff
|
||||
|
||||
{{#ref}}
|
||||
../aws-unauthenticated-enum-access/aws-api-gateway-unauthenticated-enum.md
|
||||
@@ -284,20 +272,16 @@ To make an API key work, you need to add it to a **Usage Plan**, this usage plan
|
||||
../aws-privilege-escalation/aws-apigateway-privesc.md
|
||||
{{#endref}}
|
||||
|
||||
## Post Exploitation
|
||||
## Post-Exploitation
|
||||
|
||||
{{#ref}}
|
||||
../aws-post-exploitation/aws-api-gateway-post-exploitation.md
|
||||
{{#endref}}
|
||||
|
||||
## Persistence
|
||||
## Persistenz
|
||||
|
||||
{{#ref}}
|
||||
../aws-persistence/aws-api-gateway-persistence.md
|
||||
{{#endref}}
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user