def do_exit(self, argv): """Quit current shell interface SYNOPSIS: exit [--force] OPTIONS: --force When called to leave the framework, this option forces exit, avoiding warning message if current session has not been saved to a file, or has changed since last save. DESCRIPTION: If current phpsploit session is connected to $TARGET, this command disconnects the user from remote session. Otherwise, if the interface is not connected, this command leaves the phpsploit framework. """ if len(argv) == 2 and argv[1] == "--force": force_exit = True elif len(argv) == 1: force_exit = False else: self.interpret("help exit") return False if not self.stdout.isatty() and not self.stdin.isatty(): force_exit = True if self.bind_command: self.bind_command = None elif tunnel: tunnel.close() else: if not force_exit: try: session_changed = session.diff(None) except OSError: session_changed = bool(tunnel.has_been_active()) if session_changed: msg = "Do you really want to exit without saving session ?" if ui.input.Expect(False)(msg): return False exit() return True # make pylint happy
def do_exit(self, argv): """Quit current shell interface SYNOPSIS: exit [--force] OPTIONS: --force When called to leave the framework, this option forces exit, avoiding warning message if current session has not been saved to a file, or has changed since last save. DESCRIPTION: If current phpsploit session is connected to $TARGET, this command disconnects the user from remote session. Otherwise, if the interface is not connected, this command leaves the phpsploit framework. """ if len(argv) == 2 and argv[1] == "--force": force_exit = True elif len(argv) == 1: force_exit = False else: self.interpret("help exit") if self.binded_command: self.binded_command = None elif tunnel: tunnel.close() else: if force_exit is False: try: session_changed = session.diff(None) except OSError: if tunnel.has_been_active(): session_changed = True else: session_changed = False if session_changed: msg = "Do you really want to exit without saving session ?" if ui.input.Expect(False)(msg): return False exit()
def do_exit(self, argv): """Exit Omega Framework. USAGE: exit OPTIONS: --force When called to leave the framework, this option forces exit, avoiding warning message if current session has not been saved to a file, or has changed since last save. DESCRIPTION: If current Omega session is connected to target, this command disconnects the user from remote session. Otherwise, if the interface is not connected, this command leaves the Omega Framework. """ if len(argv) == 2 and argv[1] == "--force": force_exit = True elif len(argv) == 1: force_exit = False else: self.interpret("help exit") return False if self.bind_command: self.bind_command = None elif tunnel: tunnel.close() else: if not force_exit: try: session_changed = session.diff(None) except OSError: session_changed = bool(tunnel.has_been_active()) exit() return True # make pylint happy
def do_session(self, argv): """phpsploit session handler SYNOPSIS: session [load|diff] [<FILE>] session save [-f] [<FILE>] session upgrade DESCRIPTION: The `session` core command handles phpsploit sessions. Sessions can be considered as phpsploit instances. They handle current configuration settings, environment vars, command aliases, and remote tunnel attributes (if any). USAGE: * session [<FILE>] Show a nice colored representation of FILE session content. If unset, FILE is implicly set to current instance's session. * session diff [<FILE>] Shows a textual representation of the differences between FILE and current session state. If FILE is not set, $SAVEFILE setting is used. If $SAVEFILE is not set, the session's state when framework started is used as comparator. * session save [-f] [<FILE>] Dumps the current session instance into the given file. If FILE is unset, then the session is saved to $SAVEFILE setting, if $SAVEFILE does not exist, then the file path "$SAVEPATH/phpsploit.session" is implicitly used. NOTE: The '-f' option, is used, saves the session without asking user confirmation is file already exists. * session load [<FILE>] Try to load <FILE> as the current session. If unset, FILE is implicitly set to "./phpsploit.session". * session upgrade If current session file is in v1-compatible mode, the request handler is limited to POST method and does not supports multi request and stealth modules. This command shall be used to upgrade current session AFTER you upgraded the remote $TARGET with new-style phpsploit backdoor (which can be obtained with `exploit --get-backdoor` command). EXAMPLES: > session load /tmp/phpsploit.session - Load /tmp/phpsploit.session. > session save - Save current state to session's source file ($SAVEFILE). WARNING: The `session load` action can't be used through a remote shell session. If it is the case, run `exit` to disconnect from remote server before launching this command. """ # prevent argv IndexError argv += [None, None] # session save [<FILE>] if argv[1] == 'save': if argv[2] == '-f': path = argv[3] ask_confirmation = False else: path = argv[2] ask_confirmation = True session.dump(path, ask_confirmation=ask_confirmation) path = session.File if path is None else path session.File = path print("[*] Session saved into %r" % path) # session load [<FILE>] elif argv[1] == 'load': try: session.update(argv[2], update_history=True) print("[#] Session file correctly loaded") except: print("[#] Could not load session file") raise # session diff [<FILE>] elif argv[1] == 'diff': session.diff(argv[2], display_diff=True) # session upgrade elif argv[1] == 'upgrade': if "id" in session.Compat: print("[*] You are about to upgrade phpsploit session.") print("[*] Please ensure that you have correctly upgraded") print("[*] the remote backdoor into target URL.") print("[*] After session upgrade, phpsploit assumes that") print("[*] an up-to-date backdoor is active on $TARGET.") cancel = ui.input.Expect(False) if not cancel("Do you really want to upgrade session now ?"): session.Compat = {} print("[*] Session correctly upgraded") else: print("[-] Session upgrade aborted") else: print("[-] Session already up-to-date") # sesion [<FILE>] else: print(session(argv[1]))
def do_session(self, argv): """phpsploit session handler SYNOPSIS: session [load|diff] [<FILE>] session save [-f] [<FILE>] session upgrade DESCRIPTION: The `session` core command handles phpsploit sessions. Sessions can be considered as phpsploit instances. They handle current configuration settings, environment vars, command aliases, and remote tunnel attributes (if any). USAGE: * session [<FILE>] Show a nice colored representation of FILE session content. If unset, FILE is implicly set to current instance's session. * session diff [<FILE>] Shows a textual representation of the differences between FILE and current session state. If FILE is not set, $SAVEFILE setting is used. If $SAVEFILE is not set, the session's state when framework started is used as comparator. * session save [-f] [<FILE>] Dumps the current session instance into the given file. If FILE is unset, then the session is saved to $SAVEFILE setting, if $SAVEFILE does not exist, then the file path "$SAVEPATH/phpsploit.session" is implicitly used. NOTE: The '-f' option, is used, saves the session without asking user confirmation is file already exists. * session load [<FILE>] Try to load <FILE> as the current session. If unset, FILE is implicitly set to "./phpsploit.session". * session upgrade If current session file is in v1-compatible mode, the request handler is limited to POST method and does not supports multi request and stealth modules. This command shall be used to upgrade current session AFTER you upgraded the remote $TARGET with new-style phpsploit backdoor (which can be obtained with `exploit --get-backdoor` command). EXAMPLES: > session load /tmp/phpsploit.session - Load /tmp/phpsploit.session. > session save - Save current state to session's source file ($SAVEFILE). WARNING: The `session load` action can't be used through a remote shell session. If it is the case, run `exit` to disconnect from remote server before launching this command. """ # prevent argv IndexError argv += [None, None] # session save [<FILE>] if argv[1] == 'save': if argv[2] == '-f': return session.dump(argv[3], ask_confirmation=False) else: return session.dump(argv[2]) # session load [<FILE>] elif argv[1] == 'load': try: session.update(argv[2], update_history=True) print("[#] Session file correctly loaded") except: print("[#] Could not load session file") raise # session diff [<FILE>] elif argv[1] == 'diff': session.diff(argv[2], display_diff=True) # session upgrade elif argv[1] == 'upgrade': if "id" in session.Compat: print("[*] You are about to upgrade phpsploit session.") print("[*] Please ensure that you have correctly upgraded") print("[*] the remote backdoor into target URL.") print("[*] After session upgrade, phpsploit assumes that") print("[*] an up-to-date backdoor is active on $TARGET.") cancel = ui.input.Expect(False) if not cancel("Do you really want to upgrade session now ?"): session.Compat = {} print("[*] Session correctly upgraded") else: print("[-] Session upgrade aborted") else: print("[-] Session already up-to-date") # sesion [<FILE>] else: print(session(argv[1]))
def do_session(argv): """phpsploit session handler SYNOPSIS: session [load|diff] [<FILE>] session save [-f] [<FILE>] session upgrade DESCRIPTION: The `session` core command handles phpsploit sessions. Sessions can be considered as phpsploit instances. They handle current configuration settings, environment vars, command aliases, and remote tunnel attributes (if any). They can be saved to a file for further use. USAGE: * session [<FILE>] Show a nice colored representation of FILE session content. If called without argument, current session if displayed. * session diff [<FILE>] Show a textual representation of the differences between FILE and current session. If FILE is not set, the diff between session's original and current states if shown. * session save [-f] [<FILE>] Save current session state in FILE. If FILE is not set, the session is saved to it's original path location. It still not bound to a file, default location is '$SAVEPATH/phpsploit.session'. NOTE: The '-f' option, if used, saves the session without asking user confirmation if file already exists. * session load [<FILE>] Try to load session from FILE. It unset, try to load session from './phpsploit.session' * session upgrade If current session file is in v1-compatible mode, the request handler is limited to POST method and does not supports multi request and stealth modules. This command shall be used to upgrade current session AFTER you upgraded the remote $TARGET with new-style phpsploit backdoor (which can be obtained with `exploit --get-backdoor` command). EXAMPLES: > session load /tmp/phpsploit.session - Load /tmp/phpsploit.session. > session save - Save current state to session file. WARNING: The `session load` action can't be used through a remote shell session. If it is the case, run `exit` to disconnect from remote server before launching this command. """ # prevent argv IndexError argv += [None, None] # session save [<FILE>] if argv[1] == 'save': if argv[2] == '-f': path = argv[3] ask_confirmation = False else: path = argv[2] ask_confirmation = True session.dump(path, ask_confirmation=ask_confirmation) path = session.File if path is None else path session.File = path print("[*] Session saved into %r" % path) # session load [<FILE>] elif argv[1] == 'load': try: session.update(argv[2], update_history=True) print("[#] Session file correctly loaded") except: print("[#] Could not load session file") raise # session diff [<FILE>] elif argv[1] == 'diff': session.diff(argv[2], display_diff=True) # session upgrade elif argv[1] == 'upgrade': if "id" in session.Compat: print("[*] You are about to upgrade phpsploit session.") print("[*] Please ensure that you have correctly upgraded") print("[*] the remote backdoor into target URL.") print("[*] After session upgrade, phpsploit assumes that") print("[*] an up-to-date backdoor is active on $TARGET.") cancel = ui.input.Expect(False) if not cancel("Do you really want to upgrade session now ?"): session.Compat = {} print("[*] Session correctly upgraded") else: print("[-] Session upgrade aborted") else: print("[-] Session already up-to-date") # sesion [<FILE>] else: print(session(argv[1]))
def do_session(argv): """phpsploit session handler SYNOPSIS: session [load|diff] [<FILE>] session save [-f] [<FILE>] session upgrade DESCRIPTION: The `session` core command handles phpsploit sessions. Sessions can be considered as phpsploit instances. They handle current configuration settings, environment vars, command aliases, and remote tunnel attributes (if any). They can be saved to a file for further use. USAGE: * session [<FILE>] Show a nice colored representation of FILE session content. If called without argument, current session if displayed. * session diff [<FILE>] Show a textual representation of the differences between FILE and current session. If FILE is not set, the diff between session's original and current states if shown. * session save [-f] [<FILE>] Save current session state in FILE. If FILE is not set, the session is saved to it's original path location. It still not bound to a file, default location is '$SAVEPATH/phpsploit.session'. NOTE: The '-f' option, if used, saves the session without asking user confirmation if file already exists. * session load [<FILE>] Try to load session from FILE. It unset, try to load session from './phpsploit.session' * session upgrade If current session file is in v1-compatible mode, the request handler is limited to POST method and does not supports multi request and stealth modules. This command shall be used to upgrade current session AFTER you upgraded the remote $TARGET with new-style phpsploit backdoor (which can be obtained with `exploit --get-backdoor` command). EXAMPLES: > session load /tmp/phpsploit.session - Load /tmp/phpsploit.session. > session save - Save current state to session file. WARNING: `session load` should NEVER be used while still connected to a remote TARGET. If you want to load another session, first run `exit` to disconnect from remote server. """ # prevent argv IndexError argv += [None, None] # session save [<FILE>] if argv[1] == 'save': if argv[2] == '-f': path = argv[3] ask_confirmation = False else: path = argv[2] ask_confirmation = True session.dump(path, ask_confirmation=ask_confirmation) path = session.File if path is None else path session.File = path print("[*] Session saved into %r" % path) # session load [<FILE>] elif argv[1] == 'load': try: session.update(argv[2], update_history=True) print("[#] Session file correctly loaded") except: print("[#] Could not load session file") raise # session diff [<FILE>] elif argv[1] == 'diff': session.diff(argv[2], display_diff=True) # session upgrade elif argv[1] == 'upgrade': if "id" in session.Compat: print("[*] You are about to upgrade phpsploit session.") print("[*] Please ensure that you have correctly upgraded") print("[*] the remote backdoor into target URL.") print("[*] After session upgrade, phpsploit assumes that") print("[*] an up-to-date backdoor is active on $TARGET.") cancel = ui.input.Expect(False) if not cancel("Do you really want to upgrade session now ?"): session.Compat = {} print("[*] Session correctly upgraded") else: print("[-] Session upgrade aborted") else: print("[-] Session already up-to-date") # sesion [<FILE>] else: print(session(argv[1]))