Skip to content

Commit

Permalink
Option to export hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
helviojunior committed Jul 30, 2024
1 parent 0e5a645 commit 15b42e0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
39 changes: 36 additions & 3 deletions knowsmore/cmd/hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ImportMode(Enum):
Cracked = 2
Password = 3
ExportHashes = 4
ExportCrackedHashes = 5

filename = ''
db = None
Expand Down Expand Up @@ -62,6 +63,13 @@ def add_commands(self, cmds: _ArgumentGroup):
dest=f'crackedfile',
help=Color.s('Hashcat cracked hashes filename. (format: {G}hash{R}:{G}password{W})'))

cmds.add_argument('--export-cracked',
action='store',
metavar='[cracked file]',
type=str,
dest=f'export_cracked_file',
help=Color.s('Hashcat cracked hashes filename. (format: {G}hash{R}:{G}password{W})'))

cmds.add_argument('--add-password',
action='store',
metavar='[clear text password]',
Expand Down Expand Up @@ -102,6 +110,25 @@ def load_from_arguments(self, args: Namespace) -> bool:
self.mode = NTLMHash.ImportMode.ExportHashes
self.filename = args.export_file

elif args.export_cracked_file is not None and args.export_cracked_file != '':
try:
with open(args.export_cracked_file, 'a') as f:
# file opened for writing. write to it here
pass
except IOError as x:
if x.errno == errno.EACCES:
Logger.pl('{!} {R}error: could not open NTLM hashes file {O}permission denied{R}{W}\r\n')
Tools.exit_gracefully(1)
elif x.errno == errno.EISDIR:
Logger.pl('{!} {R}error: could not open NTLM hashes file {O}it is an directory{R}{W}\r\n')
Tools.exit_gracefully(1)
else:
Logger.pl('{!} {R}error: could not open NTLM hashes file {W}\r\n')
Tools.exit_gracefully(1)

self.mode = NTLMHash.ImportMode.ExportCrackedHashes
self.filename = args.export_cracked_file

else:
if (args.ntlmfile is None or args.ntlmfile.strip() == '') and \
(args.crackedfile is None or args.crackedfile.strip() == ''):
Expand Down Expand Up @@ -164,9 +191,12 @@ def load_from_arguments(self, args: Namespace) -> bool:
return True

def run(self):
if self.mode == NTLMHash.ImportMode.ExportHashes:
if self.mode in [NTLMHash.ImportMode.ExportHashes, NTLMHash.ImportMode.ExportCrackedHashes]:
sql = 'select distinct p.ntlm_hash, p.password from passwords p'
if self.mode == NTLMHash.ImportMode.ExportCrackedHashes:
sql += ' where p.password <> ""'
rows = self.db.select_raw(
sql='select distinct ntlm_hash from passwords',
sql=sql,
args=[]
)

Expand All @@ -175,7 +205,10 @@ def run(self):
try:
with open(self.filename, 'w', encoding="UTF-8") as f:
for row in rows:
f.write(f'{row["ntlm_hash"]}\n')
if self.mode == NTLMHash.ImportMode.ExportCrackedHashes:
f.write(f'{row["ntlm_hash"]}:{row["password"]}\n')
else:
f.write(f'{row["ntlm_hash"]}\n')
pass
except KeyboardInterrupt as e:
raise e
Expand Down
2 changes: 1 addition & 1 deletion knowsmore/cmd/memberof.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def run(self):
args = [f'%{self.find_text}%']

if self.cracked_only:
sql += ' and (p.length > 0) '
sql += ' and (p.password <> "") '

sql += ' order by g2.name, c.enabled DESC, c.name'

Expand Down

0 comments on commit 15b42e0

Please sign in to comment.