-
Notifications
You must be signed in to change notification settings - Fork 14k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds rhost url support behind a feature flag
- Loading branch information
Showing
21 changed files
with
281 additions
and
80 deletions.
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
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 -*- | ||
|
||
module Msf | ||
### | ||
# | ||
# RHOST URL option. | ||
# | ||
### | ||
class OptHTTPRhostURL < OptBase | ||
def type | ||
'rhost http url' | ||
end | ||
|
||
def normalize(value) | ||
return unless value | ||
|
||
uri = get_uri(value) | ||
return unless uri | ||
|
||
option_hash = {} | ||
# Blank this out since we don't know if this new value will have a `VHOST` to ensure we remove the old value | ||
option_hash['VHOST'] = nil | ||
|
||
option_hash['RHOSTS'] = uri.hostname | ||
option_hash['RPORT'] = uri.port | ||
option_hash['SSL'] = %w[ssl https].include?(uri.scheme) | ||
|
||
# Both `TARGETURI` and `URI` are used as datastore options to denote the path on a uri | ||
option_hash['TARGETURI'] = uri.path || '/' | ||
option_hash['URI'] = uri.path || '/' | ||
|
||
if uri.scheme && %(http https).include?(uri.scheme) | ||
option_hash['VHOST'] = uri.hostname unless Rex::Socket.is_ip_addr?(uri.hostname) | ||
option_hash['HttpUsername'] = uri.user.to_s | ||
option_hash['HttpPassword'] = uri.password.to_s | ||
end | ||
|
||
option_hash | ||
end | ||
|
||
def valid?(value, check_empty: false) | ||
return true unless value || required | ||
|
||
uri = get_uri(value) | ||
return false unless uri && !uri.host.nil? && !uri.port.nil? | ||
|
||
super | ||
end | ||
|
||
def calculate_value(datastore) | ||
return unless datastore['RHOSTS'] | ||
begin | ||
uri_type = datastore['SSL'] ? URI::HTTPS : URI::HTTP | ||
uri = uri_type.build(host: datastore['RHOSTS']) | ||
uri.port = datastore['RPORT'] | ||
# The datastore uses both `TARGETURI` and `URI` to denote the path of a URL, we try both here and fall back to `/` | ||
uri.path = (datastore['TARGETURI'] || datastore['URI'] || '/') | ||
uri.user = datastore['HttpUsername'] | ||
uri.password = datastore['HttpPassword'] if uri.user | ||
uri | ||
rescue URI::InvalidComponentError | ||
nil | ||
end | ||
end | ||
|
||
protected | ||
|
||
def get_uri(value) | ||
return unless value | ||
return if check_for_range(value) | ||
|
||
value = 'http://' + value unless value.start_with?(%r{https?://}) | ||
URI(value) | ||
rescue URI::InvalidURIError | ||
nil | ||
end | ||
|
||
def check_for_range(value) | ||
return false if value =~ /[^-0-9,.*\/]/ | ||
walker = Rex::Socket::RangeWalker.new(value) | ||
if walker&.valid? | ||
# if there is only a single ip then it's not a range | ||
return walker.length != 1 | ||
end | ||
rescue ::Exception | ||
# couldn't create a range therefore it isn't one | ||
return false | ||
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
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
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
Oops, something went wrong.