Skip to content

Commit 5a33fc2

Browse files
committed
Adding IPv6 support to SMBServer
1 parent 9282c9b commit 5a33fc2

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

examples/smbserver.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@
4242
parser.add_argument('-hashes', action="store", metavar = "LMHASH:NTHASH", help='NTLM hashes for the Username, format is LMHASH:NTHASH')
4343
parser.add_argument('-ts', action='store_true', help='Adds timestamp to every logging output')
4444
parser.add_argument('-debug', action='store_true', help='Turn DEBUG output ON')
45-
parser.add_argument('-ip', '--interface-address', action='store', default='0.0.0.0', help='ip address of listening interface')
45+
parser.add_argument('-ip', '--interface-address', action='store', default=argparse.SUPPRESS, help='ip address of listening interface ("0.0.0.0" or "::" if omitted)')
4646
parser.add_argument('-port', action='store', default='445', help='TCP port for listening incoming connections (default 445)')
47+
parser.add_argument('-6','--ipv6', action='store_true',help='Listen on IPv6')
4748
parser.add_argument('-smb2support', action='store_true', default=False, help='SMB2 Support (experimental!)')
4849
parser.add_argument('-outputfile', action='store', default=None, help='Output file to log smbserver output messages')
4950

@@ -64,7 +65,10 @@
6465
else:
6566
comment = options.comment
6667

67-
server = smbserver.SimpleSMBServer(listenAddress=options.interface_address, listenPort=int(options.port))
68+
if 'interface_address' not in options:
69+
options.interface_address = '::' if options.ipv6 else '0.0.0.0'
70+
71+
server = smbserver.SimpleSMBServer(listenAddress=options.interface_address, listenPort=int(options.port), ipv6=options.ipv6)
6872

6973
if options.outputfile:
7074
logging.info('Switching output to file %s' % options.outputfile)

impacket/smbserver.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3987,7 +3987,14 @@ def finish(self):
39873987

39883988
class SMBSERVER(socketserver.ThreadingMixIn, socketserver.TCPServer):
39893989
# class SMBSERVER(socketserver.ForkingMixIn, socketserver.TCPServer):
3990-
def __init__(self, server_address, handler_class=SMBSERVERHandler, config_parser=None):
3990+
def __init__(self, server_address, handler_class=SMBSERVERHandler, config_parser=None, ipv6=False):
3991+
if ipv6:
3992+
self.address_family = socket.AF_INET6
3993+
# scope_id (after %) can be present or not - if not, default: 0
3994+
ip_parts = server_address[0].split('%')
3995+
scope_id = ip_parts[1] if len(ip_parts) == 2 else 0
3996+
server_address = server_address + (0, scope_id)
3997+
39913998
socketserver.TCPServer.allow_reuse_address = True
39923999
socketserver.TCPServer.__init__(self, server_address, handler_class)
39934000

@@ -4871,10 +4878,9 @@ class SimpleSMBServer:
48714878
:param string configFile: a file with all the servers' configuration. If no file specified, this class will create the basic parameters needed to run. You will need to add your shares manually tho. See addShare() method
48724879
"""
48734880

4874-
def __init__(self, listenAddress='0.0.0.0', listenPort=445, configFile='', smbserverclass=SMBSERVER):
4881+
def __init__(self, listenAddress='0.0.0.0', listenPort=445, configFile='', smbserverclass=SMBSERVER, ipv6=False):
48754882
if configFile != '':
4876-
#self.__server = SMBSERVER((listenAddress, listenPort))
4877-
self.__server = smbserverclass((listenAddress, listenPort))
4883+
self.__server = smbserverclass((listenAddress, listenPort), ipv6=ipv6)
48784884
self.__server.processConfigFile(configFile)
48794885
self.__smbConfig = None
48804886
else:
@@ -4899,7 +4905,7 @@ def __init__(self, listenAddress='0.0.0.0', listenPort=445, configFile='', smbse
48994905
self.__smbConfig.set('IPC$', 'read only', 'yes')
49004906
self.__smbConfig.set('IPC$', 'share type', '3')
49014907
self.__smbConfig.set('IPC$', 'path', '')
4902-
self.__server = smbserverclass((listenAddress, listenPort), config_parser=self.__smbConfig)
4908+
self.__server = smbserverclass((listenAddress, listenPort), config_parser=self.__smbConfig, ipv6=ipv6)
49034909
self.__server.processConfigFile()
49044910

49054911
# Now we have to register the MS-SRVS server. This specially important for

0 commit comments

Comments
 (0)