Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix external module encoding #15590

Merged
merged 1 commit into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We traced down the original use of this method to #10002 which allows datastore values to be a nested array, which I'm not sure is something we'd want

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