Skip to content

Commit 568b33c

Browse files
author
Pedro Ribeiro
committed
Merge pull request #22 from rapid7/master
merging
2 parents 9746753 + 1f26ec1 commit 568b33c

File tree

85 files changed

+3343
-487
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+3343
-487
lines changed

Gemfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ PATH
1616
packetfu (= 1.1.11)
1717
railties
1818
rb-readline-r7
19-
recog (= 2.0.6)
19+
recog (= 2.0.14)
2020
robots
2121
rubyzip (~> 1.1)
2222
sqlite3
@@ -25,7 +25,7 @@ PATH
2525
activerecord (>= 4.0.9, < 4.1.0)
2626
metasploit-credential (= 1.0.1)
2727
metasploit-framework (= 4.11.4)
28-
metasploit_data_models (= 1.2.5)
28+
metasploit_data_models (= 1.2.7)
2929
pg (>= 0.11)
3030
metasploit-framework-pcap (4.11.4)
3131
metasploit-framework (= 4.11.4)
@@ -126,7 +126,7 @@ GEM
126126
activesupport (>= 4.0.9, < 4.1.0)
127127
railties (>= 4.0.9, < 4.1.0)
128128
metasploit-payloads (1.0.15)
129-
metasploit_data_models (1.2.5)
129+
metasploit_data_models (1.2.7)
130130
activerecord (>= 4.0.9, < 4.1.0)
131131
activesupport (>= 4.0.9, < 4.1.0)
132132
arel-helpers
@@ -178,7 +178,7 @@ GEM
178178
thor (>= 0.18.1, < 2.0)
179179
rake (10.4.2)
180180
rb-readline-r7 (0.5.2.0)
181-
recog (2.0.6)
181+
recog (2.0.14)
182182
nokogiri
183183
redcarpet (3.2.3)
184184
rkelly-remix (0.0.6)

lib/msf/core/auxiliary/udp_scanner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def scanner_spoof_send(data, ip, port, srcip, num_packets=1)
8686
p.recalc
8787
print_status("Sending #{num_packets} packet(s) to #{ip} from #{srcip}")
8888
1.upto(num_packets) do |x|
89-
capture_sendto(p, ip)
89+
break unless capture_sendto(p, ip)
9090
end
9191
close_pcap
9292
end

lib/msf/core/db_manager/exploit_attempt.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ def do_report_failure_or_success(opts)
153153
attempt_info[:vuln_id] = vuln.id
154154
vuln.vuln_attempts.create(attempt_info)
155155

156+
create_match_result_for_vuln(vuln,opts)
157+
156158
# Correct the vuln's associated service if necessary
157159
if svc and vuln.service_id.nil?
158160
vuln.service = svc
@@ -176,4 +178,59 @@ def do_report_failure_or_success(opts)
176178
}
177179

178180
end
181+
182+
# Create a MetasploitDataModels::AutomaticExploitation::Match result for the given vuln
183+
# @option opts [Integer] :run_id
184+
# @return [void]
185+
def create_match_result_for_vuln(vuln, opts)
186+
run = MetasploitDataModels::AutomaticExploitation::Run.where(id:opts[:run_id]).last
187+
188+
if run.present?
189+
match = MetasploitDataModels::AutomaticExploitation::Match.by_run_and_vuln(run,vuln).last
190+
191+
# If no match found in the current run
192+
unless match.present?
193+
# Create match if the vuln has the data we need to create a match
194+
match = create_match_for_vuln(vuln,opts.merge(run:run))
195+
end
196+
197+
create_match_result(opts.merge(match:match,run:run)) if match.present?
198+
end
199+
end
200+
201+
# Create a MetasploitDataModels::AutomaticExploitation::Match result with a success or failure state
202+
# @option opts [MetasploitDataModels::AutomaticExploitation::Match] :match
203+
# @option opts [MetasploitDataModels::AutomaticExploitation::Run] :run
204+
# @return [void]
205+
def create_match_result(opts)
206+
if opts[:session_id]
207+
state = MetasploitDataModels::AutomaticExploitation::MatchResult::SUCCEEDED
208+
else
209+
state = MetasploitDataModels::AutomaticExploitation::MatchResult::FAILED
210+
end
211+
212+
MetasploitDataModels::AutomaticExploitation::MatchResult.create!(
213+
match: opts[:match],
214+
run: opts[:run],
215+
state: state
216+
)
217+
end
218+
219+
# Create a MetasploitDataModels::AutomaticExploitation::Match for the given vuln
220+
# @option vuln [Mdm::Vuln] :vuln
221+
# @option opts [Mdm::Workspace] :workspace
222+
# @option opts [String] :username
223+
# @return [ MetasploitDataModels::AutomaticExploitation::Match, MetasploitDataModels::AutomaticExploitation::Run]
224+
def create_match_for_vuln(vuln,opts)
225+
wspace = opts[:workspace] || workspace
226+
run = opts[:run]
227+
module_fullname = opts[:module]
228+
229+
run.match_set.create_match_for_vuln(
230+
vuln,
231+
workspace: wspace,
232+
module_fullname: module_fullname
233+
)
234+
end
235+
179236
end

