CVE-2021-38159: MOVEit Transfer SQL Injection Analysis
The SAML SSO handler in MOVEit Transfer passed values from the SAML response directly into SQL queries without escaping, allowing SQL injection. An attacker could send a crafted SAML response to the SSO callback endpoint and use time-based techniques to extract data.
Published on blog.viettelcybersecurity.com
Moveit Transfer is software for businesses to combine file transfers into one system and is also suitable for encryption in it.
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
MOVEit Transfer is file transfer software that lets a business consolidate its file transfers onto a single system. The vendor's own description, quoted in the write-up, pitches file encryption, tamper-evident logging, activity tracking and centralised access controls, and compliance with SLAs, internal governance requirements and regulations such as PCI, HIPAA, CCPA and GDPR.
The feature under examination is the SSO integration that speaks SAML. Single Sign-On lets a user sign in once and reach several systems without new accounts. SAML is the standard that covers both authentication and authorisation for SSO; the write-up notes that OAuth is the more common standard but only deals with authorisation. The SAML components involved are the User-Agent, the Service Provider and the Identity Provider. When the User-Agent sends the SAML Response from the Identity Provider back to the callback, the Service Provider has to verify it. That verification path is where the bug lives.
Setup
Installation was the first obstacle, and the write-up is candid about it.
- The vendor, Ipswitch, only offers a Full Installer. A new version has to be installed and inserted into the old version rather than applied as a patch.
- The archive contains a bundled version, so it can be downloaded by changing the version in the path.
- The licence can only be used with the latest version. Unpacking the DLLs instead of installing did not work, probably because they had not reversed it properly.
- The analysis stalled because they did not have the right licence version.
Following a suggestion from @jstnkndy, deploying through Azure solved both problems.
The analysis itself was a diff: collect all DLL files, decompile them, and compare against the old version to find the point the vendor patched.
Finding it
The decompile and comparison produced a lot of differences, probably because the versions were quite far apart. A quick look turned up many fixed statements that seemed related to SQL injection, but almost all of them belonged to MoveitApplication, the application part of the system, which requires authentication to reach. That meant every changed statement needed review, not just the ones that looked directly like SQL injection fixes.
Without reviewing all the changes, they found it in midmz.dll. Looking more deeply, they saw that the API related to SSO with SAML has an escape XML step before the process in the next step. That looked like a possible vulnerability.
Diving into the SSO functionality, the server receives the SAML Response and processes it through the Handler. They also noticed that the vendor had implemented the SAML Parser themselves. The parser takes information directly from the Attribute and Element of the XML, which is the returned SAML Response. Because there is no further processing, checking these fields in the database by entering the SQL query directly leads to SQL injection.
Exploitation
What it describes is the shape of the attack and the constraint that shaped it.
Step 1: choose a blind technique
The query returns no additional value and the system returns no error information. The most likely route is therefore a time-based attack.
Step 2: account for the database backend
MOVEit Transfer allows the use of different types of databases, so different payloads are required to detect the injection depending on the backend in use.
Step 3: deliver the payload inside the SAML Response
The payload is inserted and rewritten into the SAML Response, which is then Base64 encoded and sent back to the server at the callback endpoint for SSO.
Root cause
The vendor's own SAML Parser extracts values from the Attribute and Element of the XML in the SAML Response. Those values are then placed into SQL queries directly, with no further processing, which is the injection. The fix in later versions was to escape special values with SILUtility.XHTMLClean().
The write-up also notes that the InResponse value and the Login SSO endpoint were not the only places patched: a lot of other values and locations were fixed as well.
Impact
Because the query returns no additional value and the system returns no error information, the most likely route is a time-based attack: an attacker who can reach the SSO callback and submit a crafted SAML Response can infer data from the database through timing.
On reach, the write-up states that although the vulnerability had been patched for a long time, of more than 2000 websites using the application, maybe at least 600 were still affected.
Fix
Later versions fixed it by using SILUtility.XHTMLClean() to escape special values, and the vendor patched the InResponse value, the Login SSO endpoint and many other values and locations. The write-up describes this as what was changed; it does not propose an alternative remediation.
Variants to test
- Other SAML attributes and elements. The parser reads from Attribute and Element nodes. Try injecting into each attribute name and value, not just the ones the vendor patched, and watch for time delays on the SSO callback. A positive result is a consistent delay that scales with the injected condition.
- Other SSO endpoints. The Login SSO endpoint was patched alongside InResponse. Enumerate the SSO-related handlers and submit crafted Responses to each; a positive result is a delayed response or a behavioural difference between a true and false condition.
- Backend-specific payloads. Since MOVEit Transfer supports several database types, test time-based payloads for each backend family. A positive result is a delay on the backend in use and no delay on the others.
- Other custom parsers in the same product. The vendor wrote its own SAML Parser rather than relying on a hardened library. Look for other hand-rolled XML handling in the same DLLs and check whether extracted values reach queries or other sinks unescaped. A positive result is a value from XML appearing verbatim in a query, log or response.
- Diff-driven review of authenticated code. The write-up notes that most SQL-injection-looking fixes were in MoveitApplication, which needs authentication. With a low-privileged account, review those changed statements for the same missing escaping. A positive result is a parameter that alters query behaviour when supplied with a quote or a time-based condition.
What happened, in plain words
MOVEit Transfer is a piece of software that companies install on their own servers to move files around securely. Instead of each department running its own file-sharing tool, the business puts everything on one system. The vendor's own description, quoted in the write-up, promises file encryption, tamper-evident logging (logs that show if someone tried to alter them), activity tracking and centralised access controls, plus help with meeting SLAs, internal governance rules and regulations such as PCI, HIPAA, CCPA and GDPR.
One feature of MOVEit Transfer is single sign-on (SSO) using a standard called SAML. SSO means a person signs in once, at one place, and then gets into several different systems without creating a new account for each. SAML is the set of rules that lets the systems talk to each other during that sign-in. The researchers looked at this feature and found a SQL injection: a way of sneaking database commands into a place where the software expected ordinary text. The vendor fixed it in later versions, but the write-up says that of more than 2000 websites using the application, maybe at least 600 were still affected long after the patch.
This article walks through how the researchers got there, in the same order they did: setting up the software, comparing old and new versions to spot the fix, understanding the SSO feature, finding the flaw, and working out how an attacker would use it.
The product and the feature under examination
MOVEit Transfer, as described above, is file transfer software for businesses. The part the researchers examined is the SSO integration that speaks SAML.
A few terms first, because they come up constantly:
- Single Sign-On (SSO): sign in once, reach many systems. Think of a building pass that opens the front door, the lift and your floor, instead of a separate key for each.
- SAML: the standard that handles both authentication (proving who you are) and authorisation (deciding what you may do) for SSO. The write-up notes that OAuth is the more common standard, but OAuth only deals with authorisation.
- User-Agent: the browser (or app) on the person's computer.
- Service Provider: the system the person wants to use, here MOVEit Transfer.
- Identity Provider: the system that actually checks the person's identity, for example a company login server.
The flow is simple in outline. The browser goes to the Service Provider, gets sent to the Identity Provider to sign in, and then comes back carrying a SAML Response: a bundle of XML (structured text, like a very formal form) that says who the person is. When the browser sends that SAML Response back to the callback (the address on the Service Provider that is waiting for it), the Service Provider has to verify it. That verification path is where the bug lives.
Setting up the software
Installation was the first obstacle, and the write-up is candid about it.
- The vendor, Ipswitch, only offers a Full Installer. A new version has to be installed and inserted into the old version rather than applied as a patch. A patch is a small update file; a full installer replaces the whole thing.
- The archive contains a bundled version, so it can be downloaded by changing the version in the path. In other words, the download address contains a version number, and editing that number fetches a different build.
- The licence can only be used with the latest version. A licence is the code that proves you paid and are allowed to run the software. Unpacking the DLLs instead of installing did not work, probably because they had not reversed it properly. A DLL is a file of compiled code that the program loads; reversing means taking compiled code apart to read it.
- The analysis stalled because they did not have the right licence version.
Following a suggestion from @jstnkndy, deploying through Azure solved both problems. Azure is a cloud service: instead of installing on their own machine, they deployed through the cloud.
The analysis itself was a diff: collect all DLL files, decompile them, and compare against the old version to find the point the vendor patched. Decompiling turns compiled code back into something readable. Comparing two versions is like comparing two drafts of a document: the changed sentences are where the author did something, and in security the changed sentences are often where a bug was fixed.
Finding it
The decompile and comparison produced a lot of differences, probably because the versions were quite far apart. A quick look turned up many fixed statements that seemed related to SQL injection, but almost all of them belonged to MoveitApplication, the application part of the system, which requires authentication to reach. Authentication here means you must log in first. That meant every changed statement needed review, not just the ones that looked directly like SQL injection fixes, because the interesting change might be hiding among many unrelated ones.
Without reviewing all the changes, they found it in midmz.dll. Looking more deeply, they saw that the API related to SSO with SAML has an escape XML step before the process in the next step. An API is the set of doorways a program offers so other programs can ask it to do things. Escaping means turning characters that have special meaning into harmless text, the way you put quotation marks around a word so it is read as a word and not as an instruction. That escape step looked like a possible vulnerability: if the escaping is missing or wrong, special characters slip through.
Diving into the SSO functionality, the server receives the SAML Response and processes it through the Handler. A handler is the piece of code that receives an incoming request and decides what to do with it. They also noticed that the vendor had implemented the SAML Parser themselves. A parser is the code that reads structured text and pulls out the pieces. The parser takes information directly from the Attribute and Element of the XML, which is the returned SAML Response. Attributes and elements are the labelled fields inside XML, like the boxes on a form. Because there is no further processing, checking these fields in the database by entering the SQL query directly leads to SQL injection.
SQL injection deserves a plain explanation. A database is an organised store of data, and it is queried with a language called SQL. A query looks like a sentence: select this from there where the name is that. If a program builds that sentence by gluing in text supplied by a user, and the user supplies text that itself looks like SQL, the database can be tricked into running the user's words as commands. It is like a form that says "write your name" and someone writes "name, and also open the safe". The program meant to read a name; the database read an instruction.
Exploitation
What it describes is the shape of the attack and the constraint that shaped it.
Step 1: choose a blind technique
The query returns no additional value and the system returns no error information. In other words, the attacker cannot see the answer and cannot see an error message. This is called blind injection. The most likely route is therefore a time-based attack: instead of reading data, the attacker asks the database a yes/no question and measures how long the answer takes. If the condition is true, the database is told to wait; if false, it answers immediately. The delay is the signal, like a prisoner tapping on a wall: you cannot see the message, but you can hear the rhythm.
Step 2: account for the database backend
MOVEit Transfer allows the use of different types of databases, so different payloads are required to detect the injection depending on the backend in use. A payload is the crafted text the attacker sends. Different database products understand slightly different commands, so a payload that makes one wait may do nothing on another.
Step 3: deliver the payload inside the SAML Response
The payload is inserted and rewritten into the SAML Response, which is then Base64 encoded and sent back to the server at the callback endpoint for SSO. Base64 is a way of writing any data using only ordinary letters, digits and a couple of symbols, so it can travel safely through systems that expect text. It is not encryption; anyone can decode it. The attacker takes the SAML Response, edits one of its fields to contain the payload, encodes the whole thing, and posts it to the SSO callback.
Root cause
The vendor's own SAML Parser extracts values from the Attribute and Element of the XML in the SAML Response. Those values are then placed into SQL queries directly, with no further processing, which is the injection. The fix in later versions was to escape special values with SILUtility.XHTMLClean().
SILUtility.XHTMLClean()
This is the name of a function in the vendor's code. A function is a named block of code that does a job; here the job is to clean up text so that special characters cannot act as instructions. Calling it before the value reaches the database is the difference between reading a name and running a command.
The write-up also notes that the InResponse value and the Login SSO endpoint were not the only places patched: a lot of other values and locations were fixed as well.
Impact
Because the query returns no additional value and the system returns no error information, the most likely route is a time-based attack: an attacker who can reach the SSO callback and submit a crafted SAML Response can infer data from the database through timing.
On reach, the write-up states that although the vulnerability had been patched for a long time, of more than 2000 websites using the application, maybe at least 600 were still affected. That gap between patch and deployment is the recurring lesson: a fix only helps once it is installed.
Fix
Later versions fixed it by using SILUtility.XHTMLClean() to escape special values, and the vendor patched the InResponse value, the Login SSO endpoint and many other values and locations. The write-up describes this as what was changed; it does not propose an alternative remediation.
Variants to test
- Other SAML attributes and elements. The parser reads from Attribute and Element nodes. Try injecting into each attribute name and value, not just the ones the vendor patched, and watch for time delays on the SSO callback. A positive result is a consistent delay that scales with the injected condition.
- Other SSO endpoints. The Login SSO endpoint was patched alongside InResponse. Enumerate the SSO-related handlers and submit crafted Responses to each; a positive result is a delayed response or a behavioural difference between a true and false condition.
- Backend-specific payloads. Since MOVEit Transfer supports several database types, test time-based payloads for each backend family. A positive result is a delay on the backend in use and no delay on the others.
- Other custom parsers in the same product. The vendor wrote its own SAML Parser rather than relying on a hardened library. Look for other hand-rolled XML handling in the same DLLs and check whether extracted values reach queries or other sinks unescaped. A sink is any place where data ends up being used, such as a query, a log or a response. A positive result is a value from XML appearing verbatim in a query, log or response.
- Diff-driven review of authenticated code. The write-up notes that most SQL-injection-looking fixes were in MoveitApplication, which needs authentication. With a low-privileged account, review those changed statements for the same missing escaping. A positive result is a parameter that alters query behaviour when supplied with a quote or a time-based condition.
Glossary
- API: the set of doorways a program offers so other programs can ask it to do things.
- Attribute: a labelled field inside XML, like a box on a form.
- Authentication: proving who you are, usually by logging in.
- Authorisation: deciding what a proven user is allowed to do.
- Azure: a cloud service where you can rent machines and services instead of installing everything yourself.
- Base64: a way of writing any data using ordinary characters so it can travel through text-only systems; not encryption.
- Blind injection: an injection where the attacker cannot see the result or an error, so must infer answers indirectly.
- Callback: the address on a system that waits for a response coming back from another system.
- Database: an organised store of data, queried with a language such as SQL.
- Decompile: turn compiled code back into something readable.
- Diff: a comparison between two versions showing what changed.
- DLL: a file of compiled code that a program loads and uses.
- Element: a labelled section inside XML, like a box on a form.
- Escape: turn characters with special meaning into harmless text.
- Function: a named block of code that does a job.
- Handler: the piece of code that receives an incoming request and decides what to do with it.
- Identity Provider: the system that checks a person's identity during SSO.
- Licence: the code that proves you are allowed to run the software.
- OAuth: a common standard for authorisation only.
- Parser: code that reads structured text and pulls out the pieces.
- Patch: a small update file that fixes or changes part of a program.
- Payload: the crafted text an attacker sends.
- Reversing: taking compiled code apart to understand it.
- SAML: a standard for SSO that covers both authentication and authorisation.
- SAML Response: the XML bundle an Identity Provider sends back saying who the user is.
- Service Provider: the system the user wants to use, here MOVEit Transfer.
- Single Sign-On (SSO): sign in once and reach several systems without new accounts.
- Sink: any place where data ends up being used, such as a query, a log or a response.
- SQL: the language used to query a database.
- Time-based attack: inferring answers by measuring how long the database takes to respond.
- XML: structured text with labelled fields, used to carry data between systems.