Smbclient
Smbclient is part of the Samba suite and provides command-line access to SMB/CIFS resources on networks. Used extensively for enumerating and exploiting Windows systems.
Basic Commands
| Command | Description |
|---|---|
smbclient -L //host/share | List shares on target host |
smbclient //host/share -U username | Connect to specific share with credentials |
smbclient //host/share -U username%password | Connect with inline password |
smbclient -L //host -U '' -N | Enumerate shares without credentials (null session) |
smbclient //host/ipc$ -U username | Connect to IPC$ named pipe share |
smbclient --version | Display smbclient version |
smbclient -h | Show help and available options |
Installation
Linux/Ubuntu/Debian
# Install samba client tools
sudo apt update
sudo apt install samba-client
# Verify installation
smbclient --version
Kali Linux
# Pre-installed on Kali, but verify
which smbclient
smbclient --version
macOS
# Via Homebrew
brew install samba
# Or from source
curl -O https://www.samba.org/samba/ftp/samba-latest.tar.gz
tar xzf samba-latest.tar.gz
cd samba-latest && ./configure && make && sudo make install
Share Enumeration
| Command | Description |
|---|---|
smbclient -L 192.168.1.100 -N | List shares without auth |
smbclient -L 192.168.1.100 -U admin%pass | List shares with credentials |
smbclient -L 192.168.1.100 -U 'DOMAIN\user' | List shares using domain credentials |
smbclient //192.168.1.100/C$ -U admin%pass | Connect to hidden admin share |
smbclient //192.168.1.100/Users -U admin%pass | Access Users share on Windows systems |
File Operations
# Download (get) a single file
get filename.txt
# Upload (put) a file to share
put local_file.txt
# Download multiple files with pattern
mget *.txt
# Upload multiple files with pattern
mput *.exe
# List files in current directory
ls
# Change remote directory
cd folder_name
# Create a new directory
mkdir new_folder
# Delete a file
del filename.txt
# Remove a directory
rmdir folder_name
# Show current remote path
pwd
# Download entire folder recursively
recurse on
mget *
Share Navigation
# List all files and subdirectories
ls -la
# Search for files
ls *.doc
# Get file details
stat filename.txt
# View share info
info
# Show share size
du
# List hidden files
ls -a
Exit and Help
# Exit interactive mode
exit
# Show help
help
# Show specific command help
help get
help put
Authentication Methods
# Null session (no credentials)
smbclient //target/share -N
# Username only (prompted for password)
smbclient //target/share -U username
# Inline password
smbclient //target/share -U 'username%password'
# Domain user
smbclient //target/share -U 'DOMAIN\username%password'
# NTLM hash (pass-the-hash)
smbclient //target/share -U 'username' --pw-nt-hash <NTHASH>
# Kerberos authentication
smbclient //target/share -U 'username%password' --kerberos
# Anonymous access with -N flag
smbclient -L //target -N
# Store credentials in env
export USER='domain\username'
export PASSWD='password'
smbclient //target/share
Advanced Usage
Security and Encryption
# Force SMB3 encryption
smbclient //target/share -U user -m SMB3 -e
# Disable SSL/TLS verification
smbclient //target/share -U user --no-ssl-verify
# Use specific SMB version
smbclient //target/share -U user -m SMB2
# Set connection timeout
smbclient //target/share -U user -t 30
# Enable verbose logging
smbclient //target/share -U user -d3
Penetration Testing Workflows
Enumerate and Extract Sensitive Data
# Connect to admin share (requires admin creds)
smbclient //target/C$ -U admin%password
# Download system registry
get Windows\System32\config\SAM
get Windows\System32\config\SYSTEM
# Download password hashes
mget Windows\System32\config\SAM
mget Windows\System32\config\SYSTEM
# Search for interesting files
ls *password*
ls *.txt
mget *.xlsx
Identify Writable Shares
# Test write access with put command
put empty_file.txt
# List shares and check permissions
smbclient -L //target -U user
# Enumerate share permissions
ls -la /
Troubleshooting
Common Issues
Issue: Command not found
# Check if smbclient is installed
which smbclient
smbclient --version
# Check PATH variable
echo $PATH
# Reinstall if necessary
sudo apt reinstall smbclient
# or
brew reinstall smbclient
Issue: Permission denied
# Run with elevated privileges
sudo smbclient <command>
# Check file permissions
ls -la $(which smbclient)
# Fix permissions
chmod +x /usr/local/bin/smbclient
# Check ownership
sudo chown $USER:$USER /usr/local/bin/smbclient
Issue: Configuration errors
# Validate configuration
smbclient config validate
# Reset to default configuration
smbclient config reset
# Check configuration file location
smbclient config show --file
# Backup current configuration
smbclient config export > backup.conf
# Restore from backup
smbclient config import backup.conf
Issue: Service not starting
# Check service status
smbclient status --detailed
# Check system logs
journalctl -u smbclient
# Start in debug mode
smbclient start --debug
# Check port availability
netstat -tulpn|grep <port>
# Kill conflicting processes
smbclient killall --force
Debug Commands
| Command | Description |
|---|---|
smbclient --debug | Enable debug output |
smbclient --verbose | Enable verbose logging |
smbclient --trace | Enable trace logging |
smbclient test | Run built-in tests |
smbclient doctor | Run system health check |
smbclient diagnose | Generate diagnostic report |
smbclient benchmark | Run performance benchmarks |
smbclient validate | Validate installation and configuration |
Performance Optimization
Resource Management
# Set memory limit
smbclient --max-memory 1G <command>
# Set CPU limit
smbclient --max-cpu 2 <command>
# Enable caching
smbclient --cache-enabled <command>
# Set cache size
smbclient --cache-size 100M <command>
# Clear cache
smbclient cache clear
# Show cache statistics
smbclient cache stats
# Optimize performance
smbclient optimize --profile <profile>
# Show performance metrics
smbclient metrics
Parallel Processing
# Enable parallel processing
smbclient --parallel <command>
# Set number of workers
smbclient --workers 4 <command>
# Process in batches
smbclient --batch-size 100 <command>
# Queue management
smbclient queue add <item>
smbclient queue process
smbclient queue status
smbclient queue clear
Integration
Scripting
#!/bin/bash
# Example script using smbclient
set -euo pipefail
# Configuration
CONFIG_FILE="config.yaml"
LOG_FILE="smbclient.log"
# Check if smbclient is available
if ! command -v smbclient &> /dev/null; then
echo "Error: smbclient is not installed" >&2
exit 1
fi
# Function to log messages
log() \\\\{
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1"|tee -a "$LOG_FILE"
\\\\}
# Main operation
main() \\\\{
log "Starting smbclient operation"
if smbclient --config "$CONFIG_FILE" run; then
log "Operation completed successfully"
exit 0
else
log "Operation failed with exit code $?"
exit 1
fi
\\\\}
# Cleanup function
cleanup() \\\\{
log "Cleaning up"
smbclient cleanup
\\\\}
# Set trap for cleanup
trap cleanup EXIT
# Run main function
main "$@"
API Integration
Environment Variables
| Variable | Description | Default |
|---|---|---|
SMBCLIENT_CONFIG | Configuration file path | ~/.smbclient/config.yaml |
SMBCLIENT_HOME | Home directory | ~/.smbclient |
SMBCLIENT_LOG_LEVEL | Logging level | INFO |
SMBCLIENT_LOG_FILE | Log file path | ~/.smbclient/logs/smbclient.log |
SMBCLIENT_CACHE_DIR | Cache directory | ~/.smbclient/cache |
SMBCLIENT_DATA_DIR | Data directory | ~/.smbclient/data |
SMBCLIENT_TIMEOUT | Default timeout | 30s |
SMBCLIENT_MAX_WORKERS | Maximum workers | 4 |
Configuration File
# ~/.smbclient/config.yaml
version: "1.0"
# General settings
settings:
debug: false
verbose: false
log_level: "INFO"
log_file: "~/.smbclient/logs/smbclient.log"
timeout: 30
max_workers: 4
# Network configuration
network:
host: "localhost"
port: 8080
ssl: true
timeout: 30
retries: 3
# Security settings
security:
auth_required: true
api_key: ""
encryption: "AES256"
verify_ssl: true
# Performance settings
performance:
cache_enabled: true
cache_size: "100M"
cache_dir: "~/.smbclient/cache"
max_memory: "1G"
# Monitoring settings
monitoring:
enabled: true
interval: 60
metrics_enabled: true
alerts_enabled: true
Examples
Basic Workflow
# 1. Initialize smbclient
smbclient init
# 2. Configure basic settings
smbclient config set port 8080
# 3. Start service
smbclient start
# 4. Check status
smbclient status
# 5. Perform operations
smbclient run --target example.com
# 6. View results
smbclient results
# 7. Stop service
smbclient stop
Advanced Workflow
# Comprehensive operation with monitoring
smbclient run \
--config production.yaml \
--parallel \
--workers 8 \
--verbose \
--timeout 300 \
--output json \
--log-file operation.log
# Monitor in real-time
smbclient monitor --real-time --interval 5
# Generate report
smbclient report --type comprehensive --output report.html
Automation Example
#!/bin/bash
# Automated smbclient workflow
# Configuration
TARGETS_FILE="targets.txt"
RESULTS_DIR="results/$(date +%Y-%m-%d)"
CONFIG_FILE="automation.yaml"
# Create results directory
mkdir -p "$RESULTS_DIR"
# Process each target
while IFS= read -r target; do
echo "Processing $target..."
smbclient \
--config "$CONFIG_FILE" \
--output json \
--output-file "$RESULTS_DIR/$\\\\{target\\\\}.json" \
run "$target"
done < "$TARGETS_FILE"
# Generate summary report
smbclient report summary \
--input "$RESULTS_DIR/*.json" \
--output "$RESULTS_DIR/summary.html"
Best Practices
Security
- Always verify checksums when downloading binaries
- Use strong authentication methods (API keys, certificates)
- Regularly update to the latest version
- Follow principle of least privilege
- Enable audit logging for compliance
- Use encrypted connections when possible
- Validate all inputs and configurations
- Implement proper access controls
Performance
- Use appropriate resource limits for your environment
- Monitor system performance regularly
- Optimize configuration for your use case
- Use parallel processing when beneficial
- Implement proper caching strategies
- Regular maintenance and cleanup
- Profile performance bottlenecks
- Use efficient algorithms and data structures
Operational
- Maintain comprehensive documentation
- Implement proper backup strategies
- Use version control for configurations
- Monitor and alert on critical metrics
- Implement proper error handling
- Use automation for repetitive tasks
- Regular security audits and updates
- Plan for disaster recovery
Development
- Follow coding standards and conventions
- Write comprehensive tests
- Use continuous integration/deployment
- Implement proper logging and monitoring
- Document APIs and interfaces
- Use version control effectively
- Review code regularly
- Maintain backward compatibility
Resources
Official Documentation
Community Resources
Learning Resources
- Getting Started Guide
- Tutorial Series
- Best Practices Guide
- Video Tutorials
- Training Courses
- Certification Program
Related Tools
- Git - Complementary functionality
- Docker - Alternative solution
- Kubernetes - Integration partner
Last updated: 2025-07-06|Edit on GitHub