Skip to main content

SMB Share


note

Samba (SMB) require that the remote host have SMB (445/TCP[SMB] or 139/TCP[NetBIOS-SSN]) accessible over the network.

Setup SMB share service on MIP RHEL for file copy/transfer between MIP RHEL and target Windows/Linux host


Preparation​

info

The following steps below can be (and should be) modified as needed. For example, it is not necessary to create a folder literally named /srv/samba/myshare.

  1. Setup smb share folder and configure smb service config
# Create smb share folder
sudo mkdir -p /srv/samba/myshare
sudo chmod -R 0777 /srv/samba/myshare

# Modify smbd service config
sudo nano /etc/samba/smb.conf
  1. Append the following code snippet to the bottom of /etc/samba/smb.conf
[share]
path = /srv/samba/myshare
valid users = assessor
guest ok = no
writable = yes
browsable = yes
  1. Set smbpasswd and start smbd service
# Set smb password for valid users defined in smb.conf
sudo smbpasswd -a assessor

# Start smbd service
sudo systemctl daemon-reload
sudo systemctl start smbd

# Confirm smb share is configured correctly
sudo systemctl status smbd
smbclient -L localhost -N

File Copy​

danger

OPSEC: Follow the Cleanup procedures after you're done to maintain OPSEC for affected DAL assets

Windows​

danger

OPSEC: Use cmd instead of powershell in case of PowerShell console logging enabled on target Windows host

Map smb share to available network drive letter on target Windows host

# List all currently used drive letters
wmic logical disk get name

# Map available drive letter the smb share set up from Preparation section
net use Z: \\<MIP_IP>\myshare /user:assessor /persistent:no <ASSESSOR_SMBPASSWD>

Use xcopy to copy a single file or multiple files (i.e. directory)

# Copy single target file to smb share
xcopy C:\<SOURCE_FILE> Z:\

# Copy multiple files to smb share
xcopy C:\<SOURCE_FOLDER> Z:\<TARGET_FOLDER> /E /I

Cleanup​

net use Z: /delete

Linux​

Mount smb share on target Linux host

# Create target mount folder
cd /mnt
sudo mkdir -p /myshare
sudo chmod -R 0777 /myshare

# Mount SMB file share vers=3.0
sudo mount -t cifs //<MIP_IP>/myshare /mnt/myshare/ -o username=assessor,password=<ASSESSOR_SMBPASSWD>,vers=3.0

# Use vers=2.1 if version 3 doesn't work
sudo mount -t cifs //<MIP_IP>/myshare /mnt/myshare/ -o username=assessor,password=<ASSESSOR_SMBPASSWD>,vers=2.1

Use cp to copy a single file or multiple files (i.e. directory)

# Copy single target file to smb share
cp <SOURCE_FILE> /mnt/myshare

# Copy multiple files to smb share
cp -r <SOURCE_FOLDER> /mnt/myshare

Cleanup​

sudo umount /mnt/myshare
sudo rm -ri /mnt/myshare # `-i` is interactive prompt before each file removal
# sudo rm -rf /mnt/myshare # or invoke this to force remove all files

# Remove ALL lines containing `sudo mount` with `username=assessor,password=<ASSESSOR_SMBPASSWD>`
sudo nano $HISTFILE
sudo history -r # reload shell in-memory history