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

Reduce Unknown commands handling from 1 second to 0.5 seconds #13148

Merged
merged 3 commits into from
Apr 1, 2020
Merged
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion lib/msf/core/module_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def create(name, aliased_as: nil)
module_instance = create(aliased, aliased_as: "#{type}/#{name}")
else
module_reference_name = names.join("/")
module_instance = set.create(module_reference_name)
module_instance = set.has_key?(module_reference_name) ? set.create(module_reference_name) : nil
Copy link
Contributor

Choose a reason for hiding this comment

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

The function that takes ~1 second to execute is the PayloadSet's recalculate method. There's a comment on the code that this approach may not work as we expect:

###
#
# This class is a special case of the generic module set class because
# payloads are generated in terms of combinations between various
# components, such as a stager and a stage. As such, the payload set
# needs to be built on the fly and cannot be simply matched one-to-one
# with a payload module. Yeah, the term module is kind of overloaded
# here, but eat it!
#
###
class PayloadSet < ModuleSet

We might need a different approach to the above, but it's worth double checking.

Copy link
Contributor

Choose a reason for hiding this comment

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

Poking further at this; I'm concerned that this approach breaks the law of demeter, and may not work well with some of the assumptions that are already in place within framework. In particular it seems like module set already has some nil handling in place:

# If there is no module associated with this class, then try to demand
# load it.
if klass.nil? or klass == Msf::SymbolicModule
framework.modules.load_cached_module(module_type, reference_name)
recalculate
klass = fetch(reference_name, nil)
end

Which is actually why the slow recalculate method gets called in the first place. It might be worth doing a bit of git fu to learn why that logic was added in the first place, to make sure this approach doesn't break existing logic etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cross referencing some discussion on bootup/missing command performance - #7292 (comment)

end
break if module_instance
end
Expand Down