AWS - API Gateway Unauthenticated Enum
Reading time: 4 minutes
tip
AWS 해킹 배우기 및 연습하기:
HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기:
HackTricks Training GCP Red Team Expert (GRTE)
Azure 해킹 배우기 및 연습하기:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks 지원하기
- 구독 계획 확인하기!
- **💬 Discord 그룹 또는 텔레그램 그룹에 참여하거나 Twitter 🐦 @hacktricks_live를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.
API Invoke bypass
토크 Attack Vectors for APIs Using AWS API Gateway Lambda Authorizers - Alexandre & Leonardo에 따르면, Lambda Authorizers는 using IAM syntax로 구성하여 API 엔드포인트를 invoke할 수 있는 권한을 부여할 수 있습니다. 이는 from the docs:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Permission",
"Action": ["execute-api:Execution-operation"],
"Resource": [
"arn:aws:execute-api:region:account-id:api-id/stage/METHOD_HTTP_VERB/Resource-path"
]
}
]
}
The problem with this way to give permissions to invoke endpoints is that the "*" implies "anything" and there is no more regex syntax supported.
Some examples:
- A rule such as
arn:aws:execute-apis:sa-east-1:accid:api-id/prod/*/dashboard/*in order to give each user access to/dashboard/user/{username}will give them access to other routes such as/admin/dashboard/createAdminfor example.
warning
Note that "*" doesn't stop expanding with slashes, therefore, if you use "*" in api-id for example, it could also indicate "any stage" or "any method" as long as the final regex is still valid.
So arn:aws:execute-apis:sa-east-1:accid:*/prod/GET/dashboard/*
Can validate a post request to test stage to the path /prod/GET/dashboard/admin for example.
엔드포인트 호출 권한을 이렇게 부여할 때의 문제는 "*"가 "무엇이든"을 의미하며 정규표현식(regex) 문법을 더 이상 지원하지 않는다는 것입니다.
예시:
- 각각의 사용자에게
/dashboard/user/{username}접근을 허용하기 위해arn:aws:execute-apis:sa-east-1:accid:api-id/prod/*/dashboard/*같은 규칙을 사용하면, 예를 들어/admin/dashboard/createAdmin같은 다른 경로에도 접근이 허용됩니다.
warning
"*"는 슬래시로 확장을 멈추지 않습니다, 따라서 예를 들어 api-id에 "*"를 사용하면 최종 표현식이 여전히 유효한 한 "any stage"나 "any method"를 나타낼 수도 있습니다.
따라서 arn:aws:execute-apis:sa-east-1:accid:*/prod/GET/dashboard/*
는 예를 들어 /prod/GET/dashboard/admin 경로의 test 스테이지에 대한 POST 요청을 유효한 것으로 판단할 수 있습니다.
허용하려는 접근을 항상 명확히 정의하고, 부여된 권한으로 다른 시나리오가 가능한지 확인해야 합니다.
자세한 정보는 docs를 참고하고, authorizer를 구현하는 코드는 this official aws github에서 확인할 수 있습니다.
IAM Policy Injection
In the same talk it's exposed the fact that if the code is using user input to generate the IAM policies, wildcards (and others such as "." or specific strings) can be included in there with the goal of bypassing restrictions.
공개 URL 템플릿
https://{random_id}.execute-api.{region}.amazonaws.com/{user_provided}
공개 API Gateway URL에서 계정 ID 가져오기
S3 buckets, Data Exchange 및 Lambda URLs gateways와 마찬가지로, 공개 API Gateway URL에서 aws:ResourceAccount 정책 조건 키를 악용하여 계정 ID를 찾아낼 수 있습니다. 이는 정책의 aws:ResourceAccount 섹션에서 와일드카드를 악용해 계정 ID를 한 글자씩 찾아내는 방식으로 수행됩니다.
이 기법은 태그 키를 알고 있을 경우 태그 값도 얻을 수 있습니다(기본적으로 흥미로운 몇 가지가 있습니다).
자세한 내용은 original research 및 이 익스플로잇을 자동화하는 도구 conditional-love를 참고하세요.
tip
AWS 해킹 배우기 및 연습하기:
HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기:
HackTricks Training GCP Red Team Expert (GRTE)
Azure 해킹 배우기 및 연습하기:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks 지원하기
- 구독 계획 확인하기!
- **💬 Discord 그룹 또는 텔레그램 그룹에 참여하거나 Twitter 🐦 @hacktricks_live를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.
HackTricks Cloud