Class: BetterCap::Parsers::Httpauth
- Defined in:
- lib/bettercap/sniffer/parsers/httpauth.rb
Overview
HTTP basic and digest authentication parser.
Instance Method Summary collapse
Methods inherited from Base
available, from_cmdline, inherited, #initialize, load_by_names, load_custom
Constructor Details
This class inherits a constructor from BetterCap::Parsers::Base
Instance Method Details
#on_packet(pkt) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/bettercap/sniffer/parsers/httpauth.rb', line 18 def on_packet( pkt ) lines = pkt.to_s.split("\n") hostname = nil path = nil lines.each do |line| if line =~ /[A-Z]+\s+(\/[^\s]+)\s+HTTP\/\d\.\d/ path = $1 elsif line =~ /Host:\s*([^\s]+)/i hostname = $1 elsif line =~ /Authorization:\s*Basic\s+([^\s]+)/i encoded = $1 decoded = Base64.decode64(encoded) user, pass = decoded.split(':') StreamLogger.log_raw( pkt, 'HTTP BASIC AUTH', "http://#{hostname}#{path} - username=#{user} password=#{pass}".yellow ) elsif line =~ /Authorization:\s*([^\s]+)\s+(.+)/i StreamLogger.log_raw( pkt, "HTTP #{$1} AUTH", "http://#{hostname}#{path}\n#{$1.blue}: #{$2.yellow}" ) end end end |