Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/linux/manage/pseudo_shell.rb
Views: 11704
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'readline'67class MetasploitModule < Msf::Post8include Msf::Post::File9include Msf::Post::Unix10include Msf::Post::Linux::System11include Msf::Post::Linux::Priv1213HELP_COMMANDS = [14['help', 'help', 0, 'Show current help'],15['?', 'help', 0, 'Show current help'],16['ls', 'dir', 1, 'List files and folders in a directory'],17['cat', 'read_file', 1, 'Show file contents'],18['whoami', 'whoami', 0, 'Show current user'],19['cd', 'cd', 1, 'Change current directory'],20['users', 'get_users', 0, 'Show list of users'],21['groups', 'get_groups', 0, 'Show list of groups'],22['pwd', 'pwd', 0, 'Show current PATH'],23['interfaces', 'interfaces', 0, 'Show list of network interfaces'],24['path', 'get_path', 0, 'Show current directories included in $PATH enviroment variable'],25['macs', 'macs', 0, 'Show list of MAC addresses'],26['shell', 'get_shell_name', 0, 'Show current SHELL'],27['hostname', 'get_hostname', 0, 'Show current Hostname'],28['ips', 'ips', 0, 'Show list of current IP addresses'],29['isroot?', 'is_root?', 0, 'Show if current user has root permisions'],30['exit', '', 0, 'Exit the Pseudo-shell'],31['tcp_ports', 'listen_tcp_ports', 0, 'Show list of listen TCP ports'],32['udp_ports', 'listen_udp_ports', 0, 'Show list of listen UDP ports'],33['clear', 'clear_screen', 0, 'Clear screen']34].sort3536LIST = [].sort37HELP_COMMANDS.each do |linea|38LIST.insert(-1, linea[0])39end4041def initialize42super(43'Name' => 'Pseudo-Shell Post-Exploitation Module',44'Description' => %q{45This module will run a Pseudo-Shell.46},47'Author' => 'Alberto Rafael Rodriguez Iglesias <albertocysec[at]gmail.com>',48'License' => MSF_LICENSE,49'Platform' => ['linux'],50'SessionTypes' => ['shell', 'meterpreter']51)52end5354def run55@vhostname = get_hostname56@vusername = whoami57@vpromptchar = is_root? ? '#' : '$'58prompt59end6061def parse_cmd(cmd)62parts = cmd.split(' ')63return '' unless parts.length >= 16465cmd = parts[0]66nargs = parts.length - 167HELP_COMMANDS.each do |linea|68next unless linea[0] == cmd6970func = linea[1]71if nargs >= 172if linea[2] == 173args = parts[1]74else75nargs = 076end77else78args = ''79end8081return func, cmd, args, nargs82end8384error = get_shell_name85message = "#{error}: #{cmd}: Command does not exist\n"86print message87message88end8990def help91print "\n"92print "Commands Help\n"93print "==============\n"94print "\n"95printf("\t%-20s%-100s\n", 'Command', 'Description')96printf("\t%-20s%-100s\n", '-------', '-----------')97HELP_COMMANDS.each do |linea|98printf("\t%-20s%-100s\n", linea[0], linea[3])99end100print "\n"101end102103def prompt_show104promptshell = "#{@vusername}@#{@vhostname}:#{pwd.strip}#{@vpromptchar} "105comp = proc { |s| LIST.grep(/^#{Regexp.escape(s)}/) }106Readline.completion_append_character = ' '107Readline.completion_proc = comp108input = Readline.readline(promptshell, true)109return nil if input.nil?110111input112end113114def prompt115while (input = prompt_show)116break if input == 'exit'117break if input == 'exit '118119begin120func, command, args, nargs = parse_cmd(input)121nargs = nargs.to_i122if command == 'ls' && (nargs == 0)123nargs += 1124ruta = pwd125args = ruta126end127if nargs > 0128args = args.strip129resultado = public_send(func.to_s, args.to_s)130elsif input == ''131resultado = []132resultado.insert(-1, '')133else134resultado = public_send(func.to_s)135end136if !resultado.nil? == resultado137if command == 'isroot?'138print resultado ? "true\n" : "false\n"139end140elsif resultado.instance_of?(Array)141print resultado.join("\n")142print "\n"143elsif resultado.strip != ''144print resultado.chomp + "\n"145end146rescue StandardError # begin147next148end149end150end151end152153154