Skip to content

Commit 64e475a

Browse files
author
Brent Cook
committed
Land rapid7#7892, Enhance the creds command to allow creating logins
2 parents f101b79 + 1fcd20b commit 64e475a

File tree

2 files changed

+409
-367
lines changed

2 files changed

+409
-367
lines changed

lib/msf/ui/console/command_dispatcher/creds.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def creds_add(*args)
202202
end
203203

204204
begin
205-
params.assert_valid_keys('user','password','realm','realm-type','ntlm','ssh-key','hash','host','port')
205+
params.assert_valid_keys('user','password','realm','realm-type','ntlm','ssh-key','hash','address','port','protocol', 'service-name')
206206
rescue ArgumentError => e
207207
print_error(e.message)
208208
end
@@ -213,6 +213,13 @@ def creds_add(*args)
213213
print_error("You can only specify a single Private type. Private types given: #{private_keys.join(', ')}")
214214
return
215215
end
216+
217+
login_keys = params.slice('address','port','protocol','service-name')
218+
if login_keys.any? and login_keys.length < 3
219+
missing_login_keys = ['host','port','proto','service-name'] - login_keys.keys
220+
print_error("Creating a login requires a address, a port, and a protocol. Missing params: #{missing_login_keys}")
221+
return
222+
end
216223

217224
data = {
218225
workspace_id: framework.db.workspace,
@@ -260,9 +267,17 @@ def creds_add(*args)
260267
data[:private_type] = :nonreplayable_hash
261268
data[:private_data] = params['hash']
262269
end
263-
270+
264271
begin
265-
create_credential(data)
272+
if login_keys.any?
273+
data[:address] = params['address']
274+
data[:port] = params['port']
275+
data[:protocol] = params['protocol']
276+
data[:service_name] = params['service-name']
277+
create_credential_and_login(data)
278+
else
279+
create_credential(data)
280+
end
266281
rescue ActiveRecord::RecordInvalid => e
267282
print_error("Failed to add #{data['private_type']}: #{e}")
268283
end

0 commit comments

Comments
 (0)