Class: BetterCap::Parsers::Cookie

Inherits:
Base
  • Object
show all
Defined in:
lib/bettercap/sniffer/parsers/cookie.rb

Overview

HTTP cookies parser.

Constant Summary collapse

FILTER =

Cookies to ignore.

[ '__cfduid', '_ga', '_gat' ].freeze

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


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bettercap/sniffer/parsers/cookie.rb', line 21

def on_packet( pkt )
  hostname = nil
  cookies = {}

  pkt.to_s.split("\n").each do |line|
    if line =~ /Host:\s*([^\s]+)/i
      hostname = $1
    elsif line =~ /.*Cookie:\s*(.+)/i
      $1.strip.split(';').each do |v|
        k, v = v.split('=').map(&:strip)
        next if k.nil? or v.nil?
        unless k.empty? or v.empty? or FILTER.include?(k)
          cookies[k] = v
        end
      end
    end
  end

  unless hostname.nil? or cookies.empty?
    StreamLogger.log_raw( pkt, "COOKIE", "[#{hostname.yellow}] #{cookies.map{|k,v| "#{k.green}=#{v.yellow}"}.join('; ')}" )
  end
end