Skip to content

Instantly share code, notes, and snippets.

@3isenHeiM
Created April 20, 2021 12:49
Show Gist options
  • Save 3isenHeiM/cadf05f8e24eec0d347fa2a916a68ff9 to your computer and use it in GitHub Desktop.
Save 3isenHeiM/cadf05f8e24eec0d347fa2a916a68ff9 to your computer and use it in GitHub Desktop.
Get the SMB version from a tcpdump capture
#!/bin/sh
# Author: rewardone / 3isenHeiM
# Description:
# Requires root or enough permissions to use tcpdump
# Will listen for the first 8 packets of a null login
# and grab the SMB Version
# Notes:
# Will sometimes not capture or will print multiple
# lines. May need to run a second time for success.
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
echo "Usage: sudo $0 RHOST {RPORT}"
exit 1
fi
# Check Usage
if [ -z $1 ]; then echo "Usage: sudo $0 RHOST {RPORT}" && exit; else rhost=$1; fi
#Set port
if [ ! -z $2 ]; then rport=$2; else rport=139; fi
tcpdump -s0 -n -i tun0 src $rhost and port $rport -A -c 10 2>/dev/null | grep -i "samba\|s.a.m" | tr -d '.' | grep -oP 'UnixSamba.*[0-9a-z]' | tr -d '\n' & echo -n "$rhost: " &
echo "exit" | smbclient -L $rhost 1>/dev/null 2>/dev/null
echo "" && sleep .1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment