Skip to content

Instantly share code, notes, and snippets.

@ilyaglow
Last active May 30, 2017 02:16
Show Gist options
  • Save ilyaglow/a88654faea907b9ea7fffb7111c5b2d6 to your computer and use it in GitHub Desktop.
Save ilyaglow/a88654faea907b9ea7fffb7111c5b2d6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#
# Check SMB dialects host supports
#
# Dependencies:
# pip install impacket
#
# Usage:
# ./check_smb_dialects.py <host>
#
import sys
from impacket.smbconnection import *
from impacket import smb, smb3
SMB2_DIALECTS = {
'SMBv2': SMB2_DIALECT_002,
'SMBv2.1': SMB2_DIALECT_21,
'SMBv3': SMB2_DIALECT_30
}
SMB_TIMEOUT = 3
def test_dialects(host):
try_smbv1(host)
for dialect in SMB2_DIALECTS.items():
try_smbv2(host, dialect)
def try_smbv1(host):
connection = SMBConnection(host,
host,
timeout=SMB_TIMEOUT,
preferredDialect=SMB_DIALECT)
if isinstance(connection, SMBConnection):
print("{} supports SMBv1".format(host))
else:
print("{} doesn't support SMBv1".format(host))
def try_smbv2(host, dialect):
try:
connection = SMBConnection(host,
host,
timeout=SMB_TIMEOUT,
preferredDialect=dialect[1])
print("{} supports {}".format(host, dialect[0]))
except smb3.SessionError:
print("{} doesn't support {}".format(host, dialect[0]))
if __name__ == "__main__":
host = sys.argv[1]
test_dialects(host)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment