Skip to content

Commit

Permalink
Adding parameter "-outputfile" to set smbserver log file. (#1784)
Browse files Browse the repository at this point in the history
* Adding parameter "-outputfile" to set smbserver log file.

* Fixing log object
  • Loading branch information
gabrielg5 authored Aug 5, 2024
1 parent 6d8dd85 commit 2a0603a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions examples/smbserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
parser.add_argument('-ip', '--interface-address', action='store', default='0.0.0.0', help='ip address of listening interface')
parser.add_argument('-port', action='store', default='445', help='TCP port for listening incoming connections (default 445)')
parser.add_argument('-smb2support', action='store_true', default=False, help='SMB2 Support (experimental!)')
parser.add_argument('-outputfile', action='store', default=None, help='Output file to log smbserver output messages')

if len(sys.argv)==1:
parser.print_help()
Expand Down Expand Up @@ -70,6 +71,10 @@

server = smbserver.SimpleSMBServer(listenAddress=options.interface_address, listenPort=int(options.port))

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

server.addShare(options.shareName.upper(), options.sharePath, comment)
server.setSMB2Support(options.smb2support)

Expand Down Expand Up @@ -97,9 +102,5 @@
# e.g. server.setSMBChallenge('12345678abcdef00')
server.setSMBChallenge('')

# If you don't want log to stdout, comment the following line
# If you want log dumped to a file, enter the filename
server.setLogFile('')

# Rock and roll
server.start()
3 changes: 2 additions & 1 deletion impacket/smbserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4671,7 +4671,8 @@ def processConfigFile(self, configFile=None):
logging.basicConfig(filename=self.__logFile,
level=logging.DEBUG,
format="%(asctime)s: %(levelname)s: %(message)s",
datefmt='%m/%d/%Y %I:%M:%S %p')
datefmt='%m/%d/%Y %I:%M:%S %p',
force=True)
self.__log = LOG

# Process the credentials
Expand Down

0 comments on commit 2a0603a

Please sign in to comment.