repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
137-138-139-pentesting-netbios.mdMarkdown98 lines4.5 KiBrendered raw download
---
title: "137,138,139 - Pentesting NetBios"
section: "Network Services"
sectionSlug: "network-services-pentesting"
sourcePath: "src/network-services-pentesting/137-138-139-pentesting-netbios.md"
sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/network-services-pentesting/137-138-139-pentesting-netbios.md"
sha: "188de82beb54e70956b2952367a0af91d26758b8"
isIndex: false
modified: true
license: "CC-BY-NC-4.0"
---

# 137,138,139 - Pentesting NetBios

## NetBios Name Service

NetBIOS over TCP/IP defines name, datagram, and session services on separate ports:<sup>[[1]](#references)</sup><sup>[[2]](#references)</sup>

- Name service for name registration and resolution (ports: 137/udp and 137/tcp).
- Datagram distribution service for connectionless communication (port: 138/udp).
- Session service for connection-oriented communication (port: 139/tcp).

### Name Service

For a device to participate in a NetBIOS network, it must have a unique name. This is achieved through a **broadcast process** where a "Name Query" packet is sent. If no objections are received, the name is considered available. Alternatively, a **Name Service server** can be queried directly to check for name availability or to resolve a name to an IP address. Tools like `nmblookup`, `nbtscan`, and `nmap` are utilized for enumerating NetBIOS services, revealing server names and MAC addresses.

```bash
PORT    STATE SERVICE    VERSION
137/udp open  netbios-ns Samba nmbd netbios-ns (workgroup: WORKGROUP)
```

Enumerating a NetBIOS service you can obtain the names the server is using and the MAC address of the server.

```bash
nmblookup -A <IP>
nbtscan <IP>/30
sudo nmap -sU -sV -T4 --script nbstat.nse -p137 -Pn -n <IP>
```

The `nbstat` script queries the NetBIOS name table and may also report a MAC address.<sup>[[3]](#references)</sup>

### Datagram Distribution Service

NetBIOS datagrams allow for connectionless communication via UDP, supporting direct messaging or broadcasting to all network names. This service uses port **138/udp**.

```bash
PORT    STATE         SERVICE     VERSION
138/udp open|filtered netbios-dgm
```

### Session Service

For connection-oriented interactions, the **Session Service** facilitates a conversation between two devices, leveraging **TCP** connections through port **139/tcp**. A session begins with a "Session Request" packet and can be established based on the response. The service supports larger messages, error detection, and recovery, with TCP handling flow control and packet retransmission.

Data transmission within a session involves **Session Message packets**, with sessions being terminated by closing the TCP connection.

These services provide the NetBIOS naming and transport interfaces over TCP/IP.<sup>[[1]](#references)</sup><sup>[[2]](#references)</sup>

```bash
PORT      STATE SERVICE      VERSION
139/tcp   open  netbios-ssn  Microsoft Windows netbios-ssn
```

**Read the next page to learn how to enumerate this service:**


[Readme](/hacktricks/network-services-pentesting/pentesting-smb/overview)

## HackTricks Automatic Commands

```text
Protocol_Name: Netbios    #Protocol Abbreviation if there is one.
Port_Number:  137,138,139     #Comma separated if there is more than one.
Protocol_Description: Netbios         #Protocol Abbreviation Spelled out

Entry_1:
  Name: Notes
  Description: Notes for NetBios
  Note: |
    Name service for name registration and resolution (ports: 137/udp and 137/tcp).
    Datagram distribution service for connectionless communication (port: 138/udp).
    Session service for connection-oriented communication (port: 139/tcp).

    For a device to participate in a NetBIOS network, it must have a unique name. This is achieved through a broadcast process where a "Name Query" packet is sent. If no objections are received, the name is considered available. Alternatively, a Name Service server can be queried directly to check for name availability or to resolve a name to an IP address.

    https://book.hacktricks.wiki/en/network-services-pentesting/137-138-139-pentesting-netbios.html

Entry_2:
  Name: Find Names
  Description: Three scans to find the names of the server
  Command: nmblookup -A {IP} &&&& nbtscan {IP}/30 &&&& nmap -sU -sV -T4 --script nbstat.nse -p 137 -Pn -n {IP}
```

## References

- [1] [RFC 1001 - NetBIOS concepts and methods](https://www.rfc-editor.org/rfc/rfc1001)
- [2] [RFC 1002 - NetBIOS detailed specifications](https://www.rfc-editor.org/rfc/rfc1002)
- [3] [Nmap - `nbstat` NSE script](https://nmap.org/nsedoc/scripts/nbstat.html)