Skip to content

Commit 4fc258e

Browse files
committed
Remove duplicate entries, allow for output to file
This commit does a few tidies of code, as well as adds the ability to write all the kiwi output to disk as well as to the console. We can't yet add this stuff to the credential DB because it's tied to machine, where the creds that come out of kiwi are often tied to domains. This also removes duplicate creds from the output list, and gets rid of the auth id stuff from the output too (not sure why it was useful before).
1 parent 8bb7496 commit 4fc258e

File tree

2 files changed

+131
-94
lines changed
  • lib/rex/post/meterpreter

2 files changed

+131
-94
lines changed

lib/rex/post/meterpreter/extensions/kiwi/kiwi.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require 'rex/post/meterpreter/extensions/kiwi/tlv'
44
require 'rexml/document'
5+
require 'set'
56

67
module Rex
78
module Post
@@ -283,9 +284,12 @@ def scrape_passwords(pwd_id)
283284
request.add_tlv(TLV_TYPE_KIWI_PWD_ID, pwd_id)
284285
response = client.send_request(request)
285286

287+
# keep track of unique entries
288+
uniques = Set.new
289+
286290
results = []
287291
response.each(TLV_TYPE_KIWI_PWD_RESULT) do |r|
288-
results << {
292+
result = {
289293
:username => r.get_tlv_value(TLV_TYPE_KIWI_PWD_USERNAME),
290294
:domain => r.get_tlv_value(TLV_TYPE_KIWI_PWD_DOMAIN),
291295
:password => r.get_tlv_value(TLV_TYPE_KIWI_PWD_PASSWORD),
@@ -294,6 +298,17 @@ def scrape_passwords(pwd_id)
294298
:lm => r.get_tlv_value(TLV_TYPE_KIWI_PWD_LMHASH),
295299
:ntlm => r.get_tlv_value(TLV_TYPE_KIWI_PWD_NTLMHASH)
296300
}
301+
302+
# generate a "unique" set identifier based on the domain/user/pass. We
303+
# don't use the whole object because the auth hi/low might be different
304+
# but everything else might be the same. Join with non-printable, as this
305+
# can't appear in passwords anyway.
306+
set_id = [result[:domain], result[:username], result[:password]].join("\x01")
307+
308+
# only add to the result list if we don't already have it
309+
if uniques.add?(set_id)
310+
results << result
311+
end
297312
end
298313

299314
return results

0 commit comments

Comments
 (0)