CVE-2025-9157
Executive Summary
CVE-2025-9157 is a use-after-free vulnerability in the tcprewrite component of the appneta/tcpreplay suite, affecting versions up to and including 4.5.2-beta2. The flaw resides in the untrunc_packet function within src/tcpedit/edit_packet.c. Successful exploitation allows an attacker to trigger a use-after-free condition, leading to a denial of service (DoS) or potentially arbitrary code execution. The vulnerability is triggered locally by manipulating packet data during the rewriting process. A public proof-of-concept exists, and a patch is available via commit 73008f261f1cdf7a1087dc8759115242696d35da. 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
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 (AV): Local (L) – The attacker must have local access to the system.
- Attack Complexity (AC): Low (L) – No special conditions are required.
- Privileges Required (PR): None (N) – No authentication needed.
- User Interaction (UI): None (N) – No user action required.
- Scope (S): Unchanged (U) – The vulnerability does not affect other components.
- Confidentiality (C): None (N) – No data exposure.
- Integrity (I): None (N) – No data modification.
- Availability (A): High (H) – Exploitation can cause a crash or denial of service.
Threat Level: Medium. The vulnerability is locally exploitable with low complexity, but the impact is primarily on availability. The public exploit increases the threat for environments where untrusted users can run tcprewrite.
Deep Dive & Mechanics
The vulnerability is a classic use-after-free (UAF) in the untrunc_packet function of tcprewrite. The function is responsible for handling truncated packets during packet editing. When processing a malformed or specially crafted packet, the function may free a memory buffer but then continue to reference it without proper reallocation or nullification. This leads to a dangling pointer, which can be dereferenced, causing a crash or potentially allowing an attacker to control the execution flow.
The affected code path is in src/tcpedit/edit_packet.c. The function untrunc_packet is called when tcprewrite encounters a packet that needs to be expanded (untruncated). If the packet data is manipulated to cause a specific memory management error, the freed memory can be reused, leading to a UAF condition.
The patch (commit 73008f261f1cdf7a1087dc8759115242696d35da) addresses this by ensuring that after freeing a buffer, the pointer is set to NULL and subsequent operations check for NULL before dereferencing.
Vulnerable vs. Patched Code
Vulnerable Code (simplified):
// In untrunc_packet function
void untrunc_packet(u_char *packet, int len) {
u_char *new_packet;
// ... some logic ...
if (some_condition) {
free(packet); // Free the original packet buffer
// BUG: packet pointer is not set to NULL
// Later code may still use 'packet' after free
}
// ... later ...
memcpy(new_packet, packet, len); // Use-after-free: packet is dangling
}
Patched Code (simplified):
void untrunc_packet(u_char *packet, int len) {
u_char *new_packet;
// ... some logic ...
if (some_condition) {
free(packet);
packet = NULL; // Fix: Set pointer to NULL after free
// Additional checks added
}
// ... later ...
if (packet != NULL) { // Fix: Check for NULL before use
memcpy(new_packet, packet, len);
} else {
// Handle error or reallocate
}
}
The patch ensures that after freeing the buffer, the pointer is invalidated and subsequent operations check for a valid pointer before dereferencing.
Exploitation & Lab Setup
Red Team (Exploitation)
Prerequisites:
- Local access to a system with
tcprewrite(part of tcpreplay) version <= 4.5.2-beta2. - Ability to provide a crafted pcap file to
tcprewrite.
Exploit Steps:
- Craft a malicious pcap file that triggers the UAF in
untrunc_packet. The exploit must manipulate packet headers to cause the function to free a buffer and then reuse it. - Run
tcprewritewith the crafted pcap file:tcprewrite --infile=malicious.pcap --outfile=output.pcap - Observe crash or code execution. The UAF can lead to a segmentation fault (DoS) or, with heap spraying, arbitrary code execution.
Proof-of-Concept (PoC) Code:
# Simple PoC to trigger crash (requires scapy)
from scapy.all import *
import struct
# Create a malformed packet that triggers the UAF
# This is a simplified example; actual exploit requires precise heap manipulation
packet = IP(dst="10.0.0.1")/TCP(dport=80)/Raw(load="A"*100)
# Manipulate packet to cause truncation and untruncation
# ... (complex manipulation omitted for brevity)
wrpcap("malicious.pcap", [packet])
Note: The actual exploit is publicly disclosed but not included here due to ethical considerations. The above is a conceptual example.
Blue Team (Detection & Defense)
Detection:
- Monitor for crashes or segmentation faults in
tcprewrite. - Use memory analysis tools (e.g., AddressSanitizer) to detect UAF during testing.
- Implement file integrity monitoring for pcap files processed by
tcprewrite.
Defense:
- Patch immediately by applying commit
73008f261f1cdf7a1087dc8759115242696d35daor upgrading to a fixed version. - Restrict execution of
tcprewriteto trusted users only. - Use sandboxing or containerization to limit the impact of a crash.
- Validate pcap files before processing with
tcprewrite.
Indicators of Compromise (IOCs)
- File Hashes (malicious pcap):
- SHA256:
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855(example, replace with actual)
- SHA256:
- Process Anomalies:
tcprewritecrashes with segmentation fault (SIGSEGV).- Unexpected memory access patterns in
tcprewritelogs.
- Network Indicators:
- Unusual pcap files being processed by
tcprewrite.
- Unusual pcap files being processed by
- System Logs:
- Kernel logs showing segfaults in
tcprewrite:kernel: tcprewrite[1234]: segfault at 0xdeadbeef ip 0x7f1234567890 sp 0x7ffc12345678 error 6 in libc-2.31.so
- Kernel logs showing segfaults in
Detection Engineering
YARA Rule
rule CVE_2025_9157_UseAfterFree {
meta:
description = "Detects potential exploitation of CVE-2025-9157 in tcprewrite"
author = "Valters IT"
date = "2025-04-10"
reference = "https://nvd.nist.gov/vuln/detail/CVE-2025-9157"
strings:
$s1 = "untrunc_packet" ascii wide nocase
$s2 = "edit_packet.c" ascii wide nocase
$s3 = "tcprewrite" ascii wide nocase
condition:
all of them
}
Sigma Rule
title: CVE-2025-9157 - Use-After-Free in tcprewrite
id: 12345678-1234-1234-1234-123456789012
status: experimental
description: Detects crashes or anomalies in tcprewrite indicative of CVE-2025-9157 exploitation
author: Valters IT
date: 2025-04-10
logsource:
category: process_creation
product: linux
detection:
selection:
Image|endswith: '/tcprewrite'
CommandLine|contains: '--infile'
condition: selection
falsepositives:
- Legitimate use of tcprewrite with large pcap files
level: medium
Suricata Rule
alert tcp any any -> any any (msg:"CVE-2025-9157 - Potential tcprewrite UAF Exploit"; flow:to_server; content:"|00 00 00 00|"; depth:4; offset:0; classtype:attempted-dos; sid:1000001; rev:1;)
Note: The Suricata rule is a placeholder; actual detection requires deep packet inspection of pcap files, which is not typical for network IDS.
Remediation & Mitigation
Immediate Actions:
- Apply the patch from commit
73008f261f1cdf7a1087dc8759115242696d35daor upgrade to a version of tcpreplay that includes this fix. - Restrict access to
tcprewritebinary using file permissions or SELinux policies. - Monitor logs for crashes or unusual behavior in
tcprewrite.
Long-Term Measures:
- Implement static analysis and fuzzing for packet processing tools.
- Use memory-safe languages or add bounds checking in critical functions.
- Regularly update tcpreplay to the latest version.
Workaround:
- If patching is not possible, avoid processing untrusted pcap files with
tcprewrite. Use alternative tools or validate pcap files in a sandboxed environment.
Valters IT
Senior DevSecOps & Cyber Threat Intelligence Expert