1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
| # Install Kaspersky Free Antivirus for Windows
# This script requests for free antivirus installer from free-antivirus download page API and install it with a fake activation code.
# https://www.kaspersky.com/downloads/free-antivirus
import os
import subprocess
import tempfile
import requests
ALLOWED_LOCALES = ["en-INT", "zh-Hans-CN"]
# The FAKE_ACTIVATION_CODE skips the Kaspersky account login process when first run KFA.
# The code is hardcoded in the Kaspersky activation dll file and used only for free versions.
# We are only sure about codes for the two locales now.
FAKE_ACTIVATION_CODE = {
"en-INT": "ZM4YW-FUTDY-W9B62-GSK26",
"zh-Hans-CN": "3SXCM-M9RJM-6985N-PWKP7",
}
SITES = {
"en-INT": "https://www.kaspersky.com",
"zh-Hans-CN": "https://www.kaspersky.com.cn",
}
def get_installer_url(locale):
site = SITES[locale]
params = {
"productcodes": "5003617",
"businesspurposes": "Update",
"licensetiers": "Free",
"sites": [site],
}
response = requests.get(
"https://api-router.kaspersky-labs.com/downloads/search/v3/b2c",
params=params,
)
response.raise_for_status()
versions = response.json()[0]["response"]["Windows"]["Kaspersky4Win"]["Downloader"][
site
]
max_version_key = max(
versions, key=lambda k: float(k) if k.isdigit() else -1
) # Get the max version, usually only one version, just in case
url = versions[str(max_version_key)][locale]["Link"]
return url
def download_and_get_path(url):
temp_dir = tempfile.mkdtemp()
response = requests.get(url, stream=True)
response.raise_for_status()
file_name = url.split("/")[-1]
with open(os.path.join(temp_dir, file_name), "wb") as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
return os.path.join(temp_dir, file_name)
if __name__ == "__main__":
if os.name != "nt":
raise NotImplementedError("Only Windows is supported.")
default_locale = "zh-Hans-CN"
if len(os.sys.argv) > 1:
locale = os.sys.argv[1]
if locale not in ALLOWED_LOCALES:
raise ValueError(f"Unsupported locale: {locale}")
else:
locale = default_locale
if locale not in FAKE_ACTIVATION_CODE:
raise ValueError(f"Unsupported locale: {locale}")
print("This script will install Kaspersky Free Antivirus (KFA) for Windows.")
print(
"Attention: If you cancel the installation, do not use the installer shortcut on the desktop, it will not activate KFA automatically."
)
print(
"If KFA asks for login or activation code, please use the activation code: "
+ FAKE_ACTIVATION_CODE[locale]
)
print(
"If KFA requests for an email address, please close the window and open KFA again."
)
installer_url = get_installer_url(locale)
print(installer_url)
installer_path = download_and_get_path(installer_url)
print(installer_path)
subprocess.Popen(
[
installer_path,
"/pSKIPPRODUCTCHECK=1",
"/pACTIVATIONCODE=" + FAKE_ACTIVATION_CODE[locale],
],
)
|