CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/user_agent.rb
Views: 11766
1
# -*- coding: binary -*-
2
3
#
4
# A helper module for using and referencing coming user agent strings.
5
#
6
module Rex::UserAgent
7
8
#
9
# Taken from https://www.whatismybrowser.com/guides/the-latest-user-agent/
10
#
11
COMMON_AGENTS = [
12
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36', # Chrome Windows
13
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36', # Chrome MacOS
14
15
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.2792.79', # Edge Windows
16
17
'Mozilla/5.0 (iPad; CPU OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1', # Safari iPad
18
'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15', # Safari MacOS
19
20
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0', # Firefox Windows
21
'Mozilla/5.0 (Macintosh; Intel Mac OS X 14.7; rv:131.0) Gecko/20100101 Firefox/131.0' # Firefox MacOS
22
]
23
24
#
25
# A randomly-selected agent that will be consistent for the duration of metasploit running
26
#
27
def self.session_agent
28
if @@session_agent
29
@@session_agent
30
else
31
@@session_agent = self.random
32
end
33
end
34
35
@@session_agent = nil
36
37
#
38
# Pick a random agent from the common agent list.
39
#
40
def self.random
41
COMMON_AGENTS.sample
42
end
43
44
#
45
# Choose the agent with the shortest string (for use in payloads)
46
#
47
def self.shortest
48
@@shortest_agent ||= COMMON_AGENTS.min { |a, b| a.size <=> b.size }
49
end
50
51
#
52
# Choose the most frequent user agent
53
#
54
def self.most_common
55
COMMON_AGENTS[0]
56
end
57
58
end
59
60