Class: BetterCap::Proxy::HTTP::SSLStrip::CookieMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/bettercap/proxy/http/sslstrip/cookiemonitor.rb

Overview

Class to handle a cookies for sslstrip.

Instance Method Summary collapse

Constructor Details

#initializeCookieMonitor

Create an instance of this object.



22
23
24
# File 'lib/bettercap/proxy/http/sslstrip/cookiemonitor.rb', line 22

def initialize
  @set = []
end

Instance Method Details

#add!(request) ⇒ Object



26
27
28
# File 'lib/bettercap/proxy/http/sslstrip/cookiemonitor.rb', line 26

def add!(request)
  @set << [request.client, get_domain(request)]
end

#get_domain(request) ⇒ Object

Return the cookie domain given the request object.



58
59
60
61
# File 'lib/bettercap/proxy/http/sslstrip/cookiemonitor.rb', line 58

def get_domain(request)
  parts = request.host.split('.')
  ".#{parts[-2]}.#{parts[-1]}"
end

#get_expired_headers!(request) ⇒ Object

Build cookie expiration headers for the request and add its domain to our list.



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bettercap/proxy/http/sslstrip/cookiemonitor.rb', line 43

def get_expired_headers!(request)
  domain = get_domain(request)
  @set << [request.client, domain]

  expired = []
  request['Cookie'].split(';').each do |cookie|
    cname = cookie.split("=")[0].strip
    expired << "#{cname}=EXPIRED; path=/; domain=#{domain}; Expires=Mon, 01-Jan-1990 00:00:00 GMT"
    expired << "#{cname}=EXPIRED; path=/; domain=#{request.host}; Expires=Mon, 01-Jan-1990 00:00:00 GMT"
  end

  expired
end

#is_clean?(request) ⇒ Boolean

Return true if the request was already cleaned.

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
# File 'lib/bettercap/proxy/http/sslstrip/cookiemonitor.rb', line 31

def is_clean?(request)
  if request.post?
    return true
  elsif request['Cookie'].empty?
    return true
  else
    return @set.include?( [request.client, get_domain(request)] )
  end
end