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

RHOSTS: accept both "file://<path>" and "file:<path>" syntax #12314

Merged
merged 4 commits into from Sep 24, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/markdown_doc/auxiliary_scanner_template.erb
Expand Up @@ -25,5 +25,5 @@ msf <%= mod.type %>(<%= mod.shortname %>) > set RHOSTS 192.168.1.1/24
Example 3:

```
msf <%= mod.type %>(<%= mod.shortname %>) > set RHOSTS file:///tmp/ip_list.txt
msf <%= mod.type %>(<%= mod.shortname %>) > set RHOSTS file:/tmp/ip_list.txt
```
6 changes: 3 additions & 3 deletions documentation/modules/auxiliary/scanner/ssh/ssh_login.md
Expand Up @@ -32,7 +32,7 @@

**RHOSTS**

Either a comma space (`, `) separated list of hosts, or a file containing list of hosts, one per line. File Example: `file://root/ssh_hosts.lst`, list example: `192.168.0.1` or `192.168.0.1, 192.168.0.2`
Either a comma space (`, `) separated list of hosts, or a file containing list of hosts, one per line. File Example: `file:/root/ssh_hosts.lst`, list example: `192.168.0.1` or `192.168.0.1, 192.168.0.2`

**STOP_ON_SUCCESS**

Expand Down Expand Up @@ -104,8 +104,8 @@ msf auxiliary(ssh_login) > cat /root/ssh_hosts.lst
192.168.2.137
192.168.2.35
192.168.2.46
msf auxiliary(ssh_login) > set rhosts file://root/ssh_hosts.lst
rhosts => file://root/ssh_hosts.lst
msf auxiliary(ssh_login) > set rhosts file:/root/ssh_hosts.lst
rhosts => file:/root/ssh_hosts.lst
msf auxiliary(ssh_login) > set verbose false
verbose => false
msf auxiliary(ssh_login) > set threads 4
Expand Down
Expand Up @@ -34,7 +34,7 @@

**RHOSTS**

Either a comma space (`, `) separated list of hosts, or a file containing list of hosts, one per line. File Example: `file://root/ssh_hosts.lst`, list example: `192.168.0.1` or `192.168.0.1, 192.168.0.2`
Either a comma space (`, `) separated list of hosts, or a file containing list of hosts, one per line. File Example: `file:/root/ssh_hosts.lst`, list example: `192.168.0.1` or `192.168.0.1, 192.168.0.2`

**STOP_ON_SUCCESS**

Expand Down
4 changes: 2 additions & 2 deletions lib/msf/core/opt.rb
Expand Up @@ -41,11 +41,11 @@ def self.Proxies(default=nil, required=false, desc="A proxy chain of format type
end

# @return [OptAddressRange]
def self.RHOSTS(default=nil, required=true, desc="The target address range or CIDR identifier")
def self.RHOSTS(default=nil, required=true, desc="The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'")
Msf::OptAddressRange.new('RHOSTS', [ required, desc, default ])
end

def self.RHOST(default=nil, required=true, desc="The target address range or CIDR identifier")
def self.RHOST(default=nil, required=true, desc="The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'")
Msf::OptAddressRange.new('RHOSTS', [ required, desc, default ], aliases: [ 'RHOST' ])
end

Expand Down
3 changes: 2 additions & 1 deletion lib/msf/core/opt_address_range.rb
Expand Up @@ -18,7 +18,8 @@ def validate_on_assignment?

def normalize(value)
return nil unless value.kind_of?(String)
if (value =~ /^file:(.*)/)
# accept both "file://<path>" and "file:<path>" syntax
if (value =~ /^file:\/\/(.*)/) || (value =~ /^file:(.*)/)
path = $1
return false if not File.exist?(path) or File.directory?(path)
return File.readlines(path).map{ |s| s.strip}.join(" ")
Expand Down
3 changes: 2 additions & 1 deletion spec/lib/msf/core/opt_address_range_spec.rb
Expand Up @@ -11,7 +11,8 @@
{ :value => "192.0.2.0,1-255", :normalized => "192.0.2.0,1-255" },
{ :value => "192.0.2.*", :normalized => "192.0.2.*" },
{ :value => "192.0.2.0-192.0.2.255", :normalized => "192.0.2.0-192.0.2.255" },
{ :value => "file:#{File.expand_path('short_address_list.txt',FILE_FIXTURES_PATH)}", :normalized => '192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4 192.168.1.5'}
{ :value => "file:#{File.expand_path('short_address_list.txt',FILE_FIXTURES_PATH)}", :normalized => '192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4 192.168.1.5'},
{ :value => "file://#{File.expand_path('short_address_list.txt',FILE_FIXTURES_PATH)}", :normalized => '192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4 192.168.1.5'}
]
invalid_values = [
# Too many dots
Expand Down