CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/spoof/replay/pcap_replay.rb
Views: 11784
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Auxiliary
7
include Msf::Exploit::Remote::Capture
8
9
def initialize
10
super(
11
'Name' => 'Pcap Replay Utility',
12
'Description' => %q{
13
Replay a pcap capture file
14
},
15
'Author' => 'amaloteaux',
16
'License' => MSF_LICENSE
17
)
18
19
register_options([
20
OptPath.new('FILENAME', [true, "The local pcap file to process"]),
21
OptString.new('FILE_FILTER', [false, "The filter string to apply on the file"]),
22
OptInt.new('LOOP', [true, "The number of times to loop through the file",1]),
23
OptInt.new('DELAY', [true, "the delay in millisecond between each loop",0]),
24
OptInt.new('PKT_DELAY', [true, "the delay in millisecond between each packet",0]),
25
])
26
27
deregister_options('SNAPLEN','FILTER','PCAPFILE','RHOST','TIMEOUT','SECRET','GATEWAY_PROBE_HOST','GATEWAY_PROBE_PORT')
28
end
29
30
def run
31
check_pcaprub_loaded # Check first
32
pkt_delay = datastore['PKT_DELAY']
33
delay = datastore['DELAY']
34
loop = datastore['LOOP']
35
infinity = true if loop <= 0
36
file_filter = datastore['FILE_FILTER']
37
filename = datastore['FILENAME']
38
verbose = datastore['VERBOSE']
39
count = 0
40
unless File.exist? filename and File.file? filename
41
print_error("Pcap File does not exist")
42
return
43
end
44
open_pcap
45
print_status("Sending file...") unless verbose
46
while (loop > 0 or infinity) do
47
vprint_status("Sending file (loop: #{count = count + 1})")
48
inject_pcap(filename, file_filter, pkt_delay )
49
loop -= 1 unless infinity
50
Kernel.select(nil, nil, nil, (delay * 1.0)/1000) if loop > 0 or infinity
51
end
52
close_pcap
53
end
54
end
55
56