AWS - IAM & STS Unauthenticated Enum

HackTricksをサポートする

アカウント内のロールとユーザー名を列挙する

ロールのブルートフォース

この技術はもう機能しません。ロールが存在するかどうかにかかわらず、常にこのエラーが表示されます:

An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:iam::947247140022:user/testenv is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::429217632764:role/account-balanceasdas

これを実行してテストできます

aws sts assume-role --role-arn arn:aws:iam::412345678909:role/superadmin --role-session-name s3-access-example

必要な権限なしにロールを引き受けようとすると、AWSエラーメッセージが表示されます。たとえば、無許可の場合、AWSは次のように返すことがあります:

An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:iam::012345678901:user/MyUser is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::111111111111:role/aws-service-role/rds.amazonaws.com/AWSServiceRoleForRDS

このメッセージはロールの存在を確認しますが、そのロールのアサムポリシーがあなたのアサンプションを許可していないことを示しています。対照的に、存在しないロールをアサムしようとすると異なるエラーが発生します:

An error occurred (AccessDenied) when calling the AssumeRole operation: Not authorized to perform sts:AssumeRole

興味深いことに、既存のロールと存在しないロールを区別するこの方法は、異なるAWSアカウント間でも適用可能です。有効なAWSアカウントIDとターゲットワードリストを使用することで、アカウント内に存在するロールを列挙することができ、固有の制限に直面することはありません。

このスクリプトを使用して潜在的なプリンシパルを列挙することができます。

信頼ポリシー: クロスアカウントロールとユーザーのブルートフォース

IAMロールの信頼ポリシーを構成または更新することは、そのロールを引き受けることが許可されているAWSリソースまたはサービスを定義し、一時的な資格情報を取得することを含みます。ポリシー内で指定されたリソースが存在する場合、信頼ポリシーは正常に保存されます。しかし、リソースが存在しない場合、エラーが生成され、無効なプリンシパルが提供されたことを示します。

そのリソースでは、クロスアカウントロールまたはユーザーを指定することができます:

  • arn:aws:iam::acc_id:role/role_name

  • arn:aws:iam::acc_id:user/user_name

これはポリシーの例です:

{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Principal":
{
"AWS":"arn:aws:iam::216825089941:role\/Test"
},
"Action":"sts:AssumeRole"
}
]
}

GUI

存在しないロールを使用した場合に見つかるエラーです。ロール存在する場合、ポリシーはエラーなしで保存されます。(エラーは更新用ですが、作成時にも機能します)

CLI

### You could also use: aws iam update-assume-role-policy
# When it works
aws iam create-role --role-name Test-Role --assume-role-policy-document file://a.json
{
"Role": {
"Path": "/",
"RoleName": "Test-Role",
"RoleId": "AROA5ZDCUJS3DVEIYOB73",
"Arn": "arn:aws:iam::947247140022:role/Test-Role",
"CreateDate": "2022-05-03T20:50:04Z",
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::316584767888:role/account-balance"
},
"Action": [
"sts:AssumeRole"
]
}
]
}
}
}

# When it doesn't work
aws iam create-role --role-name Test-Role2 --assume-role-policy-document file://a.json
An error occurred (MalformedPolicyDocument) when calling the CreateRole operation: Invalid principal in policy: "AWS":"arn:aws:iam::316584767888:role/account-balanceefd23f2"

You can automate this process with https://github.com/carlospolop/aws_tools

  • bash unauth_iam.sh -t user -i 316584767888 -r TestRole -w ./unauth_wordlist.txt

Our using Pacu:

  • run iam__enum_users --role-name admin --account-id 229736458923 --word-list /tmp/names.txt

  • run iam__enum_roles --role-name admin --account-id 229736458923 --word-list /tmp/names.txt

  • The admin role used in the example is a role in your account to by impersonated by pacu to create the policies it needs to create for the enumeration

Privesc

役割が不適切に構成されており、誰でもそれを引き受けることができる場合:

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

The attacker could just assume it.

第三者 OIDC フェデレーション

Imagine that you manage to read a Github Actions workflow that is accessing a role inside AWS. This trust might give access to a role with the following trust policy:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::<acc_id>:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
}
}
}
]
}

この信頼ポリシーは正しいかもしれませんが、より多くの条件が欠けているため、信頼しないべきです。 これは、前のロールがGithub Actionsの誰でも引き受けることができるからです!条件には、組織名、リポジトリ名、環境、ブランチなどの他の要素も指定する必要があります...

もう一つの潜在的な誤設定は、次のような条件を追加することです:

"StringLike": {
"token.actions.githubusercontent.com:sub": "repo:org_name*:*"
}

注意してください コロン (:) の前の ワイルドカード (*)。 org_name1 のような組織を作成し、Github Action から ロールを引き受ける ことができます。

参考文献

HackTricksをサポートする

Last updated