forked from xFGhoul/PythonProtector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.py
More file actions
115 lines (100 loc) · 3.99 KB
/
Copy pathprocess.py
File metadata and controls
115 lines (100 loc) · 3.99 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
"""
____ ____ __ __
/ __ \\ __ __ / __ \\ _____ ____ / /_ ___ _____ / /_
/ /_/ // / / // /_/ // ___// __ \\ / __// _ \\ / ___// __/
/ ____// /_/ // ____// / / /_/ // /_ / __// /__ / /_
/_/ \\__, //_/ /_/ \\____/ \\__/ \\___/ \\___/ \\__/
/____/
Made With ❤️ By Ghoul & Marci
"""
import os
import time
import psutil
import win32gui
from win32process import GetWindowThreadProcessId
from ..types import Event, Logger
from ..abc import Module
from ..constants import Lists
from ..utils.webhook import Webhook
import contextlib
class AntiProcess(Module):
def __init__(
self, webhook: Webhook, logger: Logger, exit: bool, report: bool, event: Event
) -> None:
self.webhook: Webhook = webhook
self.logger: Logger = logger
self.exit: bool = exit
self.report: bool = report
self.event: Event = event
@property
def name(self) -> str:
return "Anti Process"
@property
def version(self) -> float:
return 1.0
def CheckProcessList(self) -> None:
"""
Checks the Process List for any Blacklisted Programs
"""
while True:
try:
time.sleep(2.0)
for process in psutil.process_iter():
if any(
process_name in process.name().lower()
for process_name in Lists.BLACKLISTED_PROGRAMS
):
try:
if self.report:
self.logger.info(f"{process.name} Process Was Running")
self.webhook.send(
f"`{process.name()}` was detected running on the system.",
self.name,
)
self.event.dispatch(
["process_running", "pyprotector_detect"],
f"{process.name()} was detected running on the system.",
self.name,
process=process,
)
process.kill()
if self.exit:
self.logger.info("Exiting Due to Blacklisted Process")
os._exit(1)
except (psutil.NoSuchProcess, psutil.AccessDenied):
pass
except BaseException:
pass
def CheckWindowNames(self) -> None:
"""Checks Window Names Against Blacklisted List"""
def winEnumHandler(hwnd, _ctx) -> None:
if (
win32gui.GetWindowText(hwnd).lower()
not in Lists.BLACKLISTED_WINDOW_NAMES
):
return
pid: tuple[int, int] = GetWindowThreadProcessId(hwnd)
if isinstance(pid, int):
with contextlib.suppress(BaseException):
psutil.Process(pid).terminate()
else:
for process in pid:
with contextlib.suppress(BaseException):
psutil.Process(process).terminate()
self.logger.info(f"{win32gui.GetWindowText(hwnd)} Found")
if self.report:
self.webhook.send(
f"Debugger {win32gui.GetWindowText(hwnd)}",
self.name,
)
self.event.dispatch(
["window_name_detected", "pyprotector_detect"],
f"Debugger {win32gui.GetWindowText(hwnd)} Found Open",
self.name,
window_name=win32gui.GetWindowText(hwnd),
)
if self.exit:
self.logger.info("Exiting Due to Blacklisted Window Name")
os._exit(1)
while True:
win32gui.EnumWindows(winEnumHandler, None)