lib/msf/core/db_manager/session.rb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,10 @@ def report_session(opts)
9191

9292
wspace = s.workspace
9393

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
103-
# This is a live session, we know the host is vulnerable to something.
104-
infer_vuln_from_session(session, wspace)
105-
end
94+
95+
if session and session.via_exploit
96+
# This is a live session, we know the host is vulnerable to something.
97+
infer_vuln_from_session(session, wspace)
10698
end
10799

108100
s
@@ -158,6 +150,7 @@ def infer_vuln_from_session(session, wspace)
158150
username: session.username,
159151
vuln: vuln,
160152
workspace: wspace,
153+
run_id: session.exploit.user_data.try(:[], :run_id)
161154
}
162155

163156
framework.db.report_exploit_success(attempt_info)

lib/msf/core/exploit.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,8 @@ def report_failure
12701270
:fail_detail => self.fail_detail,
12711271
:target_name => self.target.name,
12721272
:username => self.owner,
1273-
:refs => self.references
1273+
:refs => self.references,
1274+
:run_id => self.datastore['RUN_ID']
12741275
}
12751276

12761277
if self.datastore['RHOST'] and self.options['RHOST']
@@ -1284,15 +1285,6 @@ def report_failure
12841285
end
12851286
end
12861287

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-
12961288
framework.db.report_exploit_failure(info)
12971289
end
12981290

lib/msf/core/exploit/capture.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,24 @@ def inject_pcap(pcap_file, filter=nil, delay = 0, pcap=self.capture)
232232
end
233233
end
234234

235-
# capture_sendto is intended to replace the old Rex::Socket::Ip.sendto method. It requires
236-
# a payload and a destination address. To send to the broadcast address, set bcast
237-
# to true (this will guarantee that packets will be sent even if ARP doesn't work
238-
# out).
235+
# Sends a payload to a given target using the pcap capture interface
236+
#
237+
# == Parameters:
238+
# payload:: The payload String to send
239+
# dhost:: the destination host to send to
240+
# bcast:: set to `true` to send to the broadcast address if necessary
241+
# dev:: the name of the network interface to send the payload on
242+
#
243+
# == Returns:
244+
# The number of bytes sent iff the payload was successfully sent/injected. `false` otherwise
239245
def capture_sendto(payload="", dhost=nil, bcast=false, dev=nil)
240246
raise RuntimeError, "Could not access the capture process (remember to open_pcap first!)" unless self.capture
241247
raise RuntimeError, "Must specify a host to sendto" unless dhost
242248
dev ||= datastore['INTERFACE']
243249
dst_mac, src_mac = lookup_eth(dhost, dev)
244250
if dst_mac == nil and not bcast
245-
raise RuntimeError, 'Unable to determine the destination MAC and bcast is false'
251+
vprint_error("Unable to determine the destination MAC for #{dhost} on #{dev} and bcast is false")
252+
return false
246253
end
247254
inject_eth(:payload => payload, :eth_daddr => dst_mac, :eth_saddr => src_mac)
248255
end

lib/msf/core/exploit_driver.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ def job_run_proc(ctx)
210210
# Wait for session, but don't wait long.
211211
delay = 0.01
212212
end
213+
213214
exploit.handle_exception e
214215
end
215216

lib/msf/core/module.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ class Module
5959
# datastore, consumed by #replicant to allow clean override of MSF module methods.
6060
REPLICANT_EXTENSION_DS_KEY = 'ReplicantExtensions'
6161

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-
6662
# Make include public so we can runtime extend
6763
public_class_method :include
6864

@@ -295,13 +291,6 @@ def fail_with(reason, msg=nil)
295291
raise RuntimeError, "#{reason.to_s}: #{msg}"
296292
end
297293

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
305294

306295
##
307296
#
@@ -347,7 +336,6 @@ def self.cached?
347336
# {Msf::Simple::Auxiliary#run_simple} for correlating where modules came
348337
# from.
349338
#
350-
# @see #user_data_is_match?
351339
attr_accessor :user_data
352340

353341
protected

lib/msf/core/module/platform.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,4 +524,12 @@ class Firefox < Msf::Module::Platform
524524
Rank = 100
525525
Alias = "firefox"
526526
end
527+
528+
#
529+
# Mainframe
530+
#
531+
class Mainframe < Msf::Module::Platform
532+
Rank = 100
533+
Alias = "mainframe"
534+
end
527535
end

lib/msf/core/payload.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Payload < Msf::Module
3030
require 'msf/core/payload/java'
3131
require 'msf/core/payload/dalvik'
3232
require 'msf/core/payload/firefox'
33+
require 'msf/core/payload/mainframe'
3334

3435
##
3536
#

0 commit comments

Comments
 (0)