Browse Source

Rework how match results get created

MSP-13119

* Create match result when we create vuln attempt
Fernando Arias 4 years ago
parent
commit
c7f15ca940
No account linked to committer's email address

+ 20
- 0
lib/msf/core/db_manager/exploit_attempt.rb View File

@@ -153,6 +153,8 @@ module Msf::DBManager::ExploitAttempt
153 153
         attempt_info[:vuln_id] = vuln.id
154 154
         vuln.vuln_attempts.create(attempt_info)
155 155
 
156
+        create_match_result(vuln,opts)
157
+
156 158
         # Correct the vuln's associated service if necessary
157 159
         if svc and vuln.service_id.nil?
158 160
           vuln.service = svc
@@ -176,4 +178,22 @@ module Msf::DBManager::ExploitAttempt
176 178
     }
177 179
 
178 180
   end
181
+
182
+  def create_match_result(vuln, opts)
183
+    match = vuln.matches.last
184
+    if match
185
+      run = MetasploitDataModels::AutomaticExploitation::Run.where(match_set_id: match.match_set_id).first
186
+      if opts[:session_id]
187
+        state =  MetasploitDataModels::AutomaticExploitation::MatchResult::SUCCEEDED
188
+      else
189
+        state =  MetasploitDataModels::AutomaticExploitation::MatchResult::FAILED
190
+      end
191
+      MetasploitDataModels::AutomaticExploitation::MatchResult.create!(
192
+        match: match,
193
+        run: run,
194
+        state: state
195
+      )
196
+    end
197
+  end
198
+
179 199
 end

+ 1
- 8
lib/msf/core/db_manager/session.rb View File

@@ -92,14 +92,7 @@ module Msf::DBManager::Session
92 92
     wspace = s.workspace
93 93
 
94 94
     if session
95
-      if session.exploit.user_data_is_match?
96
-        MetasploitDataModels::AutomaticExploitation::MatchResult.create!(
97
-          match: session.exploit.user_data[:match],
98
-          run: session.exploit.user_data[:run],
99
-          state: MetasploitDataModels::AutomaticExploitation::MatchResult::SUCCEEDED,
100
-        )
101
-        infer_vuln_from_session(session, wspace)
102
-      elsif session.via_exploit
95
+      if session.via_exploit
103 96
         # This is a live session, we know the host is vulnerable to something.
104 97
         infer_vuln_from_session(session, wspace)
105 98
       end

+ 0
- 9
lib/msf/core/exploit.rb View File

@@ -1284,15 +1284,6 @@ class Exploit < Msf::Module
1284 1284
       end
1285 1285
     end
1286 1286
 
1287
-    if user_data_is_match?
1288
-      MetasploitDataModels::AutomaticExploitation::MatchResult.create!(
1289
-        match: user_data[:match],
1290
-        run: user_data[:run],
1291
-        state: MetasploitDataModels::AutomaticExploitation::MatchResult::FAILED,
1292
-      )
1293
-    end
1294
-
1295
-
1296 1287
     framework.db.report_exploit_failure(info)
1297 1288
   end
1298 1289
 

+ 1
- 0
lib/msf/core/exploit_driver.rb View File

@@ -210,6 +210,7 @@ protected
210 210
         # Wait for session, but don't wait long.
211 211
         delay = 0.01
212 212
       end
213
+
213 214
       exploit.handle_exception e
214 215
     end
215 216
 

+ 0
- 12
lib/msf/core/module.rb View File

@@ -59,10 +59,6 @@ class Module
59 59
   # datastore, consumed by #replicant to allow clean override of MSF module methods.
60 60
   REPLICANT_EXTENSION_DS_KEY = 'ReplicantExtensions'
61 61
 
62
-  # The set of keys in {#user_data} that make {#user_data_is_match?} return
63
-  # true
64
-  MATCH_KEYS = Set.new([ :match, :match_set, :run ])
65
-
66 62
   # Make include public so we can runtime extend
67 63
   public_class_method :include
68 64
 
@@ -295,13 +291,6 @@ class Module
295 291
     raise RuntimeError, "#{reason.to_s}: #{msg}"
296 292
   end
297 293
 
298
-  # Whether {#user_data} contains everything necessary to make a
299
-  # `MetasploitDataModels::AutomaticExploitation::MatchResult`
300
-  #
301
-  # @return [bool]
302
-  def user_data_is_match?
303
-    user_data.kind_of?(Hash) && Set.new(user_data.keys).superset?(MATCH_KEYS)
304
-  end
305 294
 
306 295
   ##
307 296
   #
@@ -347,7 +336,6 @@ class Module
347 336
   # {Msf::Simple::Auxiliary#run_simple} for correlating where modules came
348 337
   # from.
349 338
   #
350
-  # @see #user_data_is_match?
351 339
   attr_accessor :user_data
352 340
 
353 341
   protected

+ 0
- 11
spec/lib/msf/core/module_spec.rb View File

@@ -46,17 +46,6 @@ describe Msf::Module do
46 46
     it { is_expected.to respond_to :is_usable }
47 47
   end
48 48
 
49
-  describe '#user_data_is_match?' do
50
-    subject(:msf_module) {
51
-      msf_module = described_class.new
52
-      msf_module.user_data = { match: 'match', match_set: 'match_set', run: 'run' }
53
-      msf_module
54
-    }
55
-    specify do
56
-      expect(msf_module.user_data_is_match?).to eq(true)
57
-    end
58
-  end
59
-
60 49
   describe "cloning modules into replicants" do
61 50
     module MsfExtensionTestFoo; def my_test1; true; end; end;
62 51
     module MsfExtensionTestBar; def my_test2; true; end; end;

+ 0
- 5
spec/support/shared/examples/msf/db_manager/session.rb View File

@@ -46,7 +46,6 @@ shared_examples_for 'Msf::DBManager::Session' do
46 46
                 framework: framework,
47 47
                 name: name
48 48
             )
49
-            allow(d).to receive(:user_data_is_match?).and_return(false)
50 49
             d
51 50
           end
52 51
 
@@ -137,10 +136,6 @@ shared_examples_for 'Msf::DBManager::Session' do
137 136
               }
138 137
             end
139 138
 
140
-            before do
141
-              allow(module_instance).to receive(:user_data_is_match?).and_return(true)
142
-            end
143
-
144 139
             it 'should make a MatchResult' do
145 140
               expect {
146 141
                 report_session

Loading…
Cancel
Save