Skip to content

Commit cbfe18e

Browse files
committed
use certificates in nexpose
1 parent 4af1b59 commit cbfe18e

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ GEM
195195
nessus_rest (0.1.6)
196196
net-ssh (4.0.1)
197197
network_interface (0.0.1)
198-
nexpose (5.1.0)
198+
nexpose (5.3.0)
199199
nokogiri (1.7.0.1)
200200
mini_portile2 (~> 2.1.0)
201201
octokit (4.6.2)
@@ -350,4 +350,4 @@ DEPENDENCIES
350350
yard
351351

352352
BUNDLED WITH
353-
1.13.7
353+
1.14.3

modules/auxiliary/admin/http/nexpose_xxe_file_read.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ def report_cred(opts)
7474
def run
7575
user = datastore['USERNAME']
7676
pass = datastore['PASSWORD']
77+
trust_store = datastore['TRUST_STORE']
7778
prot = ssl ? 'https' : 'http'
7879

79-
nsc = Nexpose::Connection.new(rhost, user, pass, rport)
80+
nsc = Nexpose::Connection.new(rhost, user, pass, rport, nil, nil, trust_store)
8081

8182
print_status("Authenticating as: " << user)
8283
begin

plugins/nexpose.rb

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def cmd_nexpose_save(*args)
8181
group = "default"
8282

8383
if ((@user and @user.length > 0) and (@host and @host.length > 0) and (@port and @port.length > 0 and @port.to_i > 0) and (@pass and @pass.length > 0))
84-
config = {"#{group}" => {'username' => @user, 'password' => @pass, 'server' => @host, 'port' => @port}}
84+
config = {"#{group}" => {'username' => @user, 'password' => @pass, 'server' => @host, 'port' => @port, 'trust_cert' => @trust_cert}}
8585
::File.open("#{Nexpose_yaml}", "wb") { |f| f.puts YAML.dump(config) }
8686
print_good("#{Nexpose_yaml} created.")
8787
else
@@ -100,61 +100,74 @@ def cmd_nexpose_connect(*args)
100100
@pass = lconfig['default']['password']
101101
@host = lconfig['default']['server']
102102
@port = lconfig['default']['port']
103-
@sslv = "ok" # TODO: Not super-thrilled about bypassing the SSL warning...
103+
@trust_cert = lconfig['default']['trust_cert']
104+
unless @trust_cert
105+
@sslv = "ok" # TODO: Not super-thrilled about bypassing the SSL warning...
106+
end
104107
nexpose_login
105108
return
106109
end
107110
end
108111

109112
if(args.length == 0 or args[0].empty? or args[0] == "-h")
110-
print_status("Usage: ")
111-
print_status(" nexpose_connect username:password@host[:port] <ssl-confirm>")
112-
print_status(" -OR- ")
113-
print_status(" nexpose_connect username password host port <ssl-confirm>")
113+
nexpose_usage
114114
return
115115
end
116116

117-
@user = @pass = @host = @port = @sslv = nil
117+
@user = @pass = @host = @port = @sslv = @trust_cert = @trust_cert_file = nil
118118

119119
case args.length
120120
when 1,2
121121
cred,targ = args[0].split('@', 2)
122122
@user,@pass = cred.split(':', 2)
123123
targ ||= '127.0.0.1:3780'
124124
@host,@port = targ.split(':', 2)
125-
port ||= '3780'
126-
@sslv = args[1]
125+
@port ||= '3780'
126+
unless args.length == 1
127+
@trust_cert_file = args[1]
128+
if File.exists? @trust_cert_file
129+
@trust_cert = File.read(@trust_cert_file)
130+
end
131+
end
127132
when 4,5
128-
@user,@pass,@host,@port,@sslv = args
133+
@user,@pass,@host,@port,@trust_cert = args
134+
unless args.length == 4
135+
@trust_cert_file = @trust_cert
136+
if File.exists? @trust_cert_file
137+
@trust_cert = File.read(@trust_cert_file)
138+
end
139+
end
129140
else
130-
print_status("Usage: ")
131-
print_status(" nexpose_connect username:password@host[:port] <ssl-confirm>")
132-
print_status(" -OR- ")
133-
print_status(" nexpose_connect username password host port <ssl-confirm>")
141+
nexpose_usage
134142
return
135143
end
136144
nexpose_login
137145
end
138146

147+
def nexpose_usage
148+
print_status("Usage: ")
149+
print_status(" nexpose_connect username:password@host[:port] <ssl-confirm>")
150+
print_status(" -OR- ")
151+
print_status(" nexpose_connect username password host port <ssl-confirm>")
152+
end
153+
139154
def nexpose_login
140155

141156
if ! ((@user and @user.length > 0) and (@host and @host.length > 0) and (@port and @port.length > 0 and @port.to_i > 0) and (@pass and @pass.length > 0))
142-
print_status("Usage: ")
143-
print_status(" nexpose_connect username:password@host[:port] <ssl-confirm>")
144-
print_status(" -OR- ")
145-
print_status(" nexpose_connect username password host port <ssl-confirm>")
157+
nexpose_usage
146158
return
147159
end
148160

149-
if(@host != "localhost" and @host != "127.0.0.1" and @sslv != "ok")
161+
if(@host != "localhost" and @host != "127.0.0.1" and (@trust_cert.nil? && @sslv != "ok"))
162+
# consider removing this message and replacing with check on trust_store, and if trust_store is not found validate @host already has a truly trusted cert?
150163
print_error("Warning: SSL connections are not verified in this release, it is possible for an attacker")
151164
print_error(" with the ability to man-in-the-middle the Nexpose traffic to capture the Nexpose")
152165
print_error(" credentials. If you are running this on a trusted network, please pass in 'ok'")
153166
print_error(" as an additional parameter to this command.")
154167
return
155168
end
156169

157-
# Wrap this so a duplicate session doesnt prevent a new login
170+
# Wrap this so a duplicate session does not prevent a new login
158171
begin
159172
cmd_nexpose_disconnect
160173
rescue ::Interrupt
@@ -164,7 +177,7 @@ def nexpose_login
164177

165178
begin
166179
print_status("Connecting to Nexpose instance at #{@host}:#{@port} with username #{@user}...")
167-
nsc = Nexpose::Connection.new(@host, @user, @pass, @port)
180+
nsc = Nexpose::Connection.new(@host, @user, @pass, @port, nil, nil, @trust_cert)
168181
nsc.login
169182
rescue ::Nexpose::APIError => e
170183
print_error("Connection failed: #{e.reason}")

0 commit comments

Comments
 (0)