Module: Ronin::Web::UserAgents::Chrome

Defined in:
lib/ronin/web/user_agents/chrome.rb

Overview

Represents every possible Chrome User-Agent string.

Constant Summary collapse

KNOWN_VERSIONS =

Known Chrome versions

File.readlines(
  File.join(DATA_DIR,'chrome','versions.txt'), chomp: true
)
SUPPORTED_OSES =

Supported Operating Systems.

[
  :windows,
  :macos,
  :linux,
  :android
]
KNOWN_OS_VERSIONS =

Known OS versions grouped by OS.

{
  windows: OS::Windows::VERSIONS.keys,
  macos:   OS::MacOS::VERSIONS,
  linux:   [],
  android: OS::Android::VERSIONS
}
SUPPORTED_OS_ARCHES =

Supported architectures grouped by OS.

{
  windows: OS::Windows::ARCHES.keys,
  macos:   OS::MacOS::ARCHES.keys,
  linux:   OS::Linux::ARCHES.keys,
  android: OS::Android::ARCHES.keys
}
SUPPORTED_LINUX_DISTROS =

Supported Linux Distros.

OS::Linux::DISTROS.keys

Class Method Summary collapse

Class Method Details

.build(chrome_version:, os:, os_version: nil, linux_distro: nil, arch: nil, android_device: nil) ⇒ String

Builds a new Chrome User-Agent string.

Parameters:

  • chrome_version (String)

    The Chrome/... version.

  • os (:windows, :macos, :linux, :android)

    The Operating System.

  • os_version (String, nil) (defaults to: nil)

    The Operating System version. Is required if os: is :windows, :macos, or :android.

  • linux_distro (:ubuntu, :fedora, :arch, String, nil) (defaults to: nil)

    The optional Linux Distro. Only supported if os: is :linux.

  • arch (:x86_64, :x86, :i686, :aarch64, :arm64, :arm) (defaults to: nil)

    The hardware architecture. Can be omitted if os: is :android.

  • android_device (String, nil) (defaults to: nil)

    The Android device. Only supported if os: is :android.

Returns:

  • (String)

    The new User-Agent string.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/ronin/web/user_agents/chrome.rb', line 61

def self.build(chrome_version: ,
               os: ,
               os_version: nil,
               linux_distro: nil,
               arch: nil,
               android_device: nil)
  case os
  when :windows
    unless os_version
      raise(ArgumentError,"os: :windows also requires an os_version: value")
    end

    build_windows(
      chrome_version:  chrome_version,
      windows_version: os_version,
      arch:            arch
    )
  when :macos
    unless os_version
      raise(ArgumentError,"os: :macos also requires an os_version: value")
    end

    build_macos(
      chrome_version: chrome_version,
      macos_version:  os_version,
      arch:           arch || :intel
    )
  when :linux
    unless arch
      raise(ArgumentError,"os: :linux also requires an arch: value")
    end

    build_linux(
      chrome_version: chrome_version,
      linux_distro:   linux_distro,
      arch:           arch
    )
  when :android
    unless os_version
      raise(ArgumentError,"os: :android also requires an os_version: value")
    end

    build_android(
      chrome_version:  chrome_version,
      android_version: os_version,
      arch:            arch,
      android_device:  android_device
    )
  else
    raise(ArgumentError,"unsupported os: value (#{os.inspect})")
  end
end

.random(chrome_version: KNOWN_VERSIONS.sample, os: SUPPORTED_OSES.sample, os_version: KNOWN_OS_VERSIONS[os].sample, linux_distro: SUPPORTED_LINUX_DISTROS.sample, arch: SUPPORTED_OS_ARCHES[os].sample, android_device: OS::Android::DEVICES.sample) ⇒ String

Generates a random Chrome User-Agent string.

Parameters:

  • chrome_version (String) (defaults to: KNOWN_VERSIONS.sample)

    The Chrome/... version.

  • os (:windows, :macos, :linux, :android) (defaults to: SUPPORTED_OSES.sample)

    The Operating System.

  • os_version (String, nil) (defaults to: KNOWN_OS_VERSIONS[os].sample)

    The Operating System version. Is required if os: is :windows, :macos, or :android.

  • linux_distro (:ubuntu, :fedora, :arch, String, nil) (defaults to: SUPPORTED_LINUX_DISTROS.sample)

    The optional Linux Distro. Only supported if os: is :linux.

  • arch (:x86_64, :x86, :i686, :aarch64, :arm64, :arm) (defaults to: SUPPORTED_OS_ARCHES[os].sample)

    The hardware architecture. Can be omitted if os: is :android.

  • android_device (String, nil) (defaults to: OS::Android::DEVICES.sample)

    The Android device. Only supported if os: is :android.

Returns:

  • (String)

    The random User-Agent string.



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/ronin/web/user_agents/chrome.rb', line 173

def self.random(chrome_version: KNOWN_VERSIONS.sample,
                os:             SUPPORTED_OSES.sample,
                os_version:     KNOWN_OS_VERSIONS[os].sample,
                linux_distro:   SUPPORTED_LINUX_DISTROS.sample,
                arch:           SUPPORTED_OS_ARCHES[os].sample,
                android_device: OS::Android::DEVICES.sample)
  build(
    chrome_version: chrome_version,
    os: os,
    os_version: os_version,
    linux_distro: linux_distro,
    arch: arch,
    android_device: android_device
  )
end