64 lines
1.7 KiB
Ruby
64 lines
1.7 KiB
Ruby
# -*- coding: binary -*-
|
|
|
|
#
|
|
# A helper module for using and referencing coming user agent strings.
|
|
#
|
|
module Rex::UserAgent
|
|
|
|
#
|
|
# Taken from https://www.whatismybrowser.com/guides/the-latest-user-agent/
|
|
#
|
|
COMMON_AGENTS = [
|
|
# Chrome
|
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
|
|
|
|
# Edge
|
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.2420.65',
|
|
|
|
# Safari
|
|
'Mozilla/5.0 (iPad; CPU OS 17_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.3.1 Mobile/15E148 Safari/604.1',
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_4_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.3.1 Safari/605.1.15',
|
|
|
|
# Firefox
|
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0',
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 14.4; rv:124.0) Gecko/20100101 Firefox/124.0'
|
|
]
|
|
|
|
#
|
|
# A randomly-selected agent that will be consistent for the duration of metasploit running
|
|
#
|
|
def self.session_agent
|
|
if @@session_agent
|
|
@@session_agent
|
|
else
|
|
@@session_agent = self.random
|
|
end
|
|
end
|
|
|
|
@@session_agent = nil
|
|
|
|
#
|
|
# Pick a random agent from the common agent list.
|
|
#
|
|
def self.random
|
|
COMMON_AGENTS.sample
|
|
end
|
|
|
|
#
|
|
# Choose the agent with the shortest string (for use in payloads)
|
|
#
|
|
def self.shortest
|
|
@@shortest_agent ||= COMMON_AGENTS.min { |a, b| a.size <=> b.size }
|
|
end
|
|
|
|
#
|
|
# Choose the most frequent user agent
|
|
#
|
|
def self.most_common
|
|
COMMON_AGENTS[0]
|
|
end
|
|
|
|
end
|
|
|