# SAML Injection > SAML (Security Assertion Markup Language) is an open standard for exchanging authentication and authorization data between parties, in particular, between an identity provider and a service provider. While SAML is widely used to facilitate single sign-on (SSO) and other federated authentication scenarios, improper implementation or misconfiguration can expose systems to various vulnerabilities. ## Summary * [Tools](#tools) * [Methodology](#methodology) * [Invalid Signature](#invalid-signature) * [Signature Stripping](#signature-stripping) * [XML Signature Wrapping Attacks](#xml-signature-wrapping-attacks) * [XML Comment Handling](#xml-comment-handling) * [XML External Entity](#xml-external-entity) * [Extensible Stylesheet Language Transformation](#extensible-stylesheet-language-transformation) * [References](#references) ## Tools - [CompassSecurity/SAMLRaider](https://github.com/SAMLRaider/SAMLRaider) - SAML2 Burp Extension. - [ZAP Addon/SAML Support](https://www.zaproxy.org/docs/desktop/addons/saml-support/) - Allows to detect, show, edit, and fuzz SAML requests. ## Methodology A SAML Response should contain the ` [...]accepting unsigned SAML assertions is accepting a username without checking the password - @ilektrojohn The goal is to forge a well formed SAML Assertion without signing it. For some default configurations if the signature section is omitted from a SAML response, then no signature verification is performed. Example of SAML assertion where `NameID=admin` without signature. ```xml REDACTED REDACTED admin WLS_SP urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport ``` ### XML Signature Wrapping Attacks XML Signature Wrapping (XSW) attack, some implementations check for a valid signature and match it to a valid assertion, but do not check for multiple assertions, multiple signatures, or behave differently depending on the order of assertions. - **XSW1**: Applies to SAML Response messages. Add a cloned unsigned copy of the Response after the existing signature. - **XSW2**: Applies to SAML Response messages. Add a cloned unsigned copy of the Response before the existing signature. - **XSW3**: Applies to SAML Assertion messages. Add a cloned unsigned copy of the Assertion before the existing Assertion. - **XSW4**: Applies to SAML Assertion messages. Add a cloned unsigned copy of the Assertion within the existing Assertion. - **XSW5**: Applies to SAML Assertion messages. Change a value in the signed copy of the Assertion and adds a copy of the original Assertion with the signature removed at the end of the SAML message. - **XSW6**: Applies to SAML Assertion messages. Change a value in the signed copy of the Assertion and adds a copy of the original Assertion with the signature removed after the original signature. - **XSW7**: Applies to SAML Assertion messages. Add an “Extensions” block with a cloned unsigned assertion. - **XSW8**: Applies to SAML Assertion messages. Add an “Object” block containing a copy of the original assertion with the signature removed. In the following example, these terms are used. - **FA**: Forged Assertion - **LA**: Legitimate Assertion - **LAS**: Signature of the Legitimate Assertion ```xml Attacker Legitimate User ``` In the Github Enterprise vulnerability, this request would verify and create a sessions for `Attacker` instead of `Legitimate User`, even if `FA` is not signed. ### XML Comment Handling A threat actor who already has authenticated access into a SSO system can authenticate as another user without that individual’s SSO password. This [vulnerability](https://www.bleepstatic.com/images/news/u/986406/attacks/Vulnerabilities/SAML-flaw.png) has multiple CVE in the following libraries and products. - OneLogin - python-saml - CVE-2017-11427 - OneLogin - ruby-saml - CVE-2017-11428 - Clever - saml2-js - CVE-2017-11429 - OmniAuth-SAML - CVE-2017-11430 - Shibboleth - CVE-2018-0489 - Duo Network Gateway - CVE-2018-7340 Researchers have noticed that if an attacker inserts a comment inside the username field in such a way that it breaks the username, the attacker might gain access to a legitimate user's account. ```xml https://idp.com/ user@user.com.evil.com ``` Where `user@user.com` is the first part of the username, and `.evil.com` is the second. ### XML External Entity An alternative exploitation would use `XML entities` to bypass the signature verification, since the content will not change, except during XML parsing. In the following example: - `&s;` will resolve to the string `"s"` - `&f1;` will resolve to the string `"f1"` ```xml ]> [...] &s;taf&f1; [...] ``` The SAML response is accepted by the service provider. Due to the vulnerability, the service provider application reports "taf" as the value of the "uid" attribute. ### Extensible Stylesheet Language Transformation An XSLT can be carried out by using the `transform` element. ![http://sso-attacks.org/images/4/49/XSLT1.jpg](http://sso-attacks.org/images/4/49/XSLT1.jpg) Picture from [http://sso-attacks.org/XSLT_Attack](http://sso-attacks.org/XSLT_Attack) ```xml ... ... ``` ## References - [Attacking SSO: Common SAML Vulnerabilities and Ways to Find Them - Jem Jensen - March 7, 2017](https://blog.netspi.com/attacking-sso-common-saml-vulnerabilities-ways-find/) - [How to Hunt Bugs in SAML; a Methodology - Part I - Ben Risher (@epi052) - March 7, 2019](https://epi052.gitlab.io/notes-to-self/blog/2019-03-07-how-to-test-saml-a-methodology/) - [How to Hunt Bugs in SAML; a Methodology - Part II - Ben Risher (@epi052) - March 13, 2019](https://epi052.gitlab.io/notes-to-self/blog/2019-03-13-how-to-test-saml-a-methodology-part-two/) - [How to Hunt Bugs in SAML; a Methodology - Part III - Ben Risher (@epi052) - March 16, 2019](https://epi052.gitlab.io/notes-to-self/blog/2019-03-16-how-to-test-saml-a-methodology-part-three/) - [On Breaking SAML: Be Whoever You Want to Be - Juraj Somorovsky, Andreas Mayer, Jorg Schwenk, Marco Kampmann, and Meiko Jensen - August 23, 2012](https://www.usenix.org/system/files/conference/usenixsecurity12/sec12-final91-8-23-12.pdf) - [Oracle Weblogic - Multiple SAML Vulnerabilities (CVE-2018-2998/CVE-2018-2933) - Denis Andzakovic - July 18, 2018](https://pulsesecurity.co.nz/advisories/WebLogic-SAML-Vulnerabilities) - [SAML Burp Extension - Roland Bischofberger - July 24, 2015](https://blog.compass-security.com/2015/07/saml-burp-extension/) - [SAML Security Cheat Sheet - OWASP - February 2, 2019](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/SAML_Security_Cheat_Sheet.md) - [The road to your codebase is paved with forged assertions - Ioannis Kakavas (@ilektrojohn) - March 13, 2017](http://www.economyofmechanism.com/github-saml) - [Truncation of SAML Attributes in Shibboleth 2 - redteam-pentesting.de - January 15, 2018](https://www.redteam-pentesting.de/de/advisories/rt-sa-2017-013/-truncation-of-saml-attributes-in-shibboleth-2) - [Vulnerability Note VU#475445 - Garret Wassermann - February 27, 2018](https://www.kb.cert.org/vuls/id/475445/)