Skip to main content

How to craft a raw TCP socket without Winsock?

Medium
Published: Wed Jul 23 2025 (07/23/2025, 11:35:18 UTC)
Source: Reddit NetSec

Description

Mateusz Lewczak explains how the AFD.sys driver works under the hood on Windows 11. In Part 1 [1], he demonstrates how to use WinDbg and the NtCreateFile call to manually craft a raw TCP socket, bypassing the Winsock layer entirely. Part 2 of the series [2] dives into the bind and connect operations implemented via AFD.sys IOCTLs. Mateusz shows how to intercept and analyze IRP packets, then reconstruct the buffer needed to perform the three‑way TCP handshake by hand in kernel mode. [1] https://leftarcode.com/posts/afd-reverse-engineering-part1/ [2] https://leftarcode.com/posts/afd-reverse-engineering-part2/

AI-Powered Analysis

AILast updated: 07/26/2025, 01:05:47 UTC

Technical Analysis

The provided information describes a technical exploration into the Windows 11 kernel networking subsystem, specifically focusing on the AFD.sys driver, which is responsible for socket operations at a low level. Mateusz Lewczak's research demonstrates how to bypass the traditional Winsock API layer by directly crafting raw TCP sockets using the NtCreateFile system call and manipulating AFD.sys IOCTLs. This involves intercepting and analyzing I/O Request Packets (IRPs) to manually reconstruct the TCP three-way handshake in kernel mode. The work is presented as a two-part series that serves as a deep dive into Windows kernel networking internals, illustrating how socket operations such as bind and connect can be implemented without relying on the standard Winsock interface. While this research is primarily educational and technical, it reveals potential offensive techniques that could be leveraged by attackers to craft custom TCP connections at a very low level, potentially evading some user-mode detection mechanisms or restrictions imposed by Winsock. However, there is no indication of an existing vulnerability or exploit in AFD.sys or Windows 11 itself. No known exploits are reported in the wild, and no affected product versions or patches are listed. The content is more of a reverse engineering and offensive security technique demonstration rather than a direct security threat or vulnerability.

Potential Impact

For European organizations, the direct impact of this research is limited as it does not describe a vulnerability or active exploit but rather a method to craft raw TCP sockets bypassing Winsock. However, the technique could theoretically be used by advanced threat actors or malware developers to create stealthy network communications that evade traditional user-mode network monitoring or filtering tools relying on Winsock APIs. This could complicate network traffic analysis and detection of malicious activity, especially in environments heavily reliant on Windows 11 systems. Organizations with high-value targets or sensitive data might face increased risks if attackers adopt such low-level networking techniques to bypass endpoint security controls. Nonetheless, since this is a research demonstration without known exploitation, the immediate risk remains low to medium. It does highlight the importance of kernel-mode monitoring and advanced network traffic inspection capabilities to detect anomalous behaviors that bypass standard networking stacks.

Mitigation Recommendations

1. Employ kernel-mode security monitoring tools capable of detecting unusual IRP or IOCTL activity related to AFD.sys to identify attempts to manipulate low-level socket operations. 2. Use Endpoint Detection and Response (EDR) solutions with kernel-level visibility to monitor for suspicious NtCreateFile calls targeting AFD.sys or other unusual kernel interactions. 3. Implement network anomaly detection systems that analyze traffic patterns beyond Winsock-based monitoring, focusing on raw TCP traffic characteristics. 4. Maintain strict application whitelisting and code integrity policies to prevent unauthorized kernel-mode code execution that could leverage these techniques. 5. Keep Windows 11 systems fully updated and monitor Microsoft security advisories for any future vulnerabilities related to AFD.sys or kernel networking components. 6. Educate security teams about emerging offensive techniques that bypass traditional APIs to improve incident response and threat hunting capabilities.

Need more detailed analysis?Get Pro

Technical Details

Source Type
reddit
Subreddit
netsec
Reddit Score
6
Discussion Level
minimal
Content Source
reddit_link_post
Domain
leftarcode.com
Newsworthiness Assessment
{"score":21.6,"reasons":["external_link","newsworthy_keywords:rce,ioc,ttps","non_newsworthy_keywords:how to","question_or_tutorial_title","established_author"],"isNewsworthy":true,"foundNewsworthy":["rce","ioc","ttps"],"foundNonNewsworthy":["how to"]}
Has External Source
true
Trusted Domain
false

Threat ID: 688429e0ad5a09ad0058e904

Added to database: 7/26/2025, 1:05:36 AM

Last enriched: 7/26/2025, 1:05:47 AM

Last updated: 7/26/2025, 5:41:35 AM

Views: 3

Actions

PRO

Updates to AI analysis are available only with a Pro account. Contact root@offseq.com for access.

Please log in to the Console to use AI analysis features.

Need enhanced features?

Contact root@offseq.com for Pro access with improved analysis and higher rate limits.

Latest Threats