Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Mailgun detector #2679

Merged
merged 1 commit into from
Nov 7, 2024
Merged

Conversation

rgmz
Copy link
Contributor

@rgmz rgmz commented Apr 6, 2024

Description:

This PR implements the following changes to the Mailgun detector:

  1. Adds key- as a keyword, as it's a unique prefix of one token type

  2. Deduplicates matches in a chunk's data

  3. Updates the detector to use tri-state verification

  4. Adds the domain response as extradata

    ✅ Found verified result 🐷🔑
    Detector Type: Mailgun
    Decoder Type: PLAIN
    Raw result: key-3ax6xnjp29jd6fds4gc37jsgvjxtedl0
    Domains: adfewasfdagafdasfdafdf.com (unverified,custom), samples.mailgun.org (ate:active,sandbox)
    Commit: 8b4342e2eb4f56deb646d3c56001c904712deb34
    Email: John Mailgun <[email protected]>
    ...
    
  5. Fixes what appears to be a bug in the verification logic

    This line of code does not seem to do what it the comment claims.

    // If resMatch has "key" prefix, use it as the username for basic auth.
    if strings.HasPrefix(resMatch, "key-") {
    req.SetBasicAuth("api", resMatch)
    } else {
    req.Header.Add("Authorization", fmt.Sprintf("Basic %s", resMatch))
    }

    Mailgun seems to require basic auth for all token tokens. The way this logic is written means that key- tokens will be properly verified, but other types like "Hex" won't be unless they happen to be base64-encoded and 72 characters (so they match the "Original MailGun Token" regex).

    e.g., this is a a base-64 encoded hex key that only gets detected because it happens to match the "Original" pattern.

        Authorization:
        - Basic YXBpOmQwMTViNWNkYjlhNTgzNjg1ZDhkM2ZiMWJlYzBmMjBkLTA3YmM3YjA1LWRhNDgxNmEx
    

    If it was instead found in plain-text like below, it would be skipped.

    mailgun_key = 'd915b5cdb9a583685d8f3fb1bec0f20f-07bc7b05-fa4816a1'
    

    I'm partially convinced that the "Original MailGun Token" is just the hex token base64-encoded.

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

@rgmz rgmz force-pushed the feat/mailgun-extradata branch from 4c53595 to c035557 Compare April 6, 2024 15:34
@rgmz rgmz marked this pull request as ready for review April 6, 2024 15:34
@rgmz rgmz force-pushed the feat/mailgun-extradata branch 4 times, most recently from b5ada5b to 42a8340 Compare April 12, 2024 11:20
@rgmz rgmz force-pushed the feat/mailgun-extradata branch from 42a8340 to e048ee3 Compare April 14, 2024 14:28
@rgmz rgmz force-pushed the feat/mailgun-extradata branch from a625792 to 2946553 Compare May 2, 2024 12:48
@rgmz rgmz force-pushed the feat/mailgun-extradata branch 3 times, most recently from e5ca5fc to a256f43 Compare May 22, 2024 20:02
@rgmz rgmz force-pushed the feat/mailgun-extradata branch 3 times, most recently from 805dcf5 to 062c2c8 Compare May 30, 2024 20:04
@rgmz rgmz force-pushed the feat/mailgun-extradata branch from 062c2c8 to 71da20d Compare June 5, 2024 00:41
@rgmz rgmz force-pushed the feat/mailgun-extradata branch 3 times, most recently from b9efde0 to c62bbe9 Compare June 21, 2024 02:46
@rgmz rgmz force-pushed the feat/mailgun-extradata branch 2 times, most recently from b53eee9 to 867fb34 Compare July 1, 2024 18:36
@rgmz rgmz force-pushed the feat/mailgun-extradata branch from 867fb34 to b9cc3c3 Compare September 13, 2024 11:53
@rgmz rgmz force-pushed the feat/mailgun-extradata branch from b9cc3c3 to cd6d135 Compare October 13, 2024 00:00
@rgmz rgmz force-pushed the feat/mailgun-extradata branch from cd6d135 to 061524f Compare November 7, 2024 00:57
@rgmz rgmz requested a review from a team as a code owner November 7, 2024 00:57
Copy link
Collaborator

@ahrav ahrav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Only took 6 months to get approved. 😢 Sorry about that.

@ahrav ahrav merged commit 034ca35 into trufflesecurity:main Nov 7, 2024
12 checks passed
@rgmz rgmz deleted the feat/mailgun-extradata branch November 7, 2024 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants