# 445 - Pentesting SMB

## NetExec

netexec is the latest tool which can be used to enumerate SMB protocol

### Banner Grabbing of IPs using netexec

make a list of ips in a file and then used the below command

```python
netexec smb ips.txt 
```

### Password Spraying using netexec

this will try to list all the shares

```
netexec smb ips.txt -u users.txt -p passwords.txt 
```

### Netexec to see shares

we can see shares as well using netexec

```python
netexec smb ips.txt -u users.txt -p passwords.txt --shares
```

## SMBClient

### List Shares using SMBClient

We can use smbclient to list the shares and login to the shares as well

```python
smbclient -N -L //10.10.11.236
```

### List Shares with User and Pass

when we have a username and password we can try this

```python
smbclient -L \\\\10.0.9.158\\ -U noc
Password for [WORKGROUP\noc]:

```

<figure><img src="https://3420091786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1ZUO45eHY8aMCLJ7OiN%2Fuploads%2Fw9n4W96wfMlrTlmbuzHh%2Fimage.png?alt=media&#x26;token=63b433ee-feeb-4dab-8d9b-8917d9f1a523" alt=""><figcaption></figcaption></figure>

### Download files using SMBClient

Login to SMB

```python
smbclient \\\\10.0.9.158\\IPC$ -U noc
```

<figure><img src="https://3420091786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1ZUO45eHY8aMCLJ7OiN%2Fuploads%2FMpuuCmkpUVLgQpFvuF9j%2Fimage.png?alt=media&#x26;token=32dee8e8-c38b-4cf2-b884-c933ea1b9c41" alt=""><figcaption></figcaption></figure>

now use the following commands and it will recursively download all the files in your kali linux

```python
smb: \> recurse ON  
smb: \> prompt OFF  
smb: \> mget *

#after this you can find any file using the find command

find . -type f
```

## SMBMAP

### List Shares using SMBMAP

```
smbmap -H 10.0.9.158 -u username -p password
```

<figure><img src="https://3420091786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1ZUO45eHY8aMCLJ7OiN%2Fuploads%2FDjtIBHp5fVbfV0meheWo%2Fimage.png?alt=media&#x26;token=f231534e-de9a-4008-a8e8-3402e482c3fc" alt=""><figcaption></figcaption></figure>

### Directory Structure Listing of a Share Recursively

```
smbmap -H 10.0.9.158 -u username -p 'password' -r IPC$
```

<figure><img src="https://3420091786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1ZUO45eHY8aMCLJ7OiN%2Fuploads%2FgOJFAGzOe57jMkH0cFnq%2Fimage.png?alt=media&#x26;token=9d43268f-3c19-46af-a953-935f3ca6171c" alt=""><figcaption></figcaption></figure>

### Download files from Shares using SMBMAP

```python
smbmap -H 10.0.9.158 -u username -p 'password' -r IPC$ -A eventlog
```

<figure><img src="https://3420091786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1ZUO45eHY8aMCLJ7OiN%2Fuploads%2FadAeGJS2N7R2tYVg803R%2Fimage.png?alt=media&#x26;token=af5aa327-25cb-4cee-bea8-2c2494b4fd35" alt=""><figcaption></figcaption></figure>

## STATUS\_PASSWORD\_MUST\_CHANGE

if you see status password must change, then you can change the password of that user using **impacket-smbpasswd**

```
impacket-smbpasswd baby.vl/Caroline.Robinson@10.10.88.65 -newpass 'Test1234!'
```

<figure><img src="https://3420091786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1ZUO45eHY8aMCLJ7OiN%2Fuploads%2FlBuGvlME6EuizsuGonMm%2Fimage.png?alt=media&#x26;token=b5b561c5-cd9f-4ec5-a617-f1e1c561681d" alt=""><figcaption></figcaption></figure>
