|
| 1 | +// Score ZAP against WAVSEP |
| 2 | + |
| 3 | +var DIR = "/zap/wrk/res/"; |
| 4 | +var IGNORE_PATHS = []; |
| 5 | + |
| 6 | +// Polyfill for Nashorn c/o https://stackoverflow.com/questions/47543566/scriptengine-javascript-doesnt-support-includes |
| 7 | +if (!Array.prototype.includes) { |
| 8 | + Object.defineProperty(Array.prototype, 'includes', { |
| 9 | + value: function(valueToFind, fromIndex) { |
| 10 | + if (this == null) { |
| 11 | + throw new TypeError('\"this\" is null or not defined'); |
| 12 | + } |
| 13 | + var o = Object(this); |
| 14 | + var len = o.length >>> 0; |
| 15 | + if (len === 0) { return false; } |
| 16 | + var n = fromIndex | 0; |
| 17 | + var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); |
| 18 | + function sameValueZero(x, y) { return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y)); } |
| 19 | + while (k < len) { if (sameValueZero(o[k], valueToFind)) { return true; } k++; } return false; |
| 20 | + } |
| 21 | + }); |
| 22 | +} |
| 23 | + |
| 24 | +var totalUrls; |
| 25 | +var totalAlerts; |
| 26 | + |
| 27 | +var FileWriter = Java.type('java.io.FileWriter'); |
| 28 | +var PrintWriter = Java.type('java.io.PrintWriter'); |
| 29 | + |
| 30 | +root = org.parosproxy.paros.model.Model.getSingleton(). |
| 31 | + getSession().getSiteTree().getRoot(); |
| 32 | + |
| 33 | +function nodeHasAlert(node, rules) { |
| 34 | + var alerts = node.getAlerts(); |
| 35 | + for (var a in alerts) { |
| 36 | + var pluginId = alerts.get(a).getPluginId(); |
| 37 | + if (rules.includes(pluginId)) { |
| 38 | + return pluginId; |
| 39 | + } |
| 40 | + } |
| 41 | + return null; |
| 42 | +} |
| 43 | + |
| 44 | +function listChildren(pw, node, type, rules) { |
| 45 | + var j; |
| 46 | + for (j=0;j<node.getChildCount();j++) { |
| 47 | + var child = node.getChildAt(j); |
| 48 | + if (child.getChildCount() == 0) { |
| 49 | + var path = child.getHierarchicNodeName(); |
| 50 | + if (path.indexOf(type) > -1 && path.indexOf("Case") > -1) { |
| 51 | + // All good |
| 52 | + } else { |
| 53 | + continue; |
| 54 | + } |
| 55 | + if (path.indexOf("POST") > -1 && child.getNodeName().startsWith("GET")) { |
| 56 | + continue; |
| 57 | + } |
| 58 | + if (! IGNORE_PATHS.includes(path)) { |
| 59 | + totalUrls++; |
| 60 | + pw.println('- path: ' + path); |
| 61 | + var pluginId = nodeHasAlert(child, rules); |
| 62 | + // Following test is JS equiv of XOR |
| 63 | + if (path.indexOf("FalsePositives") > 0 ? !pluginId : pluginId) { |
| 64 | + totalAlerts++; |
| 65 | + pw.println(' result: Pass'); |
| 66 | + pw.println(' rule: ' + pluginId); |
| 67 | + } else { |
| 68 | + pw.println(' result: FAIL'); |
| 69 | + pw.println(' rule: ' + rules[0]); |
| 70 | + } |
| 71 | + } |
| 72 | + } else { |
| 73 | + listChildren(pw, child, type, rules); |
| 74 | + } |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +function scoreChildren(file, name, type, rules) { |
| 79 | + var YAML_FILE = DIR + "/" + file + ".yml"; |
| 80 | + var fw = new FileWriter(YAML_FILE); |
| 81 | + var pw = new PrintWriter(fw); |
| 82 | + |
| 83 | + pw.println('section: ' + name); |
| 84 | + pw.println('url: ' + type); |
| 85 | + pw.println('details:'); |
| 86 | + |
| 87 | + totalUrls = 0; |
| 88 | + totalAlerts = 0; |
| 89 | + |
| 90 | + |
| 91 | + listChildren(pw, root, type, rules); |
| 92 | + |
| 93 | + pw.println('tests: ' + totalUrls); |
| 94 | + pw.println('passes: ' + totalAlerts); |
| 95 | + pw.println('fails: ' + (totalUrls - totalAlerts)); |
| 96 | + pw.println('score: ' + Math.round(totalAlerts * 100 / totalUrls) + '%'); |
| 97 | + |
| 98 | + pw.close(); |
| 99 | +} |
| 100 | + |
| 101 | +scoreChildren("dom-xss-get-exp", "DOM XSS GET Experimental", "/DXSS-Detection-Evaluation-GET-Experimental/", [40026]); |
| 102 | + |
| 103 | +scoreChildren("lfi-get-200-err", "Local File Include GET 200 Error", "/LFI-Detection-Evaluation-GET-200Error/", [6]); |
| 104 | +scoreChildren("lfi-get-200-id", "Local File Include GET 200 Identical", "/LFI-Detection-Evaluation-GET-200Identical/", [6]); |
| 105 | +scoreChildren("lfi-get-200-valid", "Local File Include GET 200 Valid", "/LFI-Detection-Evaluation-GET-200Valid/", [6]); |
| 106 | +scoreChildren("lfi-get-302-redir", "Local File Include GET 302 Redirect", "/LFI-Detection-Evaluation-GET-302Redirect/", [6]); |
| 107 | +scoreChildren("lfi-get-400-err", "Local File Include GET 404 Error", "/LFI-Detection-Evaluation-GET-404Error/", [6]); |
| 108 | +scoreChildren("lfi-get-500-err", "Local File Include GET 500 Error", "/LFI-Detection-Evaluation-GET-500Error/", [6]); |
| 109 | +scoreChildren("lfi-post-200-err", "Local File Include POST 200 Error", "/LFI-Detection-Evaluation-POST-200Error/", [6]); |
| 110 | +scoreChildren("lfi-post-200-id", "Local File Include POST 200 Identical", "/LFI-Detection-Evaluation-POST-200Identical/", [6]); |
| 111 | +scoreChildren("lfi-post-200-valid", "Local File Include POST 200 Valid", "/LFI-Detection-Evaluation-POST-200Valid/", [6]); |
| 112 | +scoreChildren("lfi-post-302-redir", "Local File Include POST 302 Redirect", "/LFI-Detection-Evaluation-POST-302Redirect/", [6]); |
| 113 | +scoreChildren("lfi-post-404-err", "Local File Include POST 404 Error", "/LFI-Detection-Evaluation-POST-404Error/", [6]); |
| 114 | +scoreChildren("lfi-post-500-err", "Local File Include POST 500 Error", "/LFI-Detection-Evaluation-POST-500Error/", [6]); |
| 115 | +scoreChildren("lfi-get-fp", "Local File Include GET False Positives ", "/LFI-FalsePositives-GET/", [6]); |
| 116 | + |
| 117 | +scoreChildren("rfi-get-200-err", "Remote File Include GET 200 Error", "/RFI-Detection-Evaluation-GET-200Error/", [7]); |
| 118 | +scoreChildren("rfi-get-200-id", "Remote File Include GET 200 Identical", "/RFI-Detection-Evaluation-GET-200Identical/", [7]); |
| 119 | +scoreChildren("rfi-get-200-valid", "Remote File Include GET 200 Valid", "/RFI-Detection-Evaluation-GET-200Valid/", [7]); |
| 120 | +scoreChildren("rfi-get-302-redir", "Remote File Include GET 302 Redirect", "/RFI-Detection-Evaluation-GET-302Redirect/", [7]); |
| 121 | +scoreChildren("rfi-get-404-err", "Remote File Include GET 404 Error", "/RFI-Detection-Evaluation-GET-404Error/", [7]); |
| 122 | +scoreChildren("rfi-get-500-err", "Remote File Include GET 500 Error", "/RFI-Detection-Evaluation-GET-500Error/", [7]); |
| 123 | +scoreChildren("rfi-post-200-err", "Remote File Include POST 200 Error", "/RFI-Detection-Evaluation-POST-200Error/", [7]); |
| 124 | +scoreChildren("rfi-post-200-id", "Remote File Include POST 200 Identical", "/RFI-Detection-Evaluation-POST-200Identical/", [7]); |
| 125 | +scoreChildren("rfi-post-200-valid", "Remote File Include POST 200 Valid", "/RFI-Detection-Evaluation-POST-200Valid/", [7]); |
| 126 | +scoreChildren("rfi-post-302-redir", "Remote File Include POST 302 Redirect", "/RFI-Detection-Evaluation-POST-302Redirect/", [7]); |
| 127 | +scoreChildren("rfi-post-400-err", "Remote File Include POST 404 Error", "/RFI-Detection-Evaluation-POST-404Error/", [7]); |
| 128 | +scoreChildren("rfi-post-402-err", "Remote File Include POST 500 Error", "/RFI-Detection-Evaluation-POST-500Error/", [7]); |
| 129 | +scoreChildren("rfi-get-fp", "Remote File Include GET False Positives", "/RFI-FalsePositives-GET/", [7]); |
| 130 | + |
| 131 | +scoreChildren("rxss-cookie-exp", "Reflected XSS Cookie Experimental", "/RXSS-Detection-Evaluation-COOKIE-Experimental/", [40012]); |
| 132 | +scoreChildren("rxss-get", "Reflected XSS GET", "/RXSS-Detection-Evaluation-GET/", [40012]); |
| 133 | +scoreChildren("rxss-get-exp", "Reflected XSS GET Experimental", "/RXSS-Detection-Evaluation-GET-Experimental/", [40012]); |
| 134 | +scoreChildren("rxss-post", "Reflected XSS POST", "/RXSS-Detection-Evaluation-POST/", [40012]); |
| 135 | +scoreChildren("rxss-post-exp", "Reflected XSS POST Experimental", "/RXSS-Detection-Evaluation-POST-Experimental/", [40012]); |
| 136 | +scoreChildren("rxss-fps", "Reflected XSS GET False Positives", "/RXSS-FalsePositives-GET/", [40012]); |
| 137 | + |
| 138 | +scoreChildren("sqli-get-200-err", "SQL Injection GET 200 Error", "/SInjection-Detection-Evaluation-GET-200Error/", [40018]); |
| 139 | +scoreChildren("sqli-get-200-err-exp", "SQL Injection GET 200 Error Experimental", "/SInjection-Detection-Evaluation-GET-200Error-Experimental/", [40018]); |
| 140 | +scoreChildren("sqli-get-200-id", "SQL Injection GET 200 Identical", "/SInjection-Detection-Evaluation-GET-200Identical/", [40018]); |
| 141 | +scoreChildren("sqli-get-200-valid", "SQL Injection GET 200 Valid", "/SInjection-Detection-Evaluation-GET-200Valid/", [40018]); |
| 142 | +scoreChildren("sqli-get-500-err", "SQL Injection GET 500 Error", "/SInjection-Detection-Evaluation-GET-500Error/", [40018]); |
| 143 | +scoreChildren("sqli-post-200-err", "SQL Injection POST 200 Error", "/SInjection-Detection-Evaluation-POST-200Error/", [40018]); |
| 144 | +scoreChildren("sqli-post-200-err-exp", "SQL Injection POST 200 Error Experimental", "/SInjection-Detection-Evaluation-POST-200Error-Experimental/", [40018]); |
| 145 | +scoreChildren("sqli-post-200-id", "SQL Injection POST 200 Identical", "/SInjection-Detection-Evaluation-POST-200Identical/", [40018]); |
| 146 | +scoreChildren("sqli-post-200-valid", "SQL Injection POST 200 Valid", "/SInjection-Detection-Evaluation-POST-200Valid/", [40018]); |
| 147 | +scoreChildren("sqli-post-500-err", "SQL Injection POST 500 Error", "/SInjection-Detection-Evaluation-POST-500Error/", [40018]); |
| 148 | +scoreChildren("sqli-get-fp", "SQL Injection GET False Positives", "/SInjection-FalsePositives-GET/", [40018]); |
| 149 | + |
| 150 | +scoreChildren("redir-get-302", "Unvalidated Redirect GET 200", "/Redirect-Detection-Evaluation-GET-302Redirect/", [20019]); |
| 151 | +scoreChildren("redir-post-302", "Unvalidated Redirect POST 302", "/Redirect-Detection-Evaluation-POST-302Redirect/", [20019]); |
| 152 | +scoreChildren("redir-get-fp", "Unvalidated Redirect GET False Positives", "/Redirect-FalsePositives-GET/", [20019]); |
| 153 | +scoreChildren("redir-get-200-valid", "Unvalidated Redirect GET 200 Valid", "/Redirect-JavaScript-Detection-Evaluation-GET-200Valid/", [20019]); |
| 154 | +scoreChildren("redir-post-200-valid", "Unvalidated Redirect POST 200 Valid", "/Redirect-JavaScript-Detection-Evaluation-POST-200Valid/", [20019]); |
| 155 | + |
| 156 | +print('Done'); |
0 commit comments