예제 #1
0
def main():
    global plugins

    signal.signal(signal.SIGINT, signal_handler)

    description = (
        'Using our plugin you can do different actions in the command line\n'
        'and interact with Faraday. Faraday comes with some presets for bulk\n'
        'actions such as object removal, get object information, etc.\n'
        'Any parameter not recognized by fplugin, or everything after -- will be passed on \n'
        'to the called script.\n')

    epilog = 'Available scripts:\n'

    plugins = fplugin_utils.get_available_plugins()

    for plugin in sorted(plugins.keys()):
        epilog += '\t- %s: %s\n' % (plugin, plugins[plugin]['description'])

    parser = argparse.ArgumentParser(
        description=description,
        epilog=epilog,
        formatter_class=RawDescriptionAndDefaultsHelpFormatter)

    group = parser.add_mutually_exclusive_group()

    group.add_argument('command',
                       nargs='?',
                       help='Command to execute. Example: ./fplugin getAllIps')
    group.add_argument('-i',
                       '--interactive',
                       action='store_true',
                       help='Run in interactive mode')

    parser.add_argument('-w',
                        '--workspace',
                        help='Workspace to use',
                        default=CONF.getLastWorkspace())

    parser.add_argument(
        '-u',
        '--url',
        help='Faraday Server URL. Example: http://localhost:5985',
        default='http://localhost:5985')

    parser.add_argument('--username', required=True)

    parser.add_argument('--password', required=True)

    # Only parse known args. Unknown ones will be passed on the the called script
    args, unknown = parser.parse_known_args()

    # print("""\nTo login please provide your valid DB Credentials.\n""")
    # username = raw_input('Username: '******'Password: '******'tab: complete')
        atexit.register(readline.write_history_file, histfile)

        try:
            readline.read_history_file(histfile)
            # default history len is -1 (infinite), which may grow unruly
            readline.set_history_length(1000)
        except IOError:
            pass

        print("Welcome to interactive Faraday!")
        print("Press CTRL-D or run 'exit' to quit interactive mode.")
        last_id = None

        while True:
            try:
                line = input("> ")

                if line.strip() == 'exit':
                    os._exit(0)

                # Split line read from stdin into argv
                new_args = shlex.split(line)
                new_args += [
                    '--username', args.username, '--password', args.password
                ]

                if '-i' in new_args or '--interactive' in new_args:
                    print('Already in interactive mode!')
                    continue

                if 'h' in new_args or 'help' in new_args:
                    parser.print_help()
                    continue

                if FPLUGIN_INTERACTIVE_LAST_TOKEN in new_args:
                    i = new_args.index(FPLUGIN_INTERACTIVE_LAST_TOKEN)
                    new_args[i] = last_id or ''

                parsed_args, new_unknown = parser.parse_known_args(new_args)
                parsed_args.interactive = True

                last_id = dispatch(parsed_args, new_unknown,
                                   parser.format_help(), args.username,
                                   args.password) or last_id
                # print '$last = %s' % last_id
            except (EOFError, KeyboardInterrupt):
                print('Bye Bye!')
                sys.exit(0)
            except SystemExit:
                pass
예제 #2
0
    def do_startup(self):
        """
        GTK calls this method after Gtk.Application.run()
        Creates instances of the sidebar, terminal, console log and
        statusbar to be added to the app window.
        Sets up necesary actions on menu and toolbar buttons
        Also reads the .xml file from menubar.xml
        """
        Gtk.Application.do_startup(self)  # deep GTK magic

        self.serverIO = ServerIO(CONF.getLastWorkspace())
        self.serverIO.continously_check_server_connection()

        self.ws_sidebar = WorkspaceSidebar(self.serverIO,
                                           self.change_workspace,
                                           self.remove_workspace,
                                           self.on_new_button,
                                           CONF.getLastWorkspace())

        # the dummy values here will be updated as soon as the ws is loaded.
        self.hosts_sidebar = HostsSidebar(self.show_host_info,
                                          self.serverIO.get_hosts,
                                          self.serverIO.get_host, self.icons)
        self.sidebar = Sidebar(self.ws_sidebar.get_box(),
                               self.hosts_sidebar.get_box())

        host_count, service_count, vuln_count = 0, 0, 0  # dummy values
        self.terminal = Terminal(CONF)
        self.console_log = ConsoleLog()
        self.statusbar = Statusbar(self.on_click_notifications,
                                   self.on_click_conflicts, host_count,
                                   service_count, vuln_count)

        self.notificationsModel = Gtk.ListStore(str)

        action_to_method = {
            "about": self.on_about,
            "quit": self.on_quit,
            "preferences": self.on_preferences,
            "pluginOptions": self.on_plugin_options,
            "faradayPlugin": self.on_faraday_plugin,
            "new": self.on_new_button,
            "new_terminal": self.on_new_terminal_button,
            "open_report": self.on_open_report_button,
            "go_to_web_ui": self.on_click_go_to_web_ui_button,
            "go_to_documentation": self.on_help_dispatch,
            "go_to_faq": self.on_help_dispatch,
            "go_to_troubleshooting": self.on_help_dispatch,
            "go_to_demos": self.on_help_dispatch,
            "go_to_issues": self.on_help_dispatch,
            "go_to_forum": self.on_help_dispatch,
            "go_to_irc": self.on_help_dispatch,
            "go_to_twitter": self.on_help_dispatch,
            "go_to_googlegroup": self.on_help_dispatch
        }

        for action, method in action_to_method.items():
            gio_action = Gio.SimpleAction.new(action, None)
            gio_action.connect("activate", method)
            self.add_action(gio_action)

        dirname = os.path.dirname(os.path.abspath(__file__))
        builder = Gtk.Builder.new_from_file(dirname + '/menubar.xml')
        builder.connect_signals(self)
        appmenu = builder.get_object('appmenu')
        self.set_app_menu(appmenu)

        topmenu = Gio.Menu()
        pluginmenu = Gio.Menu()

        topmenu.append('Faraday Plugin...', 'app.faradayPlugin')

        plugins = fplugin_utils.get_available_plugins()

        for plugin in sorted(plugins.keys()):
            gio_action = Gio.SimpleAction.new('fplugin_%s' % plugin, None)
            gio_action.connect("activate", self.type_faraday_plugin_command)
            self.add_action(gio_action)

            item = Gio.MenuItem.new(plugins[plugin]['prettyname'],
                                    'app.fplugin_%s' % plugin)

            pluginmenu.append_item(item)

        fmenu = Gio.Menu()

        fmenu.append_section(None, topmenu)
        fmenu.append_section(None, pluginmenu)

        appmenu.insert_submenu(1, "Faraday Plugin", fmenu)

        helpMenu = builder.get_object('Help')
        self.set_menubar(helpMenu)