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:



96
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
# File 'lib/ronin/web/user_agents/firefox.rb', line 96

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

.build_android(device_type: :mobile, firefox_version:) ⇒ String

Builds a Firefox User-Agent string for Android.

Parameters:

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

    The optional Android device.

  • firefox_version (String)

    The Firefox/... version.

Returns:

  • (String)

    A Firefox User-Agent string For Android.



345
346
347
348
349
350
351
352
# File 'lib/ronin/web/user_agents/firefox.rb', line 345

def self.build_android(device_type: :mobile, firefox_version: )
  device_type = DEVICE_TYPES.fetch(device_type)

  extensions = "Android; #{device_type}"
  extensions << "; rv:#{firefox_version}"

  return "Mozilla/5.0 (#{extensions}) Gecko/#{firefox_version} Firefox/#{firefox_version}"
end

.build_linux(encryption: nil, linux_distro: nil, arch: nil, lang: nil, firefox_version:) ⇒ String

Builds a Firefox User-Agent string for Linux.

Parameters:

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

    The optional encryption strength to set.

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

    The Linux Distro name.

  • arch (:arm, :arm64, nil) (defaults to: nil)

    The optional hardware architecture.

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

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

  • firefox_version (String)

    The Firefox/... version.

Returns:

  • (String)

    A Firefox User-Agent string For Linux.



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/ronin/web/user_agents/firefox.rb', line 317

def self.build_linux(encryption: nil, linux_distro: nil, arch: nil, lang: nil, firefox_version: )
  encryption_flag = ENCRYPTION.fetch(encryption)
  linux_arch      = OS::Linux::ARCHES[arch]
  linux_distro    = OS::Linux::DISTROS.fetch(linux_distro,linux_distro)

  extensions = String.new("X11")
  extensions << "; #{encryption_flag}" if encryption_flag
  extensions << "; #{linux_distro}" if linux_distro
  extensions << "; Linux"
  extensions << " #{linux_arch}" if linux_arch
  extensions << "; #{lang}" if lang
  extensions << "; rv:#{firefox_version}"

  return "Mozilla/5.0 (#{extensions}) Gecko/#{DESKTOP_GECKO_VERSION} Firefox/#{firefox_version}"
end

.build_macos(arch: :intel, macos_version:, firefox_version:) ⇒ String

Builds a Firefox User-Agent string for macOS.

Parameters:

  • arch (:intel) (defaults to: :intel)

    The optional hardware architecture.

  • macos_version (String, nil)

    The macOS version.

  • firefox_version (String)

    The Firefox/... version.

Returns:

  • (String)

    A Firefox User-Agent string For macOS.



287
288
289
290
291
292
293
294
# File 'lib/ronin/web/user_agents/firefox.rb', line 287

def self.build_macos(arch: :intel, macos_version: , firefox_version: )
  macos_arch = OS::MacOS::ARCHES.fetch(arch)

  extensions = "Macintosh; #{macos_arch} Mac OS X #{macos_version}"
  extensions << "; rv:#{firefox_version}"

  return "Mozilla/5.0 (#{extensions}) Gecko/#{DESKTOP_GECKO_VERSION} Firefox/#{firefox_version}"
end

.build_windows(windows_version:, arch:, firefox_version:) ⇒ String

Builds a Firefox User-Agent string for Windows.

Parameters:

  • windows_version (String, nil)

    The Windows version.

  • arch (:arm, :arm64, nil)

    The optional hardware architecture.

  • firefox_version (String)

    The Firefox/... version.

Returns:

  • (String)

    A Firefox User-Agent string For Windows.



261
262
263
264
265
266
267
268
269
270
# File 'lib/ronin/web/user_agents/firefox.rb', line 261

def self.build_windows(windows_version: , arch: , firefox_version: )
  windows_version = OS::Windows::VERSIONS.fetch(windows_version,windows_version)
  windows_arch    = OS::Windows::ARCHES.fetch(arch)

  extensions = "Windows NT #{windows_version}"
  extensions << "; #{windows_arch}" if windows_arch
  extensions << "; rv:#{firefox_version}"

  return "Mozilla/5.0 (#{extensions}) Gecko/#{DESKTOP_GECKO_VERSION} Firefox/#{firefox_version}"
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.



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

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