Skip to content

Commit 4def7ce

Browse files
committed
Land rapid7#8327, Simplify storing credentials
2 parents 126c078 + a1efa30 commit 4def7ce

18 files changed

+69
-146
lines changed

lib/msf/core/exploit/http/client.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,16 @@ def http_fingerprint(opts={})
772772
fprint[:signature]
773773
end
774774

775+
def service_details
776+
{
777+
origin_type: :service,
778+
protocol: 'tcp',
779+
service_name: (ssl ? 'https' : 'http'),
780+
address: rhost,
781+
port: rport
782+
}
783+
end
784+
775785
protected
776786

777787
attr_accessor :client

lib/msf/core/module.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Msf
1515
###
1616
class Module
1717
autoload :Arch, 'msf/core/module/arch'
18+
autoload :Auth, 'msf/core/module/auth'
1819
autoload :Author, 'msf/core/module/author'
1920
autoload :AuxiliaryAction, 'msf/core/module/auxiliary_action'
2021
autoload :Compatibility, 'msf/core/module/compatibility'
@@ -40,6 +41,7 @@ class Module
4041
autoload :UUID, 'msf/core/module/uuid'
4142

4243
include Msf::Module::Arch
44+
include Msf::Module::Auth
4345
include Msf::Module::Author
4446
include Msf::Module::Compatibility
4547
include Msf::Module::DataStore

lib/msf/core/module/auth.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module Msf::Module::Auth
2+
def store_valid_credential(user:, private:, private_type: :password, proof: nil)
3+
service_data = {}
4+
if self.respond_to? ("service_details")
5+
service_data = service_details
6+
end
7+
8+
creation_data = {
9+
module_fullname: self.fullname,
10+
username: user,
11+
private_data: private,
12+
private_type: private_type,
13+
workspace_id: myworkspace_id
14+
}.merge(service_data)
15+
16+
if service_data.empty?
17+
cred_data = {
18+
origin_type: :import,
19+
filename: 'msfconsole' # default as values provided on the console
20+
}.merge(creation_data)
21+
create_credential(cred_data)
22+
else
23+
login_data = {
24+
proof: proof,
25+
last_attempted_at: DateTime.now,
26+
status: Metasploit::Model::Login::Status::SUCCESSFUL
27+
}.merge(creation_data)
28+
create_credential_and_login(login_data)
29+
end
30+
31+
nil
32+
end
33+
end

modules/auxiliary/admin/http/wp_custom_contact_forms.rb

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,6 @@ def get_table_prefix
6262
table_prefix
6363
end
6464

65-
def report_cred(opts)
66-
service_data = {
67-
address: opts[:ip],
68-
port: opts[:port],
69-
service_name: opts[:service_name],
70-
protocol: 'tcp',
71-
workspace_id: myworkspace_id
72-
}
73-
74-
credential_data = {
75-
origin_type: :service,
76-
module_fullname: fullname,
77-
username: opts[:user],
78-
private_data: opts[:password],
79-
private_type: :password
80-
}.merge(service_data)
81-
82-
login_data = {
83-
last_attempted_at: DateTime.now,
84-
core: create_credential(credential_data),
85-
status: Metasploit::Model::Login::Status::SUCCESSFUL,
86-
proof: opts[:proof]
87-
}.merge(service_data)
88-
89-
create_credential_login(login_data)
90-
end
91-
9265
def run
9366
username = Rex::Text.rand_text_alpha(10)
9467
password = Rex::Text.rand_text_alpha(20)
@@ -122,17 +95,10 @@ def run
12295
# test login
12396
cookie = wordpress_login(username, password)
12497

125-
# login successfull
98+
# login successful
12699
if cookie
127100
print_status("User #{username} with password #{password} successfully created")
128-
report_cred(
129-
ip: rhost,
130-
port: rport,
131-
user: username,
132-
password: password,
133-
service_name: 'WordPress',
134-
proof: cookie
135-
)
101+
store_valid_credential(user: username, private: password, proof: cookie)
136102
else
137103
print_error("User creation failed")
138104
return

modules/auxiliary/admin/http/wp_easycart_privilege_escalation.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def run
7878
print_error("Failed to authenticate with WordPress")
7979
return
8080
end
81+
store_valid_credential(user: username, private: password, proof: cookie)
8182
print_good("Authenticated with WordPress")
8283

8384
new_email = "#{Rex::Text.rand_text_alpha(5)}@#{Rex::Text.rand_text_alpha(5)}.com"

modules/auxiliary/admin/http/wp_wplms_privilege_escalation.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def run
9898
print_status("Authenticating with WordPress using #{username}:#{password}...")
9999
cookie = wordpress_login(username, password)
100100
fail_with(Failure::NoAccess, 'Failed to authenticate with WordPress') if cookie.nil?
101+
store_valid_credential(user: username, private: password, proof: cookie)
101102
print_good("Authenticated with WordPress")
102103

103104
new_email = "#{Rex::Text.rand_text_alpha(5)}@#{Rex::Text.rand_text_alpha(5)}.com"

modules/auxiliary/dos/http/wordpress_long_password_dos.rb

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -66,43 +66,11 @@ def timeout
6666
datastore['TIMEOUT']
6767
end
6868

69-
def report_cred(opts)
70-
service_data = {
71-
address: opts[:ip],
72-
port: opts[:port],
73-
service_name: opts[:service_name],
74-
protocol: 'tcp',
75-
workspace_id: myworkspace_id
76-
}
77-
78-
credential_data = {
79-
origin_type: :service,
80-
module_fullname: fullname,
81-
username: opts[:user]
82-
}.merge(service_data)
83-
84-
login_data = {
85-
last_attempted_at: DateTime.now,
86-
core: create_credential(credential_data),
87-
status: Metasploit::Model::Login::Status::SUCCESSFUL,
88-
proof: opts[:proof]
89-
}.merge(service_data)
90-
91-
create_credential_login(login_data)
92-
end
93-
9469
def user_exists(user)
9570
exists = wordpress_user_exists?(user)
9671
if exists
9772
print_good("Username \"#{username}\" is valid")
98-
report_cred(
99-
ip: rhost,
100-
port: rport,
101-
user: user,
102-
service_name: (ssl ? 'https' : 'http'),
103-
proof: "WEBAPP=\"Wordpress\", VHOST=#{vhost}"
104-
)
105-
73+
store_valid_credential(user: user, private: nil, proof: "WEBAPP=\"Wordpress\", VHOST=#{vhost}")
10674
return true
10775
else
10876
print_error("\"#{user}\" is not a valid username")

modules/auxiliary/scanner/http/cisco_ironport_enum.rb

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -115,31 +115,8 @@ def is_app_ironport?
115115
end
116116
end
117117

118-
def report_cred(opts)
119-
service_data = {
120-
address: opts[:ip],
121-
port: opts[:port],
122-
service_name: 'Cisco IronPort Appliance',
123-
protocol: 'tcp',
124-
workspace_id: myworkspace_id
125-
}
126-
127-
credential_data = {
128-
origin_type: :service,
129-
module_fullname: fullname,
130-
username: opts[:user],
131-
private_data: opts[:password],
132-
private_type: :password
133-
}.merge(service_data)
134-
135-
login_data = {
136-
last_attempted_at: DateTime.now,
137-
core: create_credential(credential_data),
138-
status: Metasploit::Model::Login::Status::SUCCESSFUL,
139-
proof: opts[:proof]
140-
}.merge(service_data)
141-
142-
create_credential_login(login_data)
118+
def service_details
119+
super.merge({service_name: 'Cisco IronPort Appliance'})
143120
end
144121

145122
#
@@ -166,7 +143,7 @@ def do_login(user, pass)
166143
if res and res.get_cookies.include?('authenticated=')
167144
print_good("#{rhost}:#{rport} - SUCCESSFUL LOGIN - #{user.inspect}:#{pass.inspect}")
168145

169-
report_cred(ip: rhost, port: rport, user: user, password: pass, proof: res.get_cookies.inspect)
146+
store_valid_credential(user: user, private: pass, proof: res.get_cookies.inspect)
170147
return :next_user
171148

172149
else

modules/auxiliary/scanner/http/wordpress_login_enum.rb

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -100,56 +100,19 @@ def run_host(ip)
100100
end
101101
end
102102

103-
104-
def report_cred(opts)
105-
service_data = {
106-
address: opts[:ip],
107-
port: opts[:port],
108-
service_name: ssl ? 'https' : 'http',
109-
protocol: 'tcp',
110-
workspace_id: myworkspace_id
111-
}
112-
113-
credential_data = {
114-
origin_type: :service,
115-
module_fullname: fullname,
116-
username: opts[:user]
117-
}.merge(service_data)
118-
119-
if opts[:password]
120-
credential_data.merge!(
121-
private_data: opts[:password],
122-
private_type: :password
123-
)
124-
end
125-
126-
login_data = {
127-
core: create_credential(credential_data),
128-
status: opts[:status]
129-
}.merge(service_data)
130-
131-
if opts[:attempt_time]
132-
login_data.merge!(last_attempted_at: opts[:attempt_time])
133-
end
134-
135-
create_credential_login(login_data)
136-
end
137-
138-
139103
def validate_user(user=nil)
140104
print_status("#{target_uri} - WordPress User-Validation - Checking Username:'#{user}'")
141105

142106
exists = wordpress_user_exists?(user)
143107
if exists
144108
print_good("#{target_uri} - WordPress User-Validation - Username: '#{user}' - is VALID")
145-
146-
report_cred(
147-
ip: rhost,
148-
port: rport,
149-
user: user,
109+
connection_details = {
110+
module_fullname: self.fullname,
111+
username: user,
112+
workspace_id: myworkspace_id,
150113
status: Metasploit::Model::Login::Status::UNTRIED
151-
)
152-
114+
}.merge(service_details)
115+
create_credential_and_login(connection_details)
153116
@users_found[user] = :reported
154117
return :next_user
155118
else
@@ -167,14 +130,7 @@ def do_login(user=nil, pass=nil)
167130
if cookie
168131
print_good("#{target_uri} - WordPress Brute Force - SUCCESSFUL login for '#{user}' : '#{pass}'")
169132

170-
report_cred(
171-
ip: rhost,
172-
port: rport,
173-
user: user,
174-
password: pass,
175-
status: Metasploit::Model::Login::Status::SUCCESSFUL,
176-
attempt_time: DateTime.now
177-
)
133+
store_valid_credential(user: user, private: pass, proof: cookie)
178134

179135
return :next_user
180136
else

modules/auxiliary/scanner/http/wp_nextgen_galley_file_read.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def run_host(ip)
9898
print_error("Unable to login as: #{user}")
9999
return
100100
end
101+
store_valid_credential(user: user, private: password, proof: cookie)
101102

102103
vprint_status("Trying to get nonce...")
103104
nonce = get_nonce(cookie)

0 commit comments

Comments
 (0)