github.com/Coalfire-Research/Slackor@v0.0.0-20191010164036-aa32a7f9250b/impacket/examples/smbserver.py (about) 1 #!/usr/bin/env python 2 # SECUREAUTH LABS. Copyright 2018 SecureAuth Corporation. All rights reserved. 3 # 4 # This software is provided under under a slightly modified version 5 # of the Apache Software License. See the accompanying LICENSE file 6 # for more information. 7 # 8 # Simple SMB Server example. 9 # 10 # Author: 11 # Alberto Solino (@agsolino) 12 # 13 14 import sys 15 import argparse 16 import logging 17 18 from impacket.examples import logger 19 from impacket import smbserver, version 20 from impacket.ntlm import compute_lmhash, compute_nthash 21 22 if __name__ == '__main__': 23 24 # Init the example's logger theme 25 logger.init() 26 print(version.BANNER) 27 28 parser = argparse.ArgumentParser(add_help = True, description = "This script will launch a SMB Server and add a " 29 "share specified as an argument. You need to be root in order to bind to port 445. " 30 "No authentication will be enforced. Example: smbserver.py -comment 'My share' TMP " 31 "/tmp") 32 33 parser.add_argument('shareName', action='store', help='name of the share to add') 34 parser.add_argument('sharePath', action='store', help='path of the share to add') 35 parser.add_argument('-comment', action='store', help='share\'s comment to display when asked for shares') 36 parser.add_argument('-username', action="store", help='Username to authenticate clients') 37 parser.add_argument('-password', action="store", help='Password for the Username') 38 parser.add_argument('-hashes', action="store", metavar = "LMHASH:NTHASH", help='NTLM hashes for the Username, format is LMHASH:NTHASH') 39 parser.add_argument('-debug', action='store_true', help='Turn DEBUG output ON') 40 parser.add_argument('-ip', '--interface-address', action='store', default='0.0.0.0', help='ip address of listening interface') 41 parser.add_argument('-port', action='store', default='445', help='TCP port for listening incoming connections (default 445)') 42 parser.add_argument('-smb2support', action='store_true', default=False, help='SMB2 Support (experimental!)') 43 44 if len(sys.argv)==1: 45 parser.print_help() 46 sys.exit(1) 47 48 try: 49 options = parser.parse_args() 50 except Exception as e: 51 logging.critical(str(e)) 52 sys.exit(1) 53 54 if options.debug is True: 55 logging.getLogger().setLevel(logging.DEBUG) 56 else: 57 logging.getLogger().setLevel(logging.INFO) 58 59 if options.comment is None: 60 comment = '' 61 else: 62 comment = options.comment 63 64 server = smbserver.SimpleSMBServer(listenAddress=options.interface_address, listenPort=int(options.port)) 65 66 server.addShare(options.shareName.upper(), options.sharePath, comment) 67 server.setSMB2Support(options.smb2support) 68 69 # If a user was specified, let's add it to the credentials for the SMBServer. If no user is specified, anonymous 70 # connections will be allowed 71 if options.username is not None: 72 # we either need a password or hashes, if not, ask 73 if options.password is None and options.hashes is None: 74 from getpass import getpass 75 password = getpass("Password:") 76 # Let's convert to hashes 77 lmhash = compute_lmhash(password) 78 nthash = compute_nthash(password) 79 elif options.password is not None: 80 lmhash = compute_lmhash(options.password) 81 nthash = compute_nthash(options.password) 82 else: 83 lmhash, nthash = options.hashes.split(':') 84 85 server.addCredential(options.username, 0, lmhash, nthash) 86 87 # Here you can set a custom SMB challenge in hex format 88 # If empty defaults to '4141414141414141' 89 # (remember: must be 16 hex bytes long) 90 # e.g. server.setSMBChallenge('12345678abcdef00') 91 server.setSMBChallenge('') 92 93 # If you don't want log to stdout, comment the following line 94 # If you want log dumped to a file, enter the filename 95 server.setLogFile('') 96 97 # Rock and roll 98 server.start()