Module: WPScan::BrowserAuthenticator

Defined in:
lib/wpscan/browser_authenticator.rb

Constant Summary collapse

/[;,\s]/

Class Method Summary collapse

Class Method Details

.authenticate(login_url) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/wpscan/browser_authenticator.rb', line 12

def self.authenticate()
  unless $stdin.tty?
    raise WPScan::Error::BrowserFailed,
          'SAML authentication needs an interactive terminal to wait for login, but stdin is not a TTY. ' \
          'Run wpscan from a real shell when using --expect-saml.'
  end

  cookies = ()

  raise WPScan::Error::SAMLAuthenticationFailed if cookies.nil? || cookies.empty?

  serialize_cookies(cookies)
end

.chrome_not_found_message(error) ⇒ Object



49
50
51
52
53
# File 'lib/wpscan/browser_authenticator.rb', line 49

def self.chrome_not_found_message(error)
  '--expect-saml requires Chrome or Chromium to be installed and available on PATH ' \
    '(install Chrome / Chromium, or point Ferrum at a binary via BROWSER_PATH). ' \
    "Underlying error: #{error.message}"
end

.run_login_session(login_url) ⇒ Object

Drives the interactive browser session and returns the resulting cookie jar. Translates Ferrum failures into BrowserFailed with a context-specific message.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/wpscan/browser_authenticator.rb', line 28

def self.()
  browser = Ferrum::Browser.new(headless: false)

  puts 'SAML authentication needed. Log in via the browser window that just opened, then press enter.'
  browser.goto()
  gets # Waits for user input

  # Attempt an innocuous command to check if the browser is still responsive
  browser.current_url

  browser.cookies.all
rescue Ferrum::BinaryNotFoundError, Ferrum::EmptyPathError => e
  raise WPScan::Error::BrowserFailed, chrome_not_found_message(e)
rescue Ferrum::Error => e
  raise WPScan::Error::BrowserFailed,
        'The browser was closed or failed before SAML authentication could be completed ' \
        "(#{e.class}: #{e.message})."
ensure
  browser.quit if browser&.process
end

.serialize_cookies(cookies) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/wpscan/browser_authenticator.rb', line 55

def self.serialize_cookies(cookies)
  cookies.map do |_name, cookie|
    raise WPScan::Error::SAMLAuthenticationFailed if cookie.name.match?(COOKIE_DELIMITERS) ||
                                                     cookie.value.to_s.match?(COOKIE_DELIMITERS)

    "#{cookie.name}=#{cookie.value}"
  end.join('; ')
end