Module: Rex::UserAgent

Defined in:
lib/rex/user_agent.rb

Overview

A helper module for using and referencing comming user agent strings.

Constant Summary collapse

COMMON_AGENTS =

List from techblog.willshouse.com/2012/01/03/most-common-user-agents/ This article was updated on July 11th 2015. It's probably worth updating this list over time.

This list is in the order of most common to least common.

[
    # Chrome
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36',
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 12_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36',

    # Edge
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 Edg/95.0.1020.44',

    # Safari
    'Mozilla/5.0 (iPad; CPU OS 15_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1',
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 12_0_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Safari/605.1.15',

    # Firefox
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0',
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 12.0; rv:94.0) Gecko/20100101 Firefox/94.0',
]
@@session_agent =
nil

Class Method Summary collapse

Class Method Details

.most_commonObject

Choose the most frequent user agent



62
63
64
# File 'lib/rex/user_agent.rb', line 62

def self.most_common
  COMMON_AGENTS[0]
end

.randomObject

Pick a random agent from the common agent list.



48
49
50
# File 'lib/rex/user_agent.rb', line 48

def self.random
  COMMON_AGENTS.sample
end

.session_agentObject

A randomly-selected agent that will be consistent for the duration of metasploit running



35
36
37
38
39
40
41
# File 'lib/rex/user_agent.rb', line 35

def self.session_agent
  if @@session_agent
    @@session_agent
  else
    @@session_agent = self.random
  end
end

.shortestObject

Choose the agent with the shortest string (for use in payloads)



55
56
57
# File 'lib/rex/user_agent.rb', line 55

def self.shortest
  @@shortest_agent ||= COMMON_AGENTS.min { |a, b| a.size <=> b.size }
end