> For the complete documentation index, see [llms.txt](https://ivalexev.gitbook.io/rednote/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ivalexev.gitbook.io/rednote/utility/service/smb-139-445.md).

# SMB (139-445)

Server Message Block.

<details>

<summary>Protocol Information</summary>

SMB (Server Message Block) is a network protocol that enables the sharing of files, printers and other resources among devices within a network. Used primarily in Windows systems, SMB allows users and applications to access remote files as if they were local and supports features such as authentication, permission management, and access control.\
SMB uses port 445 (TCP). However, SMB was originally run on NetBIOS using port 139. NetBIOS is an independent session-level service and protocol that allows computers on a local network to communicate with each other. While modern implementations of SMB can run without NetBIOS, NetBIOS over TCP (NBT) is required for backward compatibility and is often enabled together.

There is **`3 version`** of SMB: **`SMBv1`** susceptible to known attacks (Eternal blue, wanna cry), **`SMBv2`** and **`SMBv3`** that uses encryption and is more secure.

**`SAMBA`** is the open source Linux implementation of SMB.

</details>

## Port

<table data-header-hidden><thead><tr><th width="166">Port</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:green;"><strong>445</strong></mark><strong> TCP</strong></td><td>Newer versions of SMB (after Windows 2000)</td></tr><tr><td><mark style="color:green;"><strong>139</strong></mark><strong> TCP</strong></td><td>NBSession</td></tr></tbody></table>

## Config File

* `/etc/samba/smb.conf`

## Interact

If **anonymous access** is enabled, it's possible log in with username `“”` and password `“”`.\
Or try with `guest` and `""`.

{% tabs %}
{% tab title="Windows" %}
{% code overflow="wrap" %}

```powershell
net use n: \\<IP>\<SHARE>
net use n: \\<IP>\<SHARE> /user:<USER> <PASSWORD>
```

{% endcode %}
{% endtab %}

{% tab title="Linux" %}

```bash
sudo apt install cifs-utils
```

{% code overflow="wrap" %}

```bash
sudo mkdir <MyDir>
sudo mount -t cifs -o username=<USERNAME>,password=<PASSWORD>[,domain=.] //<IP>/<SHARE> <MyDir>
```

{% endcode %}
{% endtab %}

{% tab title="Tools" %}

<table><thead><tr><th width="143">Tool</th><th>Details</th></tr></thead><tbody><tr><td><a href="https://github.com/ShawnDEvans/smbmap">smbmap</a></td><td>For enumeration<br><code>smbmap [-u &#x3C;USER> -p &#x3C;PASS> -d &#x3C;DOMAIN>] -H &#x3C;IP></code></td></tr><tr><td><a href="https://github.com/cddmp/enum4linux-ng">enum4linux</a></td><td>For enumeration<br><code>enum4linux [-u &#x3C;USER> -p &#x3C;PASS> -w &#x3C;DOMAIN>] -A &#x3C;IP></code></td></tr><tr><td>smbclient</td><td><p>Accessing and interacting<br><code>smbclient [-N or -U &#x3C;USER>] -L &#x3C;IP></code><br><code>smbclient [-N or -U &#x3C;USER>] //&#x3C;IP>/&#x3C;SHARE></code></p><p><code>impacket-smbclient -k &#x3C;DOMAIN>/&#x3C;USER>:&#x3C;PASS>@&#x3C;IP/HOSTNAME></code> <em>(kerberos auth)</em><br><em>Download all file:</em><br><code>recurse ON</code><br><code>prompt OFF</code><br><code>mget *</code></p></td></tr><tr><td><a href="https://github.com/Pennyw0rth/NetExec">netexec</a></td><td><p>Searching in shares<br><code>nxc smb &#x3C;IP> -u &#x3C;USER> -p &#x3C;PASS> --shares</code> <br><code>nxc smb &#x3C;IP> -u &#x3C;USER> -p &#x3C;PASS> --spider '&#x3C;SHARE>' --regex '&#x3C;REGEX>'</code></p><p><code>nxc smb &#x3C;IP> -u &#x3C;USER> -p &#x3C;PASS> -M spider_plus</code> <em>(try again if there are errors)</em></p></td></tr></tbody></table>
{% endtab %}
{% endtabs %}

## Attacks

### [EternalBlue (MS17-010)](/rednote/pentesting-process/cve/windows.md#eternalblue)

CVE-2017-0144

EternalBlue exploits a flaw in the SMBv1 protocol. By exploiting this flaw, an attacker can send malicious data to the victim system via an SMBv1 connection, causing a condition that allows them to take control of the target system, executing malicious code without any need for authentication and with system privileges.
