forked from xFGhoul/PythonProtector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhook.py
More file actions
111 lines (88 loc) · 3.61 KB
/
Copy pathwebhook.py
File metadata and controls
111 lines (88 loc) · 3.61 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
"""
____ ____ __ __
/ __ \\ __ __ / __ \\ _____ ____ / /_ ___ _____ / /_
/ /_/ // / / // /_/ // ___// __ \\ / __// _ \\ / ___// __/
/ ____// /_/ // ____// / / /_/ // /_ / __// /__ / /_
/_/ \\__, //_/ /_/ \\____/ \\__/ \\___/ \\___/ \\__/
/____/
Made With ❤️ By Ghoul & Marci
"""
import io
from PIL import ImageGrab
from base64 import b64decode
from typing import Optional, List
from discord_webhook import DiscordEmbed, DiscordWebhook
from ..constants import EmbedConfig, LoggingInfo, UserInfo
class Webhook:
def __init__(
self, webhook_url: str, logs_path: str, screenshot: Optional[bool]
) -> None:
self.webhook_url: str = webhook_url
self.logs_path: str = logs_path
self.screenshot: bool = screenshot if screenshot else False
def TakeScreenshot(self) -> bytes:
"""
Take a screenshot of the entire screen and convert it to a byte array
Returns:
A byte array of the screenshot.
"""
screenshot = ImageGrab.grab(
bbox=None, include_layered_windows=False, all_screens=True, xdisplay=None
)
screenshot_bytes_array = io.BytesIO()
screenshot.save(screenshot_bytes_array, format="PNG")
screenshot_bytes_array = screenshot_bytes_array.getvalue()
return screenshot_bytes_array
def DecryptLogs(self) -> str:
"""
Decrypts Logs File
Returns:
The decrypted logs file.
"""
with open(self.logs_path, "r") as logs_file:
decrypted_logs_file = io.StringIO()
lines: List[str] = logs_file.readlines()
for line in lines:
if not line.strip():
continue
encrypted_message: str = line.split(" ")[4]
encoded_message: bytes = b64decode(encrypted_message.encode("latin1"))
decrypted_message: str = LoggingInfo.CIPHER.decrypt(
encoded_message
).decode("utf-8")
line: str = line.replace(encrypted_message, decrypted_message)
decrypted_logs_file.write(f"{line}\n")
return decrypted_logs_file.getvalue()
def send(self, content: str, module: str) -> None:
"""
It sends a webhook to a discord channel with the user's username, IP, and a screenshot of the user's
screen.
Args:
content (str): The content of the message
module (str): The module that the user is using.
"""
webhook: DiscordWebhook = DiscordWebhook(
self.webhook_url, rate_limit_retry=True
)
webhook.add_file(
file=self.DecryptLogs().encode("utf-8"),
filename=f"{UserInfo.USERNAME}-[Security].log",
)
embed: DiscordEmbed = DiscordEmbed(
title=EmbedConfig.TITLE, color=EmbedConfig.COLOR
)
if self.screenshot:
webhook.add_file(file=self.TakeScreenshot(), filename="screenshot.jpg")
embed.set_image(url="attachment://screenshot.jpg")
embed.add_embed_field(name="User", value=UserInfo.USERNAME, inline=True)
embed.add_embed_field(name="IP", value=UserInfo.IP, inline=True)
embed.add_embed_field(name="Module", value=module, inline=True)
embed.set_timestamp()
embed.set_description(content)
embed.set_thumbnail(url=EmbedConfig.ICON)
embed.set_footer(
text=f"PythonProtector | {EmbedConfig.VERSION}",
icon_url=EmbedConfig.ICON,
)
webhook.add_embed(embed)
webhook.execute()