-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.py
More file actions
204 lines (165 loc) · 7.07 KB
/
Copy pathinstall.py
File metadata and controls
204 lines (165 loc) · 7.07 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env python3
"""
ANTRATTER — Installer
Installs ANTRATTER as a system service for 24/7 protection:
- macOS: LaunchAgent plist (~/.config/LaunchAgents)
- Linux: systemd user unit (~/.config/systemd/user)
- Windows: Windows Service (via sc.exe / NSSM)
Usage:
python install.py install — install & enable service
python install.py uninstall — remove service
python install.py status — check service status
"""
import os
import sys
import platform
import subprocess
import argparse
_OS = platform.system()
_PYTHON = sys.executable
_SCRIPT = os.path.abspath(os.path.join(os.path.dirname(__file__), "antiratter.py"))
_SVC_NAME = "com.antratter.protection"
_SVC_DISP = "ANTRATTER Anti-RAT Protection"
_WATCHDOG = os.path.abspath(os.path.join(os.path.dirname(__file__), "watchdog.py"))
def install():
if _OS == "Darwin":
_install_macos()
elif _OS == "Linux":
_install_linux()
elif _OS == "Windows":
_install_windows()
else:
print(f"Unsupported OS: {_OS}")
sys.exit(1)
def uninstall():
if _OS == "Darwin":
_uninstall_macos()
elif _OS == "Linux":
_uninstall_linux()
elif _OS == "Windows":
_uninstall_windows()
def status():
if _OS == "Darwin":
subprocess.run(["launchctl", "list", _SVC_NAME])
elif _OS == "Linux":
subprocess.run(["systemctl", "--user", "status", "antratter.service"])
elif _OS == "Windows":
subprocess.run(["sc", "query", "AntiRatter"])
# ── macOS ──────────────────────────────────────────────────────────────────────
def _install_macos():
plist_dir = os.path.expanduser("~/Library/LaunchAgents")
plist_path = os.path.join(plist_dir, f"{_SVC_NAME}.plist")
os.makedirs(plist_dir, exist_ok=True)
plist_content = f"""<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>{_SVC_NAME}</string>
<key>ProgramArguments</key>
<array>
<string>{_PYTHON}</string>
<string>{_WATCHDOG}</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>{os.path.expanduser('~/.antratter/logs/stdout.log')}</string>
<key>StandardErrorPath</key>
<string>{os.path.expanduser('~/.antratter/logs/stderr.log')}</string>
</dict>
</plist>
"""
with open(plist_path, "w") as f:
f.write(plist_content)
subprocess.run(["launchctl", "load", "-w", plist_path], check=True)
print(f"[OK] ANTRATTER installed as LaunchAgent: {plist_path}")
print("[OK] Protection starts automatically on login.")
def _uninstall_macos():
plist_path = os.path.expanduser(
f"~/Library/LaunchAgents/{_SVC_NAME}.plist"
)
if os.path.isfile(plist_path):
subprocess.run(["launchctl", "unload", "-w", plist_path])
os.remove(plist_path)
print("[OK] ANTRATTER removed.")
else:
print("[!] ANTRATTER is not installed.")
# ── Linux ──────────────────────────────────────────────────────────────────────
def _install_linux():
unit_dir = os.path.expanduser("~/.config/systemd/user")
unit_path = os.path.join(unit_dir, "antratter.service")
os.makedirs(unit_dir, exist_ok=True)
unit_content = f"""[Unit]
Description={_SVC_DISP}
After=network.target
[Service]
Type=simple
ExecStart={_PYTHON} {_WATCHDOG}
Restart=always
RestartSec=3
RestartSec=5
StandardOutput=append:{os.path.expanduser('~/.antratter/logs/stdout.log')}
StandardError=append:{os.path.expanduser('~/.antratter/logs/stderr.log')}
[Install]
WantedBy=default.target
"""
with open(unit_path, "w") as f:
f.write(unit_content)
subprocess.run(["systemctl", "--user", "daemon-reload"], check=True)
subprocess.run(["systemctl", "--user", "enable", "--now", "antratter.service"], check=True)
subprocess.run(["loginctl", "enable-linger", os.environ.get("USER", "")], check=False)
print(f"[OK] ANTRATTER installed as systemd user service: {unit_path}")
print("[OK] Protection starts automatically on boot.")
def _uninstall_linux():
subprocess.run(["systemctl", "--user", "disable", "--now", "antratter.service"], check=False)
unit_path = os.path.expanduser("~/.config/systemd/user/antratter.service")
if os.path.isfile(unit_path):
os.remove(unit_path)
subprocess.run(["systemctl", "--user", "daemon-reload"], check=False)
print("[OK] ANTRATTER removed.")
# ── Windows ────────────────────────────────────────────────────────────────────
def _install_windows():
# Try NSSM first (Non-Sucking Service Manager), fall back to schtasks
nssm = _find_nssm()
if nssm:
_install_windows_nssm(nssm)
else:
_install_windows_schtasks()
def _find_nssm() -> str | None:
for candidate in ["nssm", "nssm.exe", r"C:\nssm\nssm.exe"]:
try:
subprocess.run([candidate, "version"], capture_output=True, check=True)
return candidate
except (FileNotFoundError, subprocess.CalledProcessError):
pass
return None
def _install_windows_nssm(nssm: str):
subprocess.run([nssm, "install", "AntiRatter", _PYTHON,
f'"{_SCRIPT}" protect --auto-quarantine'], check=True)
subprocess.run([nssm, "set", "AntiRatter", "DisplayName", _SVC_DISP], check=True)
subprocess.run([nssm, "set", "AntiRatter", "Start", "SERVICE_AUTO_START"], check=True)
subprocess.run(["sc", "start", "AntiRatter"], check=True)
print("[OK] ANTRATTER installed as Windows Service via NSSM.")
def _install_windows_schtasks():
cmd = (
f'schtasks /create /sc ONLOGON /tn "AntiRatter" /tr '
f'"{_PYTHON} {_SCRIPT} protect --auto-quarantine" '
f'/rl HIGHEST /f'
)
subprocess.run(cmd, shell=True, check=True)
print("[OK] ANTRATTER installed as Scheduled Task (runs on logon).")
def _uninstall_windows():
subprocess.run(["sc", "stop", "AntiRatter"], check=False)
subprocess.run(["sc", "delete", "AntiRatter"], check=False)
subprocess.run(['schtasks', '/delete', '/tn', 'AntiRatter', '/f'], check=False)
print("[OK] ANTRATTER removed.")
# ── Entry point ────────────────────────────────────────────────────────────────
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="ANTRATTER Service Installer")
parser.add_argument("action", choices=["install", "uninstall", "status"])
args = parser.parse_args()
{"install": install, "uninstall": uninstall, "status": status}[args.action]()