Skip to content

Commit cb10062

Browse files
authored
Merge pull request rapid7#19540 from smashery/ua_strings_oct24
Update User Agent strings for October 2024
2 parents 00b1d8f + 395e743 commit cb10062

File tree

2 files changed

+63
-12
lines changed

2 files changed

+63
-12
lines changed

lib/rex/user_agent.rb

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@ module Rex::UserAgent
99
# Taken from https://www.whatismybrowser.com/guides/the-latest-user-agent/
1010
#
1111
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',
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
1514

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',
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
1816

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',
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
2219

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'
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
2622
]
2723

2824
#
@@ -60,4 +56,3 @@ def self.most_common
6056
end
6157

6258
end
63-
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/python3
2+
import requests
3+
import re
4+
5+
def replace_agent_string(lines, replace_marker, url, regex):
6+
VALID_CHARS = 'a-zA-Z0-9\\(\\);:\\.,/_ '
7+
regex = regex.replace('{VALID_CHARS}', VALID_CHARS)
8+
print(f'Updating {replace_marker}')
9+
for x in range(0, len(lines)):
10+
if replace_marker in lines[x]:
11+
break
12+
else:
13+
raise RuntimeError(f"Couldn't find marker {replace_marker}")
14+
15+
response = requests.get(url)
16+
if response.status_code != 200:
17+
raise RuntimeError(f"Can't retrieve {url}")
18+
19+
match = re.search(regex, response.text)
20+
if match is None:
21+
raise RuntimeError(f"Couldn't match regex {regex}")
22+
23+
new_string = match.groups()[0]
24+
print(f'New value is: {new_string}')
25+
old_line = lines[x]
26+
if f"'{new_string}'" in old_line:
27+
print('(This is unchanged from the previous value)')
28+
else:
29+
new_line = re.sub("'(.*)'", f"'{new_string}'", old_line)
30+
if old_line == new_line:
31+
raise RuntimeError(f"Line didn't change: {old_line}")
32+
33+
lines[x] = new_line
34+
35+
36+
chrome_url = "https://www.whatismybrowser.com/guides/the-latest-user-agent/chrome"
37+
edge_url = "https://www.whatismybrowser.com/guides/the-latest-user-agent/edge"
38+
safari_url = "https://www.whatismybrowser.com/guides/the-latest-user-agent/safari"
39+
firefox_url = "https://www.whatismybrowser.com/guides/the-latest-user-agent/firefox"
40+
41+
user_agent_filename = 'lib/rex/user_agent.rb'
42+
with open(user_agent_filename,'r') as f:
43+
lines = f.read().splitlines()
44+
45+
replace_agent_string(lines, 'Chrome Windows', chrome_url, '<td>Chrome \\(Standard\\)</td>\s*<td>\s*<ul>\s*<li><span class="code">([{VALID_CHARS}]*Windows NT[{VALID_CHARS}]*)</span>')
46+
replace_agent_string(lines, 'Chrome MacOS', chrome_url, '<td>Chrome \\(Standard\\)</td>\s*<td>\s*<ul>\s*<li><span class="code">([{VALID_CHARS}]*Macintosh[{VALID_CHARS}]*)</span>')
47+
replace_agent_string(lines, 'Edge Windows', edge_url, '<td>Edge \\(Standard\\)</td>\s*<td>\s*<ul>\s*<li><span class="code">([{VALID_CHARS}]*Windows NT[{VALID_CHARS}]*)</span>')
48+
replace_agent_string(lines, 'Safari iPad', safari_url, '<td>\s*Safari on <b>Ipad</b>\s*</td>\s*<td>\s*<ul>\s*<li><span class="code">([{VALID_CHARS}]*iPad[{VALID_CHARS}]*)</span>')
49+
replace_agent_string(lines, 'Safari MacOS', safari_url, '<td>Safari \\(Standard\\)</td>\s*<td>\s*<ul>\s*<li><span class="code">([{VALID_CHARS}]*Macintosh[{VALID_CHARS}]*)</span>')
50+
replace_agent_string(lines, 'Firefox Windows', firefox_url, '<td>\s*Firefox on <b>Windows</b>\s*</td>\s*<td>\s*<ul>\s*<li><span class="code">([{VALID_CHARS}]*Windows NT[{VALID_CHARS}]*)</span>')
51+
replace_agent_string(lines, 'Firefox MacOS', firefox_url, '<td>\s*Firefox on <b>Macos</b>\s*</td>\s*<td>\s*<ul>\s*<li><span class="code">([{VALID_CHARS}]*Macintosh[{VALID_CHARS}]*)</span>')
52+
53+
with open(user_agent_filename, 'w') as f:
54+
f.write('\n'.join(lines) + '\n')
55+
56+
print('Done')

0 commit comments

Comments
 (0)