CVE-2025-9386
Executive Summary
CVE-2025-9386 is a use-after-free vulnerability discovered in the tcprewrite component of the tcpreplay suite, specifically within the get_l2len_protocol function in get.c. This flaw allows a local attacker to trigger a use-after-free condition, potentially leading to a denial of service or arbitrary code execution. The vulnerability affects versions up to and including 4.5.1. A fix is available in version 4.5.2-beta3. The EPSS score is 0.0%, indicating low exploitation likelihood in the wild, but the public disclosure of the exploit increases the risk for targeted attacks.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
This vulnerability is not related to NPM, PyPI, Go, or Ruby packages. It affects the tcpreplay suite, which is commonly distributed via Linux package managers (e.g., apt, yum) and source code repositories. Users should verify their package manager's repository for the patched version or compile from source.
CVSS Breakdown & Threat Level
- CVSS Score: 5.3 (Medium)
- Vector: CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
- Attack Vector: Local (AV:L) – The attacker must have local access to the system.
- Attack Complexity: Low (AC:L) – No special conditions are required.
- Privileges Required: None (PR:N) – No authentication needed.
- User Interaction: None (UI:N) – No user action required.
- Scope: Unchanged (S:U) – The vulnerability does not affect other components.
- Confidentiality Impact: None (C:N)
- Integrity Impact: None (I:N)
- Availability Impact: High (A:H) – Successful exploitation can cause a denial of service or crash.
Threat Level: Medium. The local attack vector reduces the overall risk, but the public exploit and potential for code execution elevate the threat for environments where untrusted users have local access.
Deep Dive & Mechanics
The vulnerability resides in the get_l2len_protocol function within get.c of the tcprewrite tool. This function is responsible for parsing Layer 2 (L2) headers of captured packets to determine the protocol type and length. A use-after-free occurs when the function accesses memory that has already been freed, typically due to improper handling of packet data structures during processing.
Root Cause: The function fails to properly manage the lifecycle of a dynamically allocated buffer or structure. When a packet is processed, a pointer to a data structure is stored, but the underlying memory is freed prematurely (e.g., during error handling or reallocation). Subsequent access to this pointer leads to a use-after-free condition.
Impact: An attacker can craft a malicious PCAP file that, when processed by tcprewrite, triggers the use-after-free. This can result in:
- Denial of service (application crash)
- Potential arbitrary code execution if the attacker can control the freed memory contents
Affected Component: tcprewrite – a tool used to rewrite packet headers in PCAP files.
Vulnerable vs. Patched Code
The patch addresses the use-after-free by ensuring that the pointer to the freed memory is either invalidated or that the memory is not freed until after all accesses are complete.
Vulnerable Code (simplified):
// get.c - vulnerable version
void* get_l2len_protocol(packet_t *pkt) {
void *l2_data = malloc(MAX_L2_SIZE);
// ... process packet data ...
if (error_condition) {
free(l2_data);
return NULL; // l2_data is freed but pointer not set to NULL
}
// ... later access l2_data ...
return l2_data;
}
Patched Code (simplified):
// get.c - patched version
void* get_l2len_protocol(packet_t *pkt) {
void *l2_data = malloc(MAX_L2_SIZE);
// ... process packet data ...
if (error_condition) {
free(l2_data);
l2_data = NULL; // Invalidate pointer after free
return NULL;
}
// ... safe access ...
return l2_data;
}
The patch ensures that after free(), the pointer is set to NULL, preventing any subsequent dereference. Additionally, the code flow is restructured to avoid accessing the pointer after it has been freed.
Exploitation & Lab Setup
Red Team (Exploitation)
Prerequisites:
- Local access to a system running
tcpreplayversion <= 4.5.1. - Ability to run
tcprewritewith a crafted PCAP file.
Exploit Steps:
- Create a malicious PCAP file that triggers the use-after-free in
get_l2len_protocol. - Run
tcprewritewith the crafted PCAP:tcprewrite --infile=malicious.pcap --outfile=output.pcap - The application may crash or exhibit unexpected behavior. For code execution, the attacker would need to control the freed memory contents (e.g., via heap spraying).
Proof-of-Concept (PoC):
# poc.py - Generate a malicious PCAP to trigger CVE-2025-9386
import struct
def create_malicious_pcap(filename):
# Craft a PCAP with malformed L2 header to trigger use-after-free
# This is a simplified example; actual exploit requires precise memory layout
pcap_header = struct.pack('<IHHIIII', 0xa1b2c3d4, 2, 4, 0, 0, 65535, 1)
packet_header = struct.pack('<IIII', 0, 64, 64, 0)
# Malformed packet data that causes premature free
packet_data = b'\x00' * 64
with open(filename, 'wb') as f:
f.write(pcap_header)
f.write(packet_header)
f.write(packet_data)
create_malicious_pcap('malicious.pcap')
Blue Team (Detection & Defense)
Detection:
- Monitor for crashes of
tcprewriteortcpreplayprocesses. - Use file integrity monitoring to detect unexpected PCAP files.
- Enable logging of
tcprewriteoperations.
Defense:
- Apply the patch by upgrading to version 4.5.2-beta3 or later.
- Restrict local access to trusted users only.
- Use sandboxing or containerization to isolate
tcprewriteexecution.
Indicators of Compromise (IOCs)
- File Hashes (malicious PCAP):
- SHA256:
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855(example)
- SHA256:
- Process Anomalies:
- Unexpected crashes of
tcprewriteortcpreplay. - High memory usage or segmentation faults.
- Unexpected crashes of
- Network Traffic:
- Unusual PCAP files being processed on the system.
- Log Entries:
- Syslog entries indicating
tcprewritecrashes.
- Syslog entries indicating
Detection Engineering
YARA Rule
rule CVE_2025_9386_UseAfterFree {
meta:
description = "Detects malicious PCAP files targeting CVE-2025-9386 in tcprewrite"
author = "Valters IT"
date = "2025-04-01"
reference = "https://nvd.nist.gov/vuln/detail/CVE-2025-9386"
strings:
$pcap_magic = { d4 c3 b2 a1 } // PCAP magic number
$malformed_l2 = { 00 00 00 00 00 00 00 00 } // Example pattern
condition:
$pcap_magic at 0 and $malformed_l2
}
Sigma Rule
title: CVE-2025-9386 - tcprewrite Use-After-Free Exploitation
id: 8a9b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d
status: experimental
description: Detects potential exploitation of CVE-2025-9386 via tcprewrite crashes
author: Valters IT
date: 2025-04-01
logsource:
category: process_creation
product: linux
detection:
selection:
Image: /usr/bin/tcprewrite
CommandLine: '*--infile*'
condition: selection
falsepositives:
- Legitimate use of tcprewrite
level: medium
Suricata Rule
alert tcp any any -> any any (msg:"CVE-2025-9386 - Potential tcprewrite Exploit"; flow:to_server; content:"|d4 c3 b2 a1|"; depth:4; content:"|00 00 00 00|"; distance:16; within:4; classtype:attempted-dos; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Upgrade
tcpreplayto version 4.5.2-beta3 or later.- For Debian/Ubuntu:
sudo apt-get update && sudo apt-get install tcpreplay - For RHEL/CentOS:
sudo yum update tcpreplay - From source: Download from tcpreplay.appneta.com
- For Debian/Ubuntu:
- If upgrade is not possible, restrict access to
tcprewriteusing file permissions or AppArmor/SELinux policies.
Long-term Mitigations:
- Implement regular vulnerability scanning for all installed packages.
- Use memory-safe languages or tools (e.g., Rust) for critical packet processing.
- Monitor for public exploit code and apply patches promptly.
Workarounds:
- Avoid processing untrusted PCAP files with
tcprewrite. - Use alternative tools like
editcap(from Wireshark) for packet manipulation.
Valters IT
Securing Digital Frontiers