Skip to content

Commit

Permalink
Fix external module encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanusz-r7 committed Aug 25, 2021
1 parent 8ac6303 commit 83c27b2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions lib/msf/core/data_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,23 @@ def to_h
end

# Hack on a hack for the external modules
def to_nested_values
def to_external_message_h
datastore_hash = {}

array_nester = ->(arr) do
if arr.first.is_a? Array
arr.map &array_nester
else
arr.map &:to_s
arr.map { |item| item.to_s.dup.force_encoding('UTF-8') }
end
end

self.keys.each do |k|
# TODO arbitrary depth
if self[k].is_a? Array
datastore_hash[k.to_s] = array_nester.call(self[k])
datastore_hash[k.to_s.dup.force_encoding('UTF-8')] = array_nester.call(self[k])
else
datastore_hash[k.to_s] = self[k].to_s
datastore_hash[k.to_s.dup.force_encoding('UTF-8')] = self[k].to_s.dup.force_encoding('UTF-8')
end
end
datastore_hash
Expand Down Expand Up @@ -331,4 +331,3 @@ def find_key_case(k)
end

end

4 changes: 2 additions & 2 deletions lib/msf/core/modules/external/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def initialize(m)

def to_json
params =
if self.params.respond_to? :to_nested_values
self.params.to_nested_values
if self.params.respond_to? :to_external_message_h
self.params.to_external_message_h
else
self.params.to_h
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def run_scanner(args, login_callback):
rport = int(args['rport'])
sleep_interval = float(args['sleep_interval'] or 0)
# python 2/3 compatibility hack
if isinstance(userpass, str) or ('unicode' in vars(__builtins__) and isinstance(userpass, unicode)):
if isinstance(userpass, str) or ('unicode' in dir(__builtins__) and isinstance(userpass, unicode)):
userpass = [ attempt.split(' ', 1) for attempt in userpass.splitlines() ]

curr = 0
Expand Down

0 comments on commit 83c27b2

Please sign in to comment.