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

Add version based detection for CVE-2024-54134 #156

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions agent/exploits/cve_2024_54134.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Agent Asteroid implementation for CVE-2024-54134"""

import re

from packaging import version

from agent import definitions
from agent import exploits_registry
from agent.exploits import webexploit

VULNERABILITY_TITLE = "MALICIOUS PACKAGES FOUND IN COMPROMISED @SOLANA/WEB3.JS LIBRARY"
VULNERABILITY_REFERENCE = "CVE-2024-54134"
VULNERABILITY_DESCRIPTION = """A compromised publish-access account for the @solana/web3.js library allowed attackers to release malicious packages (versions 1.95.6 and 1.95.7).
These packages were modified to steal private key material, potentially draining funds from affected Solana dapps that handle private keys directly"""
RISK_RATING = "HIGH"
MIN_VULNERABLE_VERSION = version.parse("1.95.6")
MAX_VULNERABLE_VERSION = version.parse("1.95.7")
VERSION_PATTERN = re.compile(r"@solana/web3\.js@(\d+\.\d+\.\d+)")


@exploits_registry.register
class CVE202454134Exploit(webexploit.WebExploit):
accept_request = definitions.Request(method="GET", path="/")
check_request = definitions.Request(method="GET", path="/")
accept_pattern = [re.compile("https://unpkg\.com/@solana/web3\.js")]
vuln_ranges = [
definitions.VulnRange(MIN_VULNERABLE_VERSION, MAX_VULNERABLE_VERSION)
]
metadata = definitions.VulnerabilityMetadata(
title=VULNERABILITY_TITLE,
description=VULNERABILITY_DESCRIPTION,
reference=VULNERABILITY_REFERENCE,
risk_rating=RISK_RATING,
)
version_pattern = VERSION_PATTERN
52 changes: 52 additions & 0 deletions tests/exploits/cve_2024_54134_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Unit tests for Agent Asteroid: CVE-2024-54134"""

import requests_mock as req_mock

from agent import definitions
from agent.exploits import cve_2024_54134


def testCVE202454134_whenVulnerable_reportFinding(
requests_mock: req_mock.mocker.Mocker,
) -> None:
"""CVE-2024-54134 unit test: case when target is vulnerable."""
requests_mock.get(
"http://localhost:80/",
text='<script src="https://unpkg.com/@solana/[email protected]/lib/index.iife.min.js"></script>',
status_code=200,
)
exploit_instance = cve_2024_54134.CVE202454134Exploit()
target = definitions.Target("http", "localhost", 80)

accept = exploit_instance.accept(target)
vulnerabilities = exploit_instance.check(target)

assert accept is True
assert len(vulnerabilities) > 0
vulnerability = vulnerabilities[0]
assert (
vulnerability.entry.title
== "MALICIOUS PACKAGES FOUND IN COMPROMISED @SOLANA/WEB3.JS LIBRARY"
)
assert vulnerability.technical_detail == (
"http://localhost:80 is vulnerable to CVE-2024-54134, MALICIOUS PACKAGES FOUND IN COMPROMISED @SOLANA/WEB3.JS LIBRARY"
)


def testCVE202454134_whenSafe_reportNothing(
requests_mock: req_mock.mocker.Mocker,
) -> None:
"""CVE-2024-54134 unit test: case when target is safe."""
exploit_instance = cve_2024_54134.CVE202454134Exploit()
requests_mock.get(
"http://localhost:80/",
text='<script src="https://unpkg.com/@solana/[email protected]/lib/index.iife.min.js"></script>',
status_code=200,
)
target = definitions.Target("http", "localhost", 80)

accept = exploit_instance.accept(target)
vulnerabilities = exploit_instance.check(target)

assert accept is True
assert len(vulnerabilities) == 0
Loading