Port 139 (NetBIOS): What It Is & Security Guide
What is Port 139 (NetBIOS)? Understanding a Legacy Security Risk
In the vast landscape of network ports, some stand out due to their historical significance and persistent security implications. TCP port 139 is one such port. It's primarily associated with the NetBIOS Session Service, a foundational component of early Microsoft Windows networking. While its prominence has waned with the advent of more modern protocols like direct SMB over TCP (port 445), understanding port 139 is crucial for anyone managing network security.
NetBIOS (Network Basic Input/Output System) was designed to allow applications on different computers to communicate over a local area network (LAN). It provides services for name resolution, datagram distribution, and session management. Port 139 specifically handles the NetBIOS Session Service, which enables connection-oriented communication between two NetBIOS applications. This is critical for tasks like file sharing, printer sharing, and remote procedure calls (RPC) in older Windows environments.
However, the very features that made NetBIOS useful also expose significant security vulnerabilities when port 139 is left open and unprotected, especially to the internet. Its design predates modern security considerations, making it a prime target for attackers seeking to gain unauthorized access, enumerate network resources, or exploit known vulnerabilities. This guide will delve into the technical aspects of port 139, its associated risks, and essential strategies to secure your network against potential threats.
Port 139 Technical Details: NetBIOS Session Service Explained
To fully grasp the security implications of port 139, it's important to understand its technical underpinnings. Here's a quick overview:
| Port Number | 139 |
| Protocol | TCP |
| Service | NetBIOS Session Service |
| Risk Level | High |
| Associated Protocols | SMB (Server Message Block) over NetBIOS |
NetBIOS itself is not a networking protocol but rather an API (Application Programming Interface) that allows applications to use network services. It operates over various transport protocols, with NetBIOS over TCP/IP (NBT) being the most common in modern networks. NBT uses three distinct ports:
- UDP Port 137 (NetBIOS Name Service): Used for name registration and resolution, allowing computers to find each other by name.
- UDP Port 138 (NetBIOS Datagram Service): Used for connectionless communication, sending data packets to multiple machines.
- TCP Port 139 (NetBIOS Session Service): This is our focus. It provides a reliable, connection-oriented service for two applications to establish a session and exchange data. This is the port that facilitates the actual data transfer for services like file and printer sharing when SMB is running over NetBIOS.
When a Windows machine needs to share files or printers using NetBIOS, it listens on TCP port 139. A client wishing to access these resources would initiate a TCP connection to port 139 on the server. Once the session is established, the Server Message Block (SMB) protocol is used to handle the actual file and print operations. This older method of SMB communication, often referred to as 'SMB over NetBIOS,' is distinct from 'Direct SMB' which uses TCP port 445 directly, bypassing the NetBIOS layer entirely. While modern Windows versions primarily use port 445 for SMB, port 139 remains active for backward compatibility or in environments where NetBIOS over TCP/IP is explicitly enabled.
Security Risks of Open Port 139: A Gateway for Attackers
An open TCP port 139, especially one exposed to the internet, represents a significant security vulnerability. Its legacy design and the services it supports (NetBIOS/SMB) have been the target of numerous exploits over the years. Attackers actively scan for this port to identify potential victims and launch various attacks. The high risk associated with port 139 stems from the sensitive information it can expose and the powerful capabilities it can grant to an attacker.
Common Attacks on Port 139: Exploiting NetBIOS Weaknesses
Attackers employ a variety of techniques to exploit systems with an open TCP port 139. Understanding these common attacks is the first step in defending against them.
How to Check if Port 139 is Open on Your Network
Before you can secure port 139, you need to know if it's open on your systems or network. There are several methods to check, ranging from command-line tools to online scanners.
Using Nmap (Network Mapper)
Nmap is a powerful, open-source tool for network discovery and security auditing. It's the go-to utility for checking open ports.
To check if port 139 is open on a specific target (IP address or hostname), use the following command:
nmap -p 139 target.com
Replace target.com with the IP address or hostname you want to scan. If the output shows '139/tcp open', then the port is accessible. You can also use Nmap to gather more information about the service:
nmap -p 139 -sV target.com
The -sV flag attempts to determine the service and version running on the port.
Using Netstat (Windows/Linux)
On a local machine, you can use netstat to see if any applications are listening on port 139:
- Windows: Open Command Prompt or PowerShell as administrator and type:
netstat -ano | findstr :139
This will show if any process is listening on port 139 and its PID. - Linux: Open a terminal and type:
sudo netstat -tulnp | grep :139
This will show listening TCP/UDP ports and the associated process.
Using Online Port Scanners
For a quick external check, online port scanners can be very useful. These tools scan your public IP address from the internet to see which ports are accessible. Be cautious when using unknown online tools, but reputable ones can provide a quick assessment.
You can easily check if port 139 is open on your public IP address using a reliable online tool. Scan port 139 with our free tool by visiting the Secably Port Scanner. Simply enter your IP address or domain, and our scanner will quickly tell you if port 139 is exposed to the internet.
Free Security Tools
Scan your website, check open ports, find subdomains — no signup required.
- Website Vulnerability Scanner — find XSS, SQLi, misconfigurations
- Port Scanner — Nmap-powered, all 65535 ports
- Subdomain Finder — discover hidden attack surface
How to Secure Port 139: Essential Hardening Steps
Given the high security risks associated with an open TCP port 139, it's imperative to implement robust security measures. The goal is to minimize its exposure, especially to the internet, and to secure the underlying services it supports.
When Should Port 139 Be Open? Legitimate Use Cases (with Caution)
While the general recommendation is to close or restrict access to TCP port 139, there are specific, albeit increasingly rare, scenarios where it might need to be open. However, even in these cases, access should be strictly limited and never exposed directly to the public internet.
- Legacy File and Printer Sharing: In older Windows domains or workgroup environments, port 139 is essential for traditional NetBIOS-based file and printer sharing. If you have legacy systems (e.g., Windows XP, Windows Server 2003) that cannot be upgraded and rely solely on NetBIOS over TCP/IP for SMB, this port might be necessary.
- Domain Controllers (Internal Network): Older Domain Controllers might still use NetBIOS for certain legacy functions, especially in mixed environments with older client machines. In such cases, port 139 would be open on the DC, but strictly within the internal network.
- Specific Legacy Applications: Some very old, custom-built applications might have been designed to communicate using NetBIOS Session Service. If such an application is critical to your operations and cannot be modernized, port 139 might be required for its functionality.
- WINS Servers: If you are still running a Windows Internet Name Service (WINS) server for NetBIOS name resolution, it might interact with port 139 for session establishment, though UDP 137 is the primary WINS port.
Crucial Caveat: In all these legitimate use cases, port 139 should only be accessible within a trusted, segmented internal network. It should never be directly exposed to the internet. If remote access is required, it must be facilitated through a secure VPN connection, ensuring that all traffic to port 139 is encapsulated and encrypted within the VPN tunnel.
Is port 139 dangerous?
Yes, TCP port 139 is considered highly dangerous if left open and exposed, especially to the internet. It facilitates NetBIOS Session Service, which often carries SMB traffic. This makes it a prime target for attackers to perform enumeration, gain unauthorized access to shared resources, launch brute-force attacks, or exploit known SMB vulnerabilities (like those related to EternalBlue) for remote code execution and malware propagation. Its legacy design lacks modern security features, making it inherently risky.
Should I close port 139?
In almost all modern network environments, you should close or severely restrict access to TCP port 139. For systems that no longer require legacy NetBIOS services, it's best to disable NetBIOS over TCP/IP entirely. If you have legacy systems that absolutely require it, ensure it's only accessible within a trusted, segmented internal network and never directly exposed to the internet. Use a VPN for any remote access needs.
How do I block port 139?
You can block port 139 using firewall rules on your operating system or network perimeter devices. Here are common commands for Linux and Windows:
Linux (iptables/ufw):
- Using iptables (for immediate effect, not persistent across reboots without saving):
sudo iptables -A INPUT -p tcp --dport 139 -j DROP
sudo iptables -A OUTPUT -p tcp --sport 139 -j DROP
To make it persistent, you'll need to save the iptables rules (e.g., `sudo netfilter-persistent save` or `sudo service iptables save`). - Using UFW (Uncomplicated Firewall - recommended for Ubuntu/Debian):
sudo ufw deny 139/tcp
sudo ufw enable
Windows Firewall:
Open 'Windows Defender Firewall with Advanced Security' (search for 'firewall' in Start menu). Go to 'Inbound Rules' -> 'New Rule...'
- Select 'Port' and click 'Next'.
- Select 'TCP' and enter '139' for 'Specific local ports'. Click 'Next'.
- Select 'Block the connection'. Click 'Next'.
- Choose when the rule applies (Domain, Private, Public - typically all). Click 'Next'.
- Give the rule a name (e.g., 'Block TCP 139 Inbound') and click 'Finish'.
Repeat for 'Outbound Rules' if you want to prevent your system from initiating connections on port 139.
What runs on port 139 by default?
By default, TCP port 139 is used by the NetBIOS Session Service. On Microsoft Windows operating systems, this service is part of NetBIOS over TCP/IP (NBT) and is primarily responsible for facilitating connection-oriented communication for legacy file and printer sharing via the Server Message Block (SMB) protocol. While modern Windows versions prefer Direct SMB over TCP port 445, port 139 remains active for backward compatibility or if NetBIOS over TCP/IP is explicitly enabled.