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

kbailey: rule for phished okta session #500

Merged
merged 35 commits into from
Oct 31, 2023
Merged

Conversation

k-bailey
Copy link
Contributor

Background

This rule detects two different devices using the same Okta session. Using tools like Evilginx2, attackers can phish session cookies, effectively bypassing non-FIDO2 MFA devices. When this occurs, the user and attacker use the same session token. This detection takes advantage of that abnormality. This attack vector has recently become one of the most popular initial access vectors for attackers.

To determine if multiple devices are using the same session, this rule uses two data points, the ASN of the request and a fuzzy string match of the user agents. We implement a fuzzing string match in this situation because it is possible in some instances for a session to persist across a browser upgrade, causing false positives. The sensitivity of the match can be adjusted in the rule.

Changes

  • Rule for detecting a single session being used from multiple locations.
  • Config file with tests
  • Updated the pipfile to include two packages used for fuzzy string matching (leveraging the Levenshtein distance algorithm)

Testing

  • make fmt/lint/test

@k-bailey k-bailey requested review from a team September 16, 2022 14:34
Copy link
Contributor

@edyesed edyesed left a comment

Choose a reason for hiding this comment

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

holding block for now

Copy link
Contributor

@edyesed edyesed left a comment

Choose a reason for hiding this comment

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

I think that in the current state, we'll only add the session to the kv_table if there are zero entries for the item already. I also suspect that we should user a counter vs string set to stash the count.

rules/okta_rules/okta_potentially_stolen_session.py Outdated Show resolved Hide resolved
rules/okta_rules/okta_potentially_stolen_session.py Outdated Show resolved Hide resolved
rules/okta_rules/okta_potentially_stolen_session.py Outdated Show resolved Hide resolved
rules/okta_rules/okta_potentially_stolen_session.py Outdated Show resolved Hide resolved
Copy link
Contributor

@jacknagz jacknagz left a comment

Choose a reason for hiding this comment

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

This is so cool 🎉 A few comments but stoked to get this one out!

[prev_ua] = [x for x in PREVIOUS_SESSION if "user_agent:" in x] or ["prev_ua_not_found"]
prev_ua = prev_ua.split("_agent:")[1]

diff_ratio = SequenceMatcher(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to send this as alert context? It'd be super interesting and helpful for tuning.

Copy link
Contributor

Choose a reason for hiding this comment

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

It may also be great to just include this as a helper function.

Copy link
Contributor Author

@k-bailey k-bailey Sep 22, 2022

Choose a reason for hiding this comment

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

Will investigate the helper function. That is a good point.

re: alert context -- It is returned. On line 78 I add the diff ratio to the PREVIOUS_SESSION set (I figured this would be relevant for adjusting the ratio when tuning false positives) and then line 93 appends the previous session info to the default Okta alert context.

rules/okta_rules/okta_potentially_stolen_session.py Outdated Show resolved Hide resolved
@zacbrown zacbrown removed the request for review from a team May 31, 2023 20:24
Copy link
Contributor

@egibs egibs left a comment

Choose a reason for hiding this comment

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

Chatted with @arielkr256 about this a bit today -- everything looks good.

@egibs egibs merged commit 427c07c into main Oct 31, 2023
1 check passed
@egibs egibs deleted the kbailey-okta-stolen-session-cookie branch October 31, 2023 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants