Skip to content

Commit 63b6ab5

Browse files
committed
simplify valid credential storage
1 parent 97095ab commit 63b6ab5

18 files changed

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

modules/auxiliary/admin/http/wp_custom_contact_forms.rb

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,31 +62,19 @@ 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],
65+
def service_details
66+
{
67+
address: rhost,
68+
port: rport,
69+
service_name: (ssl ? "https": "http"), # changed from "WorkPress" here
7070
protocol: 'tcp',
71-
workspace_id: myworkspace_id
72-
}
73-
74-
credential_data = {
75-
origin_type: :service,
71+
workspace_id: myworkspace_id,
7672
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)
73+
origin_type: :service
74+
# moved to Msf::Module::Auth
75+
# last_attempted_at: DateTime.now,
76+
# status: Metasploit::Model::Login::Status::SUCCESSFUL
77+
}
9078
end
9179

9280
def run
@@ -122,17 +110,10 @@ def run
122110
# test login
123111
cookie = wordpress_login(username, password)
124112

125-
# login successfull
113+
# login successful
126114
if cookie
127115
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-
)
116+
store_valid_credential(username, password, :password, cookie)
136117
else
137118
print_error("User creation failed")
138119
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(username, password, :password, 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(username, password, :password, 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: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,43 +66,25 @@ 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
69+
def service_details
70+
{
71+
service_name: (ssl ? 'https' : 'http'),
72+
address: rhost,
73+
port: rport,
74+
protocol: 'tcp',
75+
origin_type: :service,
76+
module_fullname: fullname
77+
# moved to Msf::Module::Auth
78+
# last_attempted_at: DateTime.now,
79+
# status: Metasploit::Model::Login::Status::SUCCESSFUL
7680
}
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)
9281
end
9382

9483
def user_exists(user)
9584
exists = wordpress_user_exists?(user)
9685
if exists
9786
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-
87+
store_valid_credential(user, nil, :password, "WEBAPP=\"Wordpress\", VHOST=#{vhost}")
10688
return true
10789
else
10890
print_error("\"#{user}\" is not a valid username")

modules/auxiliary/scanner/http/cisco_ironport_enum.rb

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -115,31 +115,15 @@ 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],
118+
def service_details
119+
{
120+
address: rhost,
121+
port: rport,
122122
service_name: 'Cisco IronPort Appliance',
123123
protocol: 'tcp',
124-
workspace_id: myworkspace_id
125-
}
126-
127-
credential_data = {
128124
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)
125+
module_fullname: fullname
126+
}
143127
end
144128

145129
#
@@ -166,7 +150,7 @@ def do_login(user, pass)
166150
if res and res.get_cookies.include?('authenticated=')
167151
print_good("#{rhost}:#{rport} - SUCCESSFUL LOGIN - #{user.inspect}:#{pass.inspect}")
168152

169-
report_cred(ip: rhost, port: rport, user: user, password: pass, proof: res.get_cookies.inspect)
153+
store_valid_credential(user, pass, :password, res.get_cookies.inspect)
170154
return :next_user
171155

172156
else

modules/auxiliary/scanner/http/wordpress_login_enum.rb

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -100,42 +100,20 @@ 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
103+
def service_details
104+
{
105+
address: rhost,
106+
port: rport,
107+
service_name: ssl ? 'https' : 'http',
108+
protocol: 'tcp',
109+
workspace_id: myworkspace_id,
110+
module_fullname: fullname,
111+
origin_type: :service,
112+
last_attempted_at: DateTime.now,
113+
status: Metasploit::Model::Login::Status::SUCCESSFUL
111114
}
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)
136115
end
137116

138-
139117
def validate_user(user=nil)
140118
print_status("#{target_uri} - WordPress User-Validation - Checking Username:'#{user}'")
141119

@@ -167,14 +145,7 @@ def do_login(user=nil, pass=nil)
167145
if cookie
168146
print_good("#{target_uri} - WordPress Brute Force - SUCCESSFUL login for '#{user}' : '#{pass}'")
169147

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-
)
148+
store_valid_credential(user, pass, :password, cookie)
178149

179150
return :next_user
180151
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, password, :password, cookie)
101102

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

0 commit comments

Comments
 (0)