Skip to content

Commit 678cd0a

Browse files
p0rtL6p0rtL6gabrielg5
authored
Add the Option to Dump Ntlm Hashes in Ntlmrelayx (#1904)
* Add option to dump relayed hashes to console (ntlmrelayx) * Add Documentation * Simplify print statements * Update README.md Reverted changes in the README.md file in preparation for merge. --------- Co-authored-by: p0rtL6 <[email protected]> Co-authored-by: Gabriel Gonzalez <[email protected]>
1 parent 6e0a969 commit 678cd0a

File tree

7 files changed

+37
-1
lines changed

7 files changed

+37
-1
lines changed

examples/ntlmrelayx.py

+2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ def start_servers(options, threads):
192192
c.setAttacks(PROTOCOL_ATTACKS)
193193
c.setLootdir(options.lootdir)
194194
c.setOutputFile(options.output_file)
195+
c.setdumpHashes(options.dump_hashes)
195196
c.setLDAPOptions(options.no_dump, options.no_da, options.no_acl, options.no_validate_privs, options.escalate_user, options.add_computer, options.delegate_access, options.dump_laps, options.dump_gmsa, options.dump_adcs, options.sid, options.add_dns_record)
196197
c.setRPCOptions(options.rpc_mode, options.rpc_use_smb, options.auth_smb, options.hashes_smb, options.rpc_smb_port)
197198
c.setMSSQLOptions(options.query)
@@ -306,6 +307,7 @@ def stop_servers(threads):
306307
'directory in which gathered loot such as SAM dumps will be stored (default: current directory).')
307308
parser.add_argument('-of','--output-file', action='store',help='base output filename for encrypted hashes. Suffixes '
308309
'will be added for ntlm and ntlmv2')
310+
parser.add_argument('-dh','--dump-hashes', action='store_true', default=False, help='show encrypted hashes in the console')
309311
parser.add_argument('-codec', action='store', help='Sets encoding used (codec) from the target\'s output (default '
310312
'"%s"). If errors are detected, run chcp.com at the target, '
311313
'map the result with '

impacket/examples/ntlmrelayx/servers/httprelayserver.py

+3
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,9 @@ def do_relay(self, messageType, token, proxy, content = None):
480480
authenticateMessage['lanman'], authenticateMessage['ntlm'])
481481
self.client.sessionData['JOHN_OUTPUT'] = ntlm_hash_data
482482

483+
if self.server.config.dumpHashes is True:
484+
LOG.info(ntlm_hash_data['hash_string'])
485+
483486
if self.server.config.outputFile is not None:
484487
writeJohnOutputToFile(ntlm_hash_data['hash_string'], ntlm_hash_data['hash_version'],
485488
self.server.config.outputFile)

impacket/examples/ntlmrelayx/servers/rawrelayserver.py

+3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ def handle(self):
130130
authenticateMessage['lanman'], authenticateMessage['ntlm'])
131131
self.client.sessionData['JOHN_OUTPUT'] = ntlm_hash_data
132132

133+
if self.server.config.dumpHashes is True:
134+
LOG.info(ntlm_hash_data['hash_string'])
135+
133136
if self.server.config.outputFile is not None:
134137
writeJohnOutputToFile(ntlm_hash_data['hash_string'], ntlm_hash_data['hash_version'],
135138
self.server.config.outputFile)

impacket/examples/ntlmrelayx/servers/smbrelayserver.py

+14
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ def __init__(self,config):
9191
if self.config.outputFile is not None:
9292
smbConfig.set('global','jtr_dump_path',self.config.outputFile)
9393

94+
if self.config.dumpHashes is True:
95+
smbConfig.set("global", "dump_hashes", "True")
96+
else:
97+
smbConfig.set("global", "dump_hashes", "False")
98+
9499
if self.config.SMBServerChallenge is not None:
95100
smbConfig.set('global', 'challenge', self.config.SMBServerChallenge)
96101

@@ -373,6 +378,9 @@ def SmbSessionSetup(self, connId, smbServer, recvPacket):
373378
authenticateMessage['ntlm'])
374379
client.sessionData['JOHN_OUTPUT'] = ntlm_hash_data
375380

381+
if self.server.getDumpHashes():
382+
LOG.info(ntlm_hash_data['hash_string'])
383+
376384
if self.server.getJTRdumpPath() != '':
377385
writeJohnOutputToFile(ntlm_hash_data['hash_string'], ntlm_hash_data['hash_version'],
378386
self.server.getJTRdumpPath())
@@ -667,6 +675,9 @@ def SmbSessionSetupAndX(self, connId, smbServer, SMBCommand, recvPacket):
667675
authenticateMessage['lanman'], authenticateMessage['ntlm'])
668676
client.sessionData['JOHN_OUTPUT'] = ntlm_hash_data
669677

678+
if self.server.getDumpHashes():
679+
LOG.info(ntlm_hash_data['hash_string'])
680+
670681
if self.server.getJTRdumpPath() != '':
671682
writeJohnOutputToFile(ntlm_hash_data['hash_string'], ntlm_hash_data['hash_version'],
672683
self.server.getJTRdumpPath())
@@ -742,6 +753,9 @@ def SmbSessionSetupAndX(self, connId, smbServer, SMBCommand, recvPacket):
742753
sessionSetupData['AnsiPwd'], sessionSetupData['UnicodePwd'])
743754
client.sessionData['JOHN_OUTPUT'] = ntlm_hash_data
744755

756+
if self.server.getDumpHashes():
757+
LOG.info(ntlm_hash_data['hash_string'])
758+
745759
if self.server.getJTRdumpPath() != '':
746760
writeJohnOutputToFile(ntlm_hash_data['hash_string'], ntlm_hash_data['hash_version'],
747761
self.server.getJTRdumpPath())

impacket/examples/ntlmrelayx/servers/wcfrelayserver.py

+3
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ def handle(self):
270270
authenticateMessage['lanman'], authenticateMessage['ntlm'])
271271
self.client.sessionData['JOHN_OUTPUT'] = ntlm_hash_data
272272

273+
if self.server.config.dumpHashes is True:
274+
LOG.info(ntlm_hash_data['hash_string'])
275+
273276
if self.server.config.outputFile is not None:
274277
writeJohnOutputToFile(ntlm_hash_data['hash_string'], ntlm_hash_data['hash_version'],
275278
self.server.config.outputFile)

impacket/examples/ntlmrelayx/utils/config.py

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(self):
3838
self.mode = None
3939
self.redirecthost = None
4040
self.outputFile = None
41+
self.dumpHashes = False
4142
self.attacks = None
4243
self.lootdir = None
4344
self.randomtargets = False
@@ -133,6 +134,9 @@ def setRunSocks(self, socks, server):
133134
def setOutputFile(self, outputFile):
134135
self.outputFile = outputFile
135136

137+
def setdumpHashes(self, dumpHashes):
138+
self.dumpHashes = dumpHashes
139+
136140
def setTargets(self, target):
137141
self.target = target
138142

impacket/smbserver.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -4358,6 +4358,9 @@ def setServerConfig(self, config):
43584358
def getJTRdumpPath(self):
43594359
return self.__jtr_dump_path
43604360

4361+
def getDumpHashes(self):
4362+
return self.__dump_hashes
4363+
43614364
def getAuthCallback(self):
43624365
return self.auth_callback
43634366

@@ -4674,12 +4677,16 @@ def processConfigFile(self, configFile=None):
46744677
if self.__serverConfig.has_option("global", "jtr_dump_path"):
46754678
self.__jtr_dump_path = self.__serverConfig.get("global", "jtr_dump_path")
46764679

4680+
if self.__serverConfig.has_option("global", "dump_hashes"):
4681+
self.__dump_hashes = self.__serverConfig.getboolean("global", "dump_hashes")
4682+
else:
4683+
self.__dump_hashes = False
4684+
46774685
if self.__serverConfig.has_option("global", "SMB2Support"):
46784686
self.__SMB2Support = self.__serverConfig.getboolean("global", "SMB2Support")
46794687
else:
46804688
self.__SMB2Support = False
46814689

4682-
46834690
if self.__serverConfig.has_option("global", "anonymous_logon"):
46844691
self.__anonymousLogon = self.__serverConfig.getboolean("global", "anonymous_logon")
46854692
else:

0 commit comments

Comments
 (0)