smbclient

smbclient Cheat Sheet

Below is a cheat sheet for smbclient, a command-line tool used to access and manipulate files on servers running the Server Message Block (SMB) protocol, commonly used in Windows networks:

Basic Usage:

  1. Connect to a Share:
   smbclient //<server>/<share> -U <username>
  1. Authenticate with Password:
   smbclient //<server>/<share> -U <username>%<password>
  1. Anonymous Connection:
   smbclient //<server>/<share>

Commands:

  1. ls – List Files:
   smb: \> ls
  1. cd – Change Directory:
   smb: \> cd <directory>
  1. get – Download File:
   smb: \> get <filename>
  1. put – Upload File:
   smb: \> put <local_file>
  1. mget – Download Multiple Files:
   smb: \> mget <pattern>
  1. mput – Upload Multiple Files:
   smb: \> mput <pattern>
  1. mkdir – Create Directory:
   smb: \> mkdir <directory>
  1. rmdir – Remove Directory:
   smb: \> rmdir <directory>
  1. rm – Remove File:
   smb: \> rm <filename>
  1. rename – Rename File: smb: \> rename <old_name> <new_name>
  2. prompt – Toggle Interactive Mode: smb: \> prompt
  3. quit or exit – Quit smbclient:
    smb: \> quit

Options:

  1. -U – Specify Username:
   smbclient //<server>/<share> -U <username>
  1. -N – Use Null Session:
   smbclient //<server>/<share> -N
  1. -W – Specify Workgroup:
   smbclient //<server>/<share> -W <workgroup>
  1. -c – Execute Commands:
   smbclient //<server>/<share> -U <username> -c 'ls; get <filename>'

Examples:

  1. Connect and List Files:
   smbclient //server/share -U username
   smb: \> ls
  1. Download File:
   smbclient //server/share -U username
   smb: \> get file.txt
  1. Upload File:
   smbclient //server/share -U username
   smb: \> put local_file.txt
  1. Interactive Mode:
   smbclient //server/share -U username
   smb: \> prompt
  1. Connect with Null Session:
   smbclient //server/share -N

Note:

  • Ensure you have necessary permissions to access the SMB share.
  • Replace placeholders like <server>, <share>, <username>, and <password> with actual values.
  • Use -N for null sessions only if allowed and required.

Resources:

This cheat sheet provides an overview of common smbclient commands and options for accessing and interacting with SMB shares. Adjustments may be necessary based on specific requirements and configurations. Always ensure compliance with security policies and legal regulations when accessing remote systems.