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

Add tcp uri scheme for setting rhosts #15965

Merged
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
22 changes: 22 additions & 0 deletions lib/msf/core/rhosts_walker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class RhostsWalker
postgres
smb
ssh
tcp
].freeze
private_constant :SUPPORTED_SCHEMAS

Expand Down Expand Up @@ -296,6 +297,27 @@ def parse_ssh_uri(value, datastore)
result
end

# Parses a uri string such as tcp://user:password@example.com into a hash
# which can safely be merged with a [Msf::DataStore] datastore for setting options.
#
# @param value [String] the uri string
# @return [Hash] A hash where keys match the required datastore options associated with
# the uri value
def parse_tcp_uri(value, datastore)
uri = ::Addressable::URI.parse(value)
gwillcox-r7 marked this conversation as resolved.
Show resolved Hide resolved
result = {}

result['RHOSTS'] = uri.hostname
if uri.port
result['RPORT'] = uri.port
end

set_username(datastore, result, uri.user) if uri.user
set_password(datastore, result, uri.password) if uri.password

result
end

protected

def set_username(datastore, result, username)
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/msf/core/rhosts_walker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,18 @@ def create_tempfile(content)
end
end

context 'when using the tcp scheme' do
it 'enumerates tcp schemes' do
ssh_mod.datastore['RHOSTS'] = '"tcp://user:a b c@example.com" "tcp://example.com:3000"'
expected = [
{ 'RHOSTS' => '192.0.2.2', 'RPORT' => 22, 'USERNAME' => 'user', 'PASSWORD' => 'a b c' },
{ 'RHOSTS' => '192.0.2.2', 'RPORT' => 3000, 'USERNAME' => nil, 'PASSWORD' => nil },
gwillcox-r7 marked this conversation as resolved.
Show resolved Hide resolved
]
expect(each_error_for(ssh_mod)).to be_empty
expect(each_host_for(ssh_mod)).to have_datastore_values(expected)
end
end

context 'when using the ssh scheme' do
it 'enumerates ssh schemes' do
ssh_mod.datastore['RHOSTS'] = '"ssh://user:a b c@example.com/"'
Expand Down