-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
Adding an option to specify a target URL #13766
Closed
Closed
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
25305ee
Add WrappedTable support with feature flag integration
adfoster-r7 fdb4499
Add feature configuration persistence
adfoster-r7 a644a58
Add rhost url macro
dwelch-r7 729e83a
Add new rhost url option
dwelch-r7 cc52f3a
Check for an RHOSTS entry before attempting to create a URI
dwelch-r7 79c0c43
remove leading `//` from rhost url option
dwelch-r7 53e89f7
If no path is specified default to `/`
dwelch-r7 d72b846
Add some extra validation and checks
dwelch-r7 13fcabe
Ran rubocop
dwelch-r7 4125f75
Code review changes
dwelch-r7 fbd0d0e
Refactor rhost_url to be http/https only
dwelch-r7 dd0a883
use HTTP/HTTPS uris when re-calculating the URI
dwelch-r7 6c0d3bf
Add initial test suite for rhost url
dwelch-r7 b14a74e
More tests
dwelch-r7 f4def25
Add guard clause
dwelch-r7 1a634fc
Add feature flag and start fixing tests
dwelch-r7 0fdac85
More test fixes
dwelch-r7 ffbc5cb
Fixed all tests
dwelch-r7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -43,14 +43,23 @@ def []=(k, v) | |||||||
end | ||||||||
end | ||||||||
|
||||||||
super(k,v) | ||||||||
if v.is_a? Hash | ||||||||
v.each { |key, value| self[key] = value } | ||||||||
else | ||||||||
super(k,v) | ||||||||
end | ||||||||
end | ||||||||
|
||||||||
# | ||||||||
# Case-insensitive wrapper around hash lookup | ||||||||
# | ||||||||
def [](k) | ||||||||
super(find_key_case(k)) | ||||||||
k = find_key_case(k) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
if options[k].respond_to? :calculate_value | ||||||||
options[k].calculate_value(self) | ||||||||
else | ||||||||
super(k) | ||||||||
end | ||||||||
end | ||||||||
|
||||||||
# | ||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# -*- coding: binary -*- | ||
# frozen_string_literal: true | ||
|
||
require 'msf/core/plugin' | ||
|
||
module Msf | ||
### | ||
# | ||
# The feature manager is responsible for managing feature flags that can change characteristics of framework. | ||
# Each feature will have a default value. The user can choose to override this default value if they wish. | ||
### | ||
class FeatureManager | ||
|
||
include Singleton | ||
|
||
CONFIG_KEY = 'framework/features' | ||
WRAPPED_TABLES = 'wrapped_tables' | ||
DEFAULTS = [ | ||
{ | ||
name: 'wrapped_tables', | ||
description: 'When enabled Metasploit will wordwrap all tables to fit into the available terminal width', | ||
default_value: false | ||
}.freeze | ||
].freeze | ||
|
||
# | ||
# Initializes the feature manager. | ||
# | ||
def initialize | ||
@flag_lookup = DEFAULTS.each_with_object({}) do |feature, acc| | ||
key = feature[:name] | ||
acc[key] = feature.dup | ||
end | ||
end | ||
|
||
def all | ||
@flag_lookup.values.map do |feature| | ||
feature.slice(:name, :description).merge(enabled: enabled?(feature[:name])) | ||
end | ||
end | ||
|
||
def enabled?(name) | ||
return false unless @flag_lookup[name] | ||
|
||
feature = @flag_lookup[name] | ||
feature.key?(:user_preference) ? feature[:user_preference] : feature[:default_value] | ||
end | ||
|
||
def exists?(name) | ||
@flag_lookup.key?(name) | ||
end | ||
|
||
def names | ||
all.map { |feature| feature[:name] } | ||
end | ||
|
||
def set(name, value) | ||
return false unless @flag_lookup[name] | ||
|
||
@flag_lookup[name][:user_preference] = value | ||
|
||
if name == WRAPPED_TABLES | ||
if value | ||
Rex::Text::Table.wrap_tables! | ||
else | ||
Rex::Text::Table.unwrap_tables! | ||
end | ||
end | ||
end | ||
|
||
def load_config | ||
conf = Msf::Config.load | ||
conf.fetch(CONFIG_KEY, {}).each do |name, value| | ||
set(name, value == 'true') | ||
end | ||
end | ||
|
||
def save_config | ||
# Note, we intentionally omit features that have not explicitly been set by the user. | ||
config = Msf::Config.load | ||
old_config = config.fetch(CONFIG_KEY, {}) | ||
new_config = @flag_lookup.values.each_with_object(old_config) do |feature, config| | ||
next unless feature.key?(:user_preference) | ||
|
||
config.merge!(feature[:name] => feature[:user_preference].to_s) | ||
end | ||
|
||
Msf::Config.save(CONFIG_KEY => new_config) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.