Skip to content

Commit 2815462

Browse files
committed
Update Mdm to staging hash
2 parents 1226b36 + 27e05d7 commit 2815462

File tree

9 files changed

+504
-311
lines changed

9 files changed

+504
-311
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ source 'https://rubygems.org'
33
# spec.add_runtime_dependency '<name>', [<version requirements>]
44
gemspec name: 'metasploit-framework'
55

6+
gem 'metasploit_data_models', git: 'https://github.com/rapid7/metasploit_data_models.git', branch: 'staging/single-vuln-push'
7+
68
# separate from test as simplecov is not run on travis-ci
79
group :coverage do
810
# code coverage for tests

Gemfile.lock

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
GIT
2+
remote: https://github.com/rapid7/metasploit_data_models.git
3+
revision: 532eedb5f5f68396380dc16355537ebee25ffa0d
4+
branch: staging/single-vuln-push
5+
specs:
6+
17
PATH
28
remote: .
39
specs:
@@ -101,11 +107,11 @@ GEM
101107
gherkin (2.11.6)
102108
json (>= 1.7.6)
103109
hike (1.2.3)
104-
i18n (0.6.11)
110+
i18n (0.7.0)
105111
journey (1.0.4)
106112
jsobfu (0.2.1)
107113
rkelly-remix (= 0.0.6)
108-
json (1.8.1)
114+
json (1.8.2)
109115
mail (2.5.4)
110116
mime-types (~> 1.16)
111117
treetop (~> 1.4.8)
@@ -135,11 +141,11 @@ GEM
135141
meterpreter_bins (0.0.16)
136142
method_source (0.8.2)
137143
mime-types (1.25.1)
138-
mini_portile (0.6.1)
144+
mini_portile (0.6.2)
139145
msgpack (0.5.11)
140146
multi_json (1.0.4)
141147
network_interface (0.0.1)
142-
nokogiri (1.6.5)
148+
nokogiri (1.6.6.2)
143149
mini_portile (~> 0.6.0)
144150
packetfu (1.1.9)
145151
pcaprub (0.11.3)
@@ -154,7 +160,7 @@ GEM
154160
rack (>= 0.4)
155161
rack-ssl (1.3.4)
156162
rack
157-
rack-test (0.6.2)
163+
rack-test (0.6.3)
158164
rack (>= 1.0)
159165
rails (3.2.21)
160166
actionmailer (= 3.2.21)
@@ -175,7 +181,7 @@ GEM
175181
rb-readline-r7 (0.5.2.0)
176182
rdoc (3.12.2)
177183
json (~> 1.4)
178-
recog (1.0.16)
184+
recog (1.0.24)
179185
nokogiri
180186
redcarpet (3.1.2)
181187
rkelly-remix (0.0.6)
@@ -219,7 +225,7 @@ GEM
219225
treetop (1.4.15)
220226
polyglot
221227
polyglot (>= 0.3.1)
222-
tzinfo (0.3.42)
228+
tzinfo (0.3.43)
223229
xpath (2.0.0)
224230
nokogiri (~> 1.3)
225231
yard (0.8.7.4)
@@ -236,6 +242,7 @@ DEPENDENCIES
236242
metasploit-framework!
237243
metasploit-framework-db!
238244
metasploit-framework-pcap!
245+
metasploit_data_models!
239246
pry
240247
rake (>= 10.0.0)
241248
redcarpet

db/schema.rb

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,55 @@
1111
#
1212
# It's strongly recommended to check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(:version => 20150212214222) do
14+
ActiveRecord::Schema.define(:version => 20150312155312) do
1515

1616
create_table "api_keys", :force => true do |t|
1717
t.text "token"
1818
t.datetime "created_at", :null => false
1919
t.datetime "updated_at", :null => false
2020
end
2121

22+
create_table "automatic_exploitation_match_results", :force => true do |t|
23+
t.integer "match_id"
24+
t.integer "run_id"
25+
t.string "state", :null => false
26+
t.datetime "created_at", :null => false
27+
t.datetime "updated_at", :null => false
28+
end
29+
30+
create_table "automatic_exploitation_match_sets", :force => true do |t|
31+
t.integer "workspace_id"
32+
t.integer "user_id"
33+
t.datetime "created_at", :null => false
34+
t.datetime "updated_at", :null => false
35+
end
36+
37+
add_index "automatic_exploitation_match_sets", ["user_id"], :name => "index_automatic_exploitation_match_sets_on_user_id"
38+
add_index "automatic_exploitation_match_sets", ["workspace_id"], :name => "index_automatic_exploitation_match_sets_on_workspace_id"
39+
40+
create_table "automatic_exploitation_matches", :force => true do |t|
41+
t.integer "module_detail_id"
42+
t.string "state"
43+
t.integer "nexpose_data_vulnerability_definition_id"
44+
t.datetime "created_at", :null => false
45+
t.datetime "updated_at", :null => false
46+
t.integer "match_set_id"
47+
t.string "matchable_type"
48+
t.integer "matchable_id"
49+
t.text "module_fullname"
50+
end
51+
52+
add_index "automatic_exploitation_matches", ["module_detail_id"], :name => "index_automatic_exploitation_matches_on_ref_id"
53+
add_index "automatic_exploitation_matches", ["module_fullname"], :name => "index_automatic_exploitation_matches_on_module_fullname"
54+
55+
create_table "automatic_exploitation_runs", :force => true do |t|
56+
t.integer "workspace_id"
57+
t.integer "user_id"
58+
t.integer "match_set_id"
59+
t.datetime "created_at", :null => false
60+
t.datetime "updated_at", :null => false
61+
end
62+
2263
create_table "clients", :force => true do |t|
2364
t.integer "host_id"
2465
t.datetime "created_at"
@@ -102,7 +143,7 @@
102143

103144
create_table "hosts", :force => true do |t|
104145
t.datetime "created_at"
105-
t.string "address", :limit => nil, :null => false
146+
t.string "address", :null => false
106147
t.string "mac"
107148
t.string "comm"
108149
t.string "name"
@@ -155,19 +196,22 @@
155196
end
156197

157198
create_table "loots", :force => true do |t|
158-
t.integer "workspace_id", :default => 1, :null => false
199+
t.integer "workspace_id", :default => 1, :null => false
159200
t.integer "host_id"
160201
t.integer "service_id"
161-
t.string "ltype", :limit => 512
162-
t.string "path", :limit => 1024
202+
t.string "ltype", :limit => 512
203+
t.string "path", :limit => 1024
163204
t.text "data"
164-
t.datetime "created_at", :null => false
165-
t.datetime "updated_at", :null => false
205+
t.datetime "created_at", :null => false
206+
t.datetime "updated_at", :null => false
166207
t.string "content_type"
167208
t.text "name"
168209
t.text "info"
210+
t.integer "module_run_id"
169211
end
170212

213+
add_index "loots", ["module_run_id"], :name => "index_loots_on_module_run_id"
214+
171215
create_table "macros", :force => true do |t|
172216
t.datetime "created_at", :null => false
173217
t.datetime "updated_at", :null => false
@@ -359,6 +403,24 @@
359403
add_index "module_refs", ["detail_id"], :name => "index_module_refs_on_module_detail_id"
360404
add_index "module_refs", ["name"], :name => "index_module_refs_on_name"
361405

406+
create_table "module_runs", :force => true do |t|
407+
t.datetime "attempted_at"
408+
t.text "fail_detail"
409+
t.string "fail_reason"
410+
t.integer "module_detail_id"
411+
t.text "module_full_name"
412+
t.integer "port"
413+
t.string "proto"
414+
t.integer "session_id"
415+
t.string "status"
416+
t.integer "trackable_id"
417+
t.string "trackable_type"
418+
t.integer "user_id"
419+
t.string "username"
420+
t.datetime "created_at", :null => false
421+
t.datetime "updated_at", :null => false
422+
end
423+
362424
create_table "module_targets", :force => true do |t|
363425
t.integer "detail_id"
364426
t.integer "index"
@@ -481,13 +543,16 @@
481543
t.integer "port"
482544
t.string "platform"
483545
t.text "datastore"
484-
t.datetime "opened_at", :null => false
546+
t.datetime "opened_at", :null => false
485547
t.datetime "closed_at"
486548
t.string "close_reason"
487549
t.integer "local_id"
488550
t.datetime "last_seen"
551+
t.integer "module_run_id"
489552
end
490553

554+
add_index "sessions", ["module_run_id"], :name => "index_sessions_on_module_run_id"
555+
491556
create_table "tags", :force => true do |t|
492557
t.integer "user_id"
493558
t.string "name", :limit => 1024
@@ -688,7 +753,7 @@
688753

689754
create_table "wmap_requests", :force => true do |t|
690755
t.string "host"
691-
t.string "address", :limit => nil
756+
t.string "address"
692757
t.integer "port"
693758
t.integer "ssl"
694759
t.string "meth", :limit => 32
@@ -705,7 +770,7 @@
705770

706771
create_table "wmap_targets", :force => true do |t|
707772
t.string "host"
708-
t.string "address", :limit => nil
773+
t.string "address"
709774
t.integer "port"
710775
t.integer "ssl"
711776
t.integer "selected"

lib/msf/core/db_manager/exploit_attempt.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,4 @@ def report_exploit_success(opts)
209209
host.exploit_attempts.create(attempt_info)
210210
}
211211
end
212-
end
212+
end

lib/msf/core/db_manager/session.rb

Lines changed: 62 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def report_session(opts)
121121
else
122122
raise ArgumentError.new("Missing option :session or :host")
123123
end
124-
ret = {}
125124

126125
# Truncate the session data if necessary
127126
if sess_data[:desc]
@@ -145,61 +144,80 @@ def report_session(opts)
145144
end
146145
end
147146

148-
149147
if opts[:session]
150148
session.db_record = s
149+
if session.assoc_exploit.user_data_is_match?
150+
# do some shit with the match
151+
MetasploitDataModels::AutomaticExploitation::MatchResult.create!(
152+
match: session.assoc_exploit.user_data[:match],
153+
match_set: session.assoc_exploit.user_data[:match_set],
154+
run: session.assoc_exploit.user_data[:run],
155+
state: 'succeeded',
156+
)
157+
elsif session.via_exploit
158+
# This is a live session, we know the host is vulnerable to something.
159+
infer_vuln_from_session(session, wspace)
160+
end
151161
end
152162

153-
# If this is a live session, we know the host is vulnerable to something.
154-
if opts[:session] and session.via_exploit
155-
mod = framework.modules.create(session.via_exploit)
163+
s
164+
}
165+
end
166+
167+
protected
156168

157-
if session.via_exploit == "exploit/multi/handler" and sess_data[:datastore]['ParentModule']
158-
mod_fullname = sess_data[:datastore]['ParentModule']
159-
mod_name = ::Mdm::Module::Detail.find_by_fullname(mod_fullname).name
160-
else
161-
mod_name = mod.name
162-
mod_fullname = mod.fullname
163-
end
169+
# @param session [Msf::Session] A session with a {db_record Msf::Session#db_record}
170+
# @param wspace [Mdm::Workspace]
171+
# @return [void]
172+
def infer_vuln_from_session(session, wspace)
173+
s = session.db_record
174+
host = session.db_record.host
164175

165-
vuln_info = {
166-
:host => host.address,
167-
:name => mod_name,
168-
:refs => mod.references,
169-
:workspace => wspace,
170-
:exploited_at => Time.now.utc,
171-
:info => "Exploited by #{mod_fullname} to create Session #{s.id}"
172-
}
176+
mod = framework.modules.create(session.via_exploit)
173177

174-
port = session.exploit_datastore["RPORT"]
175-
service = (port ? host.services.find_by_port(port.to_i) : nil)
178+
if session.via_exploit == "exploit/multi/handler" and session.exploit_datastore['ParentModule']
179+
mod_fullname = session.exploit_datastore['ParentModule']
180+
mod_name = ::Mdm::Module::Detail.find_by_fullname(mod_fullname).name
181+
else
182+
mod_name = mod.name
183+
mod_fullname = mod.fullname
184+
end
176185

177-
vuln_info[:service] = service if service
186+
vuln_info = {
187+
:host => host.address,
188+
:name => mod_name,
189+
:refs => mod.references,
190+
:workspace => wspace,
191+
:exploited_at => Time.now.utc,
192+
:info => "Exploited by #{mod_fullname} to create Session #{s.id}"
193+
}
178194

179-
vuln = framework.db.report_vuln(vuln_info)
195+
port = session.exploit_datastore["RPORT"]
196+
service = (port ? host.services.find_by_port(port.to_i) : nil)
180197

181-
if session.via_exploit == "exploit/multi/handler" and sess_data[:datastore]['ParentModule']
182-
via_exploit = sess_data[:datastore]['ParentModule']
183-
else
184-
via_exploit = session.via_exploit
185-
end
186-
attempt_info = {
187-
:timestamp => Time.now.utc,
188-
:workspace => wspace,
189-
:module => via_exploit,
190-
:username => session.username,
191-
:refs => mod.references,
192-
:session_id => s.id,
193-
:host => host,
194-
:service => service,
195-
:vuln => vuln
196-
}
198+
vuln_info[:service] = service if service
197199

198-
framework.db.report_exploit_success(attempt_info)
200+
vuln = framework.db.report_vuln(vuln_info)
199201

202+
if session.via_exploit == "exploit/multi/handler" and session.exploit_datastore['ParentModule']
203+
via_exploit = session.exploit_datastore['ParentModule']
204+
else
205+
via_exploit = session.via_exploit
200206
end
207+
attempt_info = {
208+
:timestamp => Time.now.utc,
209+
:workspace => wspace,
210+
:module => via_exploit,
211+
:username => session.username,
212+
:refs => mod.references,
213+
:session_id => s.id,
214+
:host => host,
215+
:service => service,
216+
:vuln => vuln
217+
}
218+
219+
framework.db.report_exploit_success(attempt_info)
201220

202-
s
203-
}
204221
end
205-
end
222+
223+
end

0 commit comments

Comments
 (0)