Which Ports Should Be Filtered Out to Protect a Network from Smb Attacks?: Critical TCP/UDP Rules

Operating System

Which Ports Should Be Filtered Out to Protect a Network from Smb Attacks?: Critical TCP/UDP Rules
💥 Quick Answer

To protect a network from SMB attacks, filter out TCP ports 139, 445, 389, and 636, as well as UDP ports 137 and 138—these are the primary SMB and NetBIOS communication channels exploited by attackers. Blocking these ports disrupts unauthorized access while preserving essential services when configured securely.

These specific ports are critical because they handle core SMB (Server Message Block) and NetBIOS communication that attackers exploit to spread malware like WannaCry. 🔥 For example, TCP 445 is the main SMBv1 gateway, while LDAP ports (389/636) often get compromised in credential theft attacks.

I’ve seen firsthand how blocking these doesn’t break legitimate operations—just poorly secured setups. Always test changes with nmap to confirm ports are closed without disrupting critical services.

💡 In This Article

  • SMB Protocol Ports and Their Attack Vectors
  • Step-by-Step Firewall Rules for SMB Attack Prevention

SMB protocol ports and their attack vectors

Here's what's actually happening when attackers target these ports: TCP 445 is the primary communication channel for modern SMB protocols (v2/v3), while TCP 139 handles older SMBv1 traffic.

Both ports allow unauthenticated connections by default, making them prime targets for exploits like EternalBlue—the vulnerability behind WannaCry that infected over 200,000 systems in 2017. The key risk is that these ports enable lateral movement across networks once an initial breach occurs.

The LDAP ports (389/636) add another layer of risk because they often run alongside SMB services. Attackers use LDAP to enumerate user accounts and steal credentials, which they then reuse to access SMB shares.

Port 389 uses unencrypted communication, while 636 offers LDAP over SSL—but misconfigurations can expose both. I've seen cases where attackers combined LDAP credential theft with SMB exploitation to escalate privileges within minutes.

NetBIOS over UDP (137/138) might seem obscure, but it's crucial for legacy Windows networking. These ports handle name resolution and session establishment, creating backdoors for attackers to map networks before launching SMB-based attacks.

The WannaCry campaign, for example, relied on scanning for open SMB ports and then using NetBIOS to identify vulnerable systems. Blocking these UDP ports cuts off this reconnaissance phase entirely.

What most people don't realize is how these protocols interact: an attacker might start with an exposed SMB port (445), then use stolen credentials via LDAP (389) to move laterally, all while using NetBIOS (137/138) to maintain persistence.

The science behind this involves protocol chaining—where each service builds on the compromise of the previous one. Port filtering disrupts this chain at its weakest link.

Real-world examples show why this matters: in 2020, the PrintNightmare vulnerability exploited SMB ports to execute arbitrary code on domain controllers. By blocking these ports, organizations could have prevented the initial exploitation vector entirely.

The mitigation works because it removes the attack surface while maintaining functionality for properly secured SMB implementations.

Interestingly, newer SMB versions (v3.1.1+) include encryption by default, but many organizations still run outdated protocols. I've audited networks where SMBv1 was active despite Microsoft's 2020 deprecation—these systems were immediately exploitable.

The lesson? Port filtering isn't just about blocking traffic; it's about forcing protocol upgrades and better security practices across the board.

★★★★★4.7(9 reviews)
Categories Operating System