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

Adds rhost url support behind a feature flag #13961

Merged
merged 1 commit into from
Aug 19, 2020

Conversation

dwelch-r7
Copy link
Contributor

@dwelch-r7 dwelch-r7 commented Aug 7, 2020

This PR is for an additional option that allows users to specify a URL (i.e. set RHOST_URL https://example.com/path) rather than setting each individual option that is the current workflow (i.e. set RHOSTS example.com, set RPORT 443, set SSL true ... etc)

For full details on the various approaches to adding URL Support to Metasploit:
https://github.com/rapid7/metasploit-framework/wiki/RFC---Metasploit-URL-support

I currently only have the new option added to Exploit::Remote::HttpClient but I'm sure there are a few other places it also belongs, more than happy to add it in anywhere that makes sense

Here is an example of the setting in action:
image

The reverse is also true, i.e. you can set multiple individual values and the RHOST_URL will be displayed for you:
image

Http username and password is also supported:
image

Some things to note with the current implementation:

  • Only single URLs may be specified (In other words you are not able specify an address range in the new option), attempting this will blank out the RHOST_URL option, but any previous options that were set will remain.
    image

  • URLs of the format example.com notably missing the scheme are not supported, you must do //example.com:<port> or even better https://example.com
    image

To sum up, if this feature is to be added users would be able to simply input set RHOST_URL and paste in their target rather than having to set anywhere up to 6 different options depending on what that particular module cared about.

Continued from #13766.

@adfoster-r7 adfoster-r7 added the blocked Blocked by one or more additional tasks label Aug 7, 2020
Copy link
Contributor

@adfoster-r7 adfoster-r7 left a comment

Choose a reason for hiding this comment

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

This currently crashes for me when I try to use it, full details here #13961 (comment)

spec/lib/msf/core/opt_http_rhost_url_spec.rb Show resolved Hide resolved
lib/msf/core/option_container.rb Show resolved Hide resolved

def get_uri(value)
return unless value
return if check_for_range(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return if check_for_range(value)
return unless single_rhost?(value)

def check_for_range(value)
return false if value =~ /[^-0-9,.*\/]/
walker = Rex::Socket::RangeWalker.new(value)
if walker&.valid?
Copy link
Contributor

Choose a reason for hiding this comment

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

For context, when can walker be nil?

Suggested change
if walker&.valid?
return false unless walker.valid?
walker.length == 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if it can be, but I figured better to be safe? I don't remember if passing it something invalid causes it to be nil or if I was just being cautious at the time

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like it's just a normal constructor method to me, I don't think there's any need for the nil check here in that case 👀

lib/msf/core/opt_http_rhost_url.rb Show resolved Hide resolved
lib/msf/core/opt_http_rhost_url.rb Show resolved Hide resolved
Comment on lines 29 to 30
option_hash['TARGETURI'] = uri.path || '/'
option_hash['URI'] = uri.path || '/'
Copy link
Contributor

Choose a reason for hiding this comment

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

uri.path seems to return an empty string, which is truthy in ruby - so I think this defaulting logic will never occur 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, will change

return false unless walker.valid?
# if there is only a single ip then it's not a range
walker.length == 1
rescue ::Exception
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we don't want to capture Exception here? 👀

https://thoughtbot.com/blog/rescue-standarderror-not-exception

Tidy up test

Return a string instead of a URI object

Code review comments

Rubcocop
@adfoster-r7 adfoster-r7 merged commit 7fd489c into rapid7:master Aug 19, 2020
@adfoster-r7 adfoster-r7 added rn-enhancement release notes enhancement and removed blocked Blocked by one or more additional tasks labels Aug 19, 2020
@adfoster-r7
Copy link
Contributor

## Release notes

Updates http modules to support the setting of multiple http options a single option value RHOST_HTTP_URL. For example: set RHOST_HTTP_URL http://example.com/. This functionality is currently opt-in. The steps for enabling this feature can be seen within the help features command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants