Skip to content

Instantly share code, notes, and snippets.

@evilsocket
Last active May 16, 2018 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save evilsocket/bfdb1af7e6bf9d9d0bfe to your computer and use it in GitHub Desktop.
Save evilsocket/bfdb1af7e6bf9d9d0bfe to your computer and use it in GitHub Desktop.
BetterCAP example HTTP(S) Proxy Module
class HackTitle < BetterCap::Proxy::HTTP::Module
meta(
'Name' => 'HackTitle',
'Description' => 'Adds a "!!! HACKED !!!" string to every webpage title.',
'Version' => '1.0.0',
'Author' => "Simone 'evilsocket' Margaritelli",
'License' => 'GPL3'
)
# called before the request is performed
def on_pre_request( request ); end
# this method is called after the request is performed
def on_request( request, response )
# is it a html page?
if response.content_type =~ /^text\/html.*/
BetterCap::Logger.info "Hacking http://#{request.host}#{request.url}"
# make sure to use sub! or gsub! to update the instance
response.body.sub!( '<title>', '<title> !!! HACKED !!! ' )
end
end
end
@g4z
Copy link

g4z commented May 1, 2016

I think that in this code snippet, "#{request.url}" should be changed to "#{request.path}".
Running this snippet (as found in the documentation) throws this warning...

...
[W] Error with proxy module: undefined method url' for #<BetterCap::Proxy::HTTP::Request:0x00000001dd3230> [W] Exception : NoMethodError Message : undefined methodurl' for #BetterCap::Proxy::HTTP::Request:0x00000001dd3230
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment