CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/user_agent.rb
Views: 1904
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
# Chrome
13
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
14
'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',
15
16
# Edge
17
'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',
18
19
# Safari
20
'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',
21
'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',
22
23
# Firefox
24
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0',
25
'Mozilla/5.0 (Macintosh; Intel Mac OS X 14.4; rv:124.0) Gecko/20100101 Firefox/124.0'
26
]
27
28
#
29
# A randomly-selected agent that will be consistent for the duration of metasploit running
30
#
31
def self.session_agent
32
if @@session_agent
33
@@session_agent
34
else
35
@@session_agent = self.random
36
end
37
end
38
39
@@session_agent = nil
40
41
#
42
# Pick a random agent from the common agent list.
43
#
44
def self.random
45
COMMON_AGENTS.sample
46
end
47
48
#
49
# Choose the agent with the shortest string (for use in payloads)
50
#
51
def self.shortest
52
@@shortest_agent ||= COMMON_AGENTS.min { |a, b| a.size <=> b.size }
53
end
54
55
#
56
# Choose the most frequent user agent
57
#
58
def self.most_common
59
COMMON_AGENTS[0]
60
end
61
62
end
63
64
65