AWS - Federation Abuse

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

HackTricks를 지원하는 다른 방법:

SAML

SAML에 대한 정보는 다음을 확인하세요:

SAML을 통한 Identity Federation을 구성하려면 이름SAML 구성(엔드포인트, 공개 키가 있는 인증서)을 포함한 메타데이터 XML을 제공하면 됩니다.

OIDC - Github Actions 남용

Identity 공급자로 github action을 추가하려면 다음을 수행하세요:

  1. _공급자 유형_으로 OpenID Connect를 선택합니다.

  2. _공급자 URL_에 https://token.actions.githubusercontent.com을 입력합니다.

  3. _Get thumbprint_를 클릭하여 공급자의 썸프린트를 가져옵니다.

  4. _Audience_에 sts.amazonaws.com을 입력합니다.

  5. github action이 필요로 하는 권한과 공급자를 신뢰하는 신뢰 정책을 가진 새 역할을 생성합니다. 예시:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::0123456789:oidc-provider/token.actions.githubusercontent.com" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { "token.actions.githubusercontent.com:sub": [ "repo:ORG_OR_USER_NAME/REPOSITORY:pull_request", "repo:ORG_OR_USER_NAME/REPOSITORY:ref:refs/heads/main" ], "token.actions.githubusercontent.com:aud": "sts.amazonaws.com" } } } ] }

6. 이전 정책에서 특정 **트리거**로 **조직**의 **저장소**의 **브랜치**만 허용되었음을 확인하세요.
7. github action이 **가장하게 될** **역할**의 **ARN**은 github action이 알아야 하는 "비밀"이므로 **환경** 내의 **비밀**에 저장하세요.
8. 마지막으로 github action을 사용하여 워크플로우에서 사용할 AWS 자격 증명을 구성하세요.
```yaml
name: 'test AWS Access'

# The workflow should only trigger on pull requests to the main branch
on:
pull_request:
branches:
- main

# Required to get the ID Token that will be used for OIDC
permissions:
id-token: write
contents: read # needed for private repos to checkout

jobs:
aws:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: eu-west-1
role-to-assume: ${{ secrets.READ_ROLE }}
role-session-name: OIDCSession

- run: aws sts get-caller-identity
shell: bash

OIDC - EKS 남용

In this section, we will discuss how to abuse the OpenID Connect (OIDC) authentication mechanism in Amazon Elastic Kubernetes Service (EKS) to gain unauthorized access to resources.

이 섹션에서는 Amazon Elastic Kubernetes Service (EKS)에서 OpenID Connect (OIDC) 인증 메커니즘을 남용하여 무단으로 리소스에 액세스하는 방법에 대해 논의합니다.

Introduction

소개

Amazon EKS allows you to use OIDC to authenticate users and applications to your Kubernetes cluster. OIDC is an open standard for authentication that allows users to authenticate to multiple applications using a single set of credentials. EKS uses OIDC to authenticate users and applications by leveraging AWS Identity and Access Management (IAM) roles.

Amazon EKS는 OIDC를 사용하여 사용자 및 애플리케이션을 Kubernetes 클러스터에 인증할 수 있도록 합니다. OIDC는 사용자가 단일 자격 증명 세트를 사용하여 여러 애플리케이션에 인증할 수 있는 인증을 위한 개방형 표준입니다. EKS는 AWS Identity and Access Management (IAM) 역할을 활용하여 사용자 및 애플리케이션을 인증하기 위해 OIDC를 사용합니다.

Exploiting OIDC in EKS

EKS에서 OIDC 악용하기

To exploit OIDC in EKS, an attacker needs to perform the following steps:

EKS에서 OIDC를 악용하기 위해 공격자는 다음 단계를 수행해야 합니다:

  1. Identify the target EKS cluster and the associated IAM roles.

    대상 EKS 클러스터와 관련된 IAM 역할을 식별합니다.

  2. Enumerate the permissions and policies associated with the IAM roles.

    IAM 역할과 관련된 권한 및 정책을 열거합니다.

  3. Identify the OIDC provider URL and the client ID associated with the EKS cluster.

    EKS 클러스터와 관련된 OIDC 제공자 URL 및 클라이언트 ID를 식별합니다.

  4. Register a malicious application with the OIDC provider using the client ID.

    클라이언트 ID를 사용하여 OIDC 제공자에 악성 애플리케이션을 등록합니다.

  5. Obtain an authorization code by redirecting the victim to the malicious application.

    피해자를 악성 애플리케이션으로 리디렉션하여 인가 코드를 획득합니다.

  6. Exchange the authorization code for an access token and ID token.

    인가 코드를 액세스 토큰 및 ID 토큰으로 교환합니다.

  7. Use the obtained tokens to authenticate and gain unauthorized access to resources in the EKS cluster.

    획득한 토큰을 사용하여 EKS 클러스터의 리소스에 인증하고 무단으로 액세스합니다.

Mitigation

완화 방법

To mitigate the abuse of OIDC in EKS, consider the following measures:

EKS에서 OIDC 남용을 완화하기 위해 다음 조치를 고려해보세요:

  • Regularly review and audit the IAM roles associated with your EKS cluster to ensure they have the least privileges necessary.

    EKS 클러스터와 관련된 IAM 역할을 정기적으로 검토하고 감사하여 필요한 최소한의 권한만 가지도록 합니다.

  • Implement strong authentication mechanisms, such as multi-factor authentication (MFA), to protect the OIDC provider.

    OIDC 제공자를 보호하기 위해 다중 인증 (MFA)와 같은 강력한 인증 메커니즘을 구현합니다.

  • Regularly monitor and analyze the logs and events generated by the OIDC provider and the EKS cluster for any suspicious activities.

    OIDC 제공자 및 EKS 클러스터에서 생성된 로그 및 이벤트를 정기적으로 모니터링하고 분석하여 의심스러운 활동을 감지합니다.

  • Educate users and administrators about the risks and best practices associated with OIDC and EKS security.

    OIDC 및 EKS 보안과 관련된 위험 및 모범 사례에 대해 사용자 및 관리자에게 교육을 제공합니다.

# Crate an EKS cluster (~10min)
eksctl create cluster --name demo --fargate
# Create an Identity Provider for an EKS cluster
eksctl utils associate-iam-oidc-provider --cluster Testing --approve

OIDC 공급자를 생성하는 것은 EKS 클러스터에서 간단히 수행할 수 있습니다. 클러스터의 OIDC URL새로운 Open ID Identity 공급자로 설정하기만 하면 됩니다. 이는 일반적인 기본 정책입니다:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::123456789098:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/20C159CDF6F2349B68846BEC03BE031B"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"oidc.eks.us-east-1.amazonaws.com/id/20C159CDF6F2349B68846BEC03BE031B:aud": "sts.amazonaws.com"
}
}
}
]
}

이 정책은 id20C159CDF6F2349B68846BEC03BE031BEKS 클러스터만 역할을 가질 수 있다고 올바르게 나타내고 있습니다. 그러나 어떤 서비스 계정이 그 역할을 가질 수 있는지를 나타내지 않고 있으므로, 웹 신원 토큰을 가진 아무 서비스 계정이 역할을 가질 수 있게 됩니다.

어떤 서비스 계정이 역할을 가질 수 있는지를 지정하기 위해서는 서비스 계정 이름이 지정된 조건을 지정해야 합니다. 다음과 같이:

"oidc.eks.region-code.amazonaws.com/id/20C159CDF6F2349B68846BEC03BE031B:sub": "system:serviceaccount:default:my-service-account",

참고 자료

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

HackTricks를 지원하는 다른 방법:

最終更新