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

feat: add websocket support for c2 detection #29150

Merged
merged 9 commits into from
Dec 12, 2024
Merged

Conversation

AugmentedMode
Copy link
Contributor

@AugmentedMode AugmentedMode commented Dec 12, 2024

Description

This pull request adds WebSocket support to the MetaMask extension's phishing detection functionality. Scammers have started using WebSocket connections for command-and-control (C2) operations to bypass traditional HTTP-based phishing detection. This PR allows the extension to intercept and block WebSocket handshake requests (ws:// and wss://) in addition to HTTP/HTTPS requests.

The key changes include:

  1. Adding WebSocket schemes (ws://*/* and wss://*/*) to the urls filter in background.js.
  2. Updating the manifest.json to include WebSocket permissions in the host_permissions field.

This ensures that malicious WebSocket connections can be detected and blocked.

Open in GitHub Codespaces

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/3788

Manual testing steps

  1. Navigate to example.com
  2. Initiate a WebSocket connection to a known safe domain (e.g., wss://example.com) and verify it works as expected by going to the console via right clicking and hitting inspect. Then type into the console new WebSocket("https://example.com/")
  3. Attempt a WebSocket connection to a domain flagged as phishing, and verify the connection is blocked and appropriate warnings are displayed by going to the console via right clicking and hitting inspect. Then type into the console new WebSocket("https://walietconnectapi.com/")

Screenshots/Recordings

Before

No support for detecting WebSocket phishing connections.


After

WebSocket phishing connections are detected and blocked during the handshake phase.

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

AugmentedMode and others added 5 commits December 12, 2024 09:02
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

This pull request adds WebSocket support to the MetaMask extension's
phishing detection functionality. Scammers have started using WebSocket
connections for command-and-control (C2) operations to bypass
traditional HTTP-based phishing detection. This PR allows the extension
to intercept and block WebSocket handshake requests (`ws://` and
`wss://`) in addition to HTTP/HTTPS requests.

The key changes include:
1. Adding WebSocket schemes (`ws://*/*` and `wss://*/*`) to the `urls`
filter in `background.js`.
2. Updating the `manifest.json` to include WebSocket permissions in the
`host_permissions` field.

This ensures that malicious WebSocket connections can be detected and
blocked.

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28782?quickstart=1)

Fixes: MetaMask/MetaMask-planning#3788

1. Navigate to `example.com`
2. Initiate a WebSocket connection to a known safe domain (e.g.,
`wss://example.com`) and verify it works as expected by going to the
`console` via right clicking and hitting inspect. Then type into the
console `new WebSocket("https://example.com/")`
3. Attempt a WebSocket connection to a domain flagged as phishing, and
verify the connection is blocked and appropriate warnings are displayed
by going to the `console` via right clicking and hitting inspect. Then
type into the console `new WebSocket("https://walietconnectapi.com/")`

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

No support for detecting WebSocket phishing connections.

---

WebSocket phishing connections are detected and blocked during the
handshake phase.

<!-- [screenshots/recordings] -->

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**


This pull request adds WebSocket support to the MetaMask extension's
phishing detection functionality. Scammers have started using WebSocket
connections for command-and-control (C2) operations to bypass
traditional HTTP-based phishing detection. This PR allows the extension
to intercept and block WebSocket handshake requests (`ws://` and
`wss://`) in addition to HTTP/HTTPS requests.

The key changes include:
1. Adding WebSocket schemes (`ws://*/*` and `wss://*/*`) to the `urls`
filter in `background.js`.
2. Updating the `manifest.json` to include WebSocket permissions in the
`host_permissions` field.

This ensures that malicious WebSocket connections can be detected and
blocked.


<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28782?quickstart=1)

## **Related issues**

Fixes: MetaMask/MetaMask-planning#3788

## **Manual testing steps**

1. Navigate to `example.com`
2. Initiate a WebSocket connection to a known safe domain (e.g.,
`wss://example.com`) and verify it works as expected by going to the
`console` via right clicking and hitting inspect. Then type into the
console `new WebSocket("https://example.com/")`
3. Attempt a WebSocket connection to a domain flagged as phishing, and
verify the connection is blocked and appropriate warnings are displayed
by going to the `console` via right clicking and hitting inspect. Then
type into the console `new WebSocket("https://walietconnectapi.com/")`


## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

No support for detecting WebSocket phishing connections.

---

### **After**

WebSocket phishing connections are detected and blocked during the
handshake phase.


<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
@AugmentedMode AugmentedMode requested a review from a team as a code owner December 12, 2024 17:23
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-product-safety Push issues to Product Safety team label Dec 12, 2024
@AugmentedMode AugmentedMode self-assigned this Dec 12, 2024
@AugmentedMode AugmentedMode changed the title Fix/c2 websockets eat: add websocket support for c2 detection Dec 12, 2024
@AugmentedMode AugmentedMode changed the title eat: add websocket support for c2 detection feat: add websocket support for c2 detection Dec 12, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [2392de9]
Page Load Metrics (1906 ± 84 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint25522451730508244
domContentLoaded15832216186817182
load16152303190617484
domInteractive26111482311
backgroundConnect1084342110
firstReactRender1777362210
getState67421199
initialActions01000
loadScripts11601709141814168
setupStore76620199
uiStartup18602556216619393
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -14 Bytes (-0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [9562bac]
Page Load Metrics (1648 ± 68 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint27018771569327157
domContentLoaded14131882162614570
load14501887164814268
domInteractive228240168
backgroundConnect85824168
firstReactRender1580382512
getState45012126
initialActions01000
loadScripts10221394120211455
setupStore65617178
uiStartup15962126185216077
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 24 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@dabossdana

This comment was marked as spam.

Gudahtt
Gudahtt previously approved these changes Dec 12, 2024
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

mindofmar
mindofmar previously approved these changes Dec 12, 2024
test/e2e/helpers.js Outdated Show resolved Hide resolved
@AugmentedMode AugmentedMode dismissed stale reviews from mindofmar and Gudahtt via 3546487 December 12, 2024 20:41
@metamaskbot
Copy link
Collaborator

Builds ready [3546487]
Page Load Metrics (1697 ± 110 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint147525591704228109
domContentLoaded146625481671230111
load147525571697228110
domInteractive2499462311
backgroundConnect972302010
firstReactRender1570322110
getState46512136
initialActions01000
loadScripts10732068126820799
setupStore663212110
uiStartup171828641922248119
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 24 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@AugmentedMode AugmentedMode added this pull request to the merge queue Dec 12, 2024
Merged via the queue into main with commit 16d1693 Dec 12, 2024
77 checks passed
@AugmentedMode AugmentedMode deleted the fix/c2-websockets branch December 12, 2024 21:50
@github-actions github-actions bot locked and limited conversation to collaborators Dec 12, 2024
@metamaskbot metamaskbot added the release-12.10.2 Issue or pull request that will be included in release 12.10.2 label Dec 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.10.2 Issue or pull request that will be included in release 12.10.2 team-product-safety Push issues to Product Safety team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants