Module: WPScan::BrowserAuthenticator
- Defined in:
- lib/wpscan/browser_authenticator.rb
Constant Summary collapse
- COOKIE_DELIMITERS =
Characters that, if present in a cookie name or value, would corrupt the serialized Cookie header. Per RFC 6265 these are forbidden in cookie-octets, but a noncompliant IdP could still emit them.
/[;,\s]/
Class Method Summary collapse
- .authenticate(login_url) ⇒ Object
- .chrome_not_found_message(error) ⇒ Object
-
.run_login_session(login_url) ⇒ Object
Drives the interactive browser session and returns the resulting cookie jar.
- .serialize_cookies(cookies) ⇒ Object
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(login_url) 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 = run_login_session(login_url) raise WPScan::Error::SAMLAuthenticationFailed if .nil? || .empty? () end |
.chrome_not_found_message(error) ⇒ Object
49 50 51 52 53 |
# File 'lib/wpscan/browser_authenticator.rb', line 49 def self.(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.}" 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.run_login_session(login_url) browser = Ferrum::Browser.new(headless: false) puts 'SAML authentication needed. Log in via the browser window that just opened, then press enter.' browser.goto(login_url) gets # Waits for user input # Attempt an innocuous command to check if the browser is still responsive browser.current_url browser..all rescue Ferrum::BinaryNotFoundError, Ferrum::EmptyPathError => e raise WPScan::Error::BrowserFailed, (e) rescue Ferrum::Error => e raise WPScan::Error::BrowserFailed, 'The browser was closed or failed before SAML authentication could be completed ' \ "(#{e.class}: #{e.})." 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.() .map do |_name, | raise WPScan::Error::SAMLAuthenticationFailed if .name.match?(COOKIE_DELIMITERS) || .value.to_s.match?(COOKIE_DELIMITERS) "#{.name}=#{.value}" end.join('; ') end |