Module: Ronin::Web::UserAgents::Firefox

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

Overview

Represents all possible Firefox User-Agent strings.

Constant Summary collapse

DESKTOP_GECKO_VERSION =

The default Gecko/... version.

@note: On desktop, the Gecko/... version is hardcoded to 20100101

'20100101'
ENCRYPTION =

Encryption Strengths.

{
  usa:  'U',
  international: 'I',
  none: 'N',
  no:   'N',

  nil => nil
}
DEVICE_TYPES =

Common device types.

{
  mobile: 'Mobile',
  tablet: 'Tablet',

  nil => nil
}
KNOWN_VERSIONS =

Known versions for the rv:... and Firefox/... values.

File.readlines(
  File.join(DATA_DIR,'firefox','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.

Returns:

  • (Array<Symbol, nil>)
OS::Linux::DISTROS.keys
SUPPORTED_ENCRYPTION =

Supported encryption strengths.

Returns:

  • (Array<Symbol, nil>)
ENCRYPTION.keys
KNOWN_LANGS =

IETF language tags (ex: en-GB).

Returns:

  • (Array<String>)
File.readlines(
  File.join(DATA_DIR,'firefox','langs.txt'), chomp: true
)
SUPPORTED_DEVICE_TYPES =

Supported device types.

Returns:

  • (Array<Symbol, nil>)
DEVICE_TYPES.keys

Class Method Summary collapse

Class Method Details

.build(firefox_version:, lang: nil, encryption: nil, os:, os_version: nil, linux_distro: nil, arch: nil, device_type: nil) ⇒ String

Builds a new Firefox User-Agent string.

Parameters:

  • firefox_version (String)

    The rv:... and Firefox/... version.

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

    The optional language identifier to add (ex: en-GB).

  • encryption (:usa, :international, :none, :no, nil) (defaults to: nil)

    The supported encryption strength.

  • 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, nil) (defaults to: nil)

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

  • device_type (:mobile, :tablet, nil) (defaults to: nil)

    The optional device type.

Returns:

  • (String)

    The Firefox User-Agent string.

See Also:



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/ronin/web/user_agents/firefox.rb', line 97

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

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

    build_macos(
      arch:            arch || :intel,
      macos_version:   os_version,
      firefox_version: firefox_version
    )
  when :linux
    build_linux(
      encryption:      encryption,
      linux_distro:    linux_distro,
      arch:            arch,
      lang:            lang,
      firefox_version: firefox_version
    )
  when :android
    build_android(
      device_type:     device_type || :mobile,
      firefox_version: firefox_version
    )
  else
    raise(ArgumentError,"unsupported os: value (#{os.inspect})")
  end
end

.random(firefox_version: KNOWN_VERSIONS.sample, encryption: SUPPORTED_ENCRYPTION.sample, lang: KNOWN_LANGS.sample, os: SUPPORTED_OSES.sample, os_version: KNOWN_OS_VERSIONS[os].sample, linux_distro: SUPPORTED_LINUX_DISTROS.sample, arch: SUPPORTED_OS_ARCHES[os].sample, device_type: DEVICE_TYPES.keys.sample) ⇒ String

Generates a random Firefox User-Agent string.

Parameters:

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

    The rv:... and Firefox/... version.

  • encryption (:usa, :international, :none, :no, nil) (defaults to: SUPPORTED_ENCRYPTION.sample)

    The supported encryption strength.

  • lang (String, nil) (defaults to: KNOWN_LANGS.sample)

    The optional language identifier to add (ex: en-GB).

  • 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, nil) (defaults to: SUPPORTED_OS_ARCHES[os].sample)

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

  • device_type (:mobile, :tablet, nil) (defaults to: DEVICE_TYPES.keys.sample)

    The optional device type.

Returns:

  • (String)

    The random User-Agent string.



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/ronin/web/user_agents/firefox.rb', line 228

def self.random(firefox_version: KNOWN_VERSIONS.sample,
                encryption:      SUPPORTED_ENCRYPTION.sample,
                lang:            KNOWN_LANGS.sample,
                os:              SUPPORTED_OSES.sample,
                os_version:      KNOWN_OS_VERSIONS[os].sample,
                linux_distro:    SUPPORTED_LINUX_DISTROS.sample,
                arch:            SUPPORTED_OS_ARCHES[os].sample,
                device_type:     DEVICE_TYPES.keys.sample)
  build(
    firefox_version: firefox_version,
    os: os,
    os_version: os_version,
    device_type: device_type,
    linux_distro: linux_distro,
    arch: arch,
    lang: lang
  )
end