|
| 1 | +/** |
| 2 | + * OWASP Benchmark Project |
| 3 | + * |
| 4 | + * This file is part of the Open Web Application Security Project (OWASP) |
| 5 | + * Benchmark Project For details, please see |
| 6 | + * <a href="https://www.owasp.org/index.php/Benchmark">https://www.owasp.org/index.php/Benchmark</a>. |
| 7 | + * |
| 8 | + * The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms |
| 9 | + * of the GNU General Public License as published by the Free Software Foundation, version 2. |
| 10 | + * |
| 11 | + * The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without |
| 12 | + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details |
| 14 | + * |
| 15 | + * @author Dave Wichers <a href="https://www.aspectsecurity.com">Aspect Security</a> |
| 16 | + * @created 2015 |
| 17 | + */ |
| 18 | + |
| 19 | +package org.owasp.benchmark.score.parsers; |
| 20 | + |
| 21 | +import java.io.BufferedReader; |
| 22 | +import java.io.File; |
| 23 | +import java.io.FileReader; |
| 24 | +import java.text.SimpleDateFormat; |
| 25 | +import java.util.ArrayList; |
| 26 | +import java.util.Date; |
| 27 | +import java.util.List; |
| 28 | + |
| 29 | +import org.owasp.benchmark.score.BenchmarkScore; |
| 30 | + |
| 31 | +public class SeczoneReader extends Reader { |
| 32 | + |
| 33 | + public static void main(String[] args) throws Exception { |
| 34 | + File f = new File("seczone.log"); |
| 35 | + SeczoneReader cr = new SeczoneReader(); |
| 36 | + cr.parse(f); |
| 37 | + } |
| 38 | + |
| 39 | + public TestResults parse(File f) throws Exception { |
| 40 | + TestResults tr = new TestResults("VulHunter", true, TestResults.ToolType.IAST); |
| 41 | + |
| 42 | + BufferedReader reader = new BufferedReader(new FileReader(f)); |
| 43 | + String firstLine = null; |
| 44 | + String lastLine = ""; |
| 45 | + String line = ""; |
| 46 | + ArrayList<String> chunk = new ArrayList<String>(); |
| 47 | + String testNumber = "00001"; |
| 48 | + while (line != null) { |
| 49 | + try { |
| 50 | + line = reader.readLine(); |
| 51 | + if (line != null) { |
| 52 | + if ( firstLine == null ) firstLine = line; |
| 53 | + lastLine = line; |
| 54 | + if (line.contains("Accept Request URL====>>") && !line.endsWith(".html")) { |
| 55 | + // ok, we're starting a new URL, so process this one and start the next chunk |
| 56 | + parseVulHunterFinding(tr, testNumber, chunk); |
| 57 | + chunk.clear(); |
| 58 | + testNumber = "00000"; |
| 59 | + String fname = "/" + BenchmarkScore.TESTCASENAME; |
| 60 | + int idx = line.indexOf( fname ); |
| 61 | + if ( idx != -1 ) { |
| 62 | + testNumber = line.substring(idx + fname.length(), idx + fname.length() + 5 ); |
| 63 | + } |
| 64 | + } else if (line.contains("Report BUG===>>>")) { |
| 65 | + chunk.add(line); |
| 66 | + } else if (line.contains("get engine jar")) { |
| 67 | + String versionLine = line.substring(line.indexOf("\\engine-") |
| 68 | + + "\\engine-".length()); |
| 69 | + String version = versionLine.substring(0, versionLine.indexOf(".jar")); |
| 70 | + tr.setToolVersion(version); |
| 71 | + } |
| 72 | + } |
| 73 | + } catch (Exception ex) { |
| 74 | + ex.printStackTrace(); |
| 75 | + } |
| 76 | + } |
| 77 | + //Last |
| 78 | + if(!chunk.isEmpty()){ |
| 79 | + // ok, we're starting a new URL, so process this one and start the next chunk |
| 80 | + parseVulHunterFinding(tr, testNumber, chunk); |
| 81 | + chunk.clear(); |
| 82 | + testNumber = "00000"; |
| 83 | + String fname = "/" + BenchmarkScore.TESTCASENAME; |
| 84 | + int idx = lastLine.indexOf( fname ); |
| 85 | + if ( idx != -1 ) { |
| 86 | + testNumber = lastLine.substring(idx + fname.length(), idx + fname.length() + 5 ); |
| 87 | + } |
| 88 | + } |
| 89 | + reader.close(); |
| 90 | + tr.setTime(calculateTime(firstLine, lastLine)); |
| 91 | + return tr; |
| 92 | + } |
| 93 | + |
| 94 | + private String calculateTime(String firstLine, String lastLine) { |
| 95 | + // Lines start with: PID_8772 | 2020-12-11 19:00:51.370 INFO ... |
| 96 | + try { |
| 97 | + String start = firstLine.split(" ")[3]; |
| 98 | + String stop = lastLine.split(" ")[3]; |
| 99 | + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS"); |
| 100 | + Date startTime = sdf.parse(start); |
| 101 | + Date stopTime = sdf.parse(stop); |
| 102 | + long startMillis = startTime.getTime(); |
| 103 | + long stopMillis = stopTime.getTime(); |
| 104 | + return ((stopMillis - startMillis) / 1000) + " seconds"; |
| 105 | + } catch (Exception e) { |
| 106 | + e.printStackTrace(); |
| 107 | + } |
| 108 | + return null; |
| 109 | + } |
| 110 | + |
| 111 | + private void parseVulHunterFinding(TestResults tr, String testNumber, List<String> chunk) throws Exception { |
| 112 | + for (String line : chunk) { |
| 113 | + TestCaseResult tcr = new TestCaseResult(); |
| 114 | + |
| 115 | + String ruleid = line.substring(line.indexOf("ruleId=\"") + 8, line.length() - 2); |
| 116 | + tcr.setCWE(cweLookup(ruleid)); |
| 117 | + tcr.setCategory(ruleid); |
| 118 | + |
| 119 | + try { |
| 120 | + tcr.setNumber(Integer.parseInt(testNumber)); |
| 121 | + } catch (NumberFormatException e) { |
| 122 | + System.out.println("> Parse error: " + line); |
| 123 | + } |
| 124 | + |
| 125 | + if (tcr.getCWE() != 0) { |
| 126 | + // System.out.println( tcr.getNumber() + "\t" + tcr.getCWE() + "\t" + tcr.getCategory() ); |
| 127 | + tr.put(tcr); |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + private static int cweLookup(String rule) { |
| 133 | + switch (rule) { |
| 134 | + case "cmd-injection"://12432 |
| 135 | + return 78; // command injection |
| 136 | + case "cookie-injection": |
| 137 | + return 0000; // What is this exactly? |
| 138 | + case "content-type-missing": |
| 139 | + return 0000; // Don't care |
| 140 | + case "cookie-missing-httponly": |
| 141 | + return 1004; // insecure cookie use |
| 142 | + case "cookie-missing-secure": |
| 143 | + return 614; // insecure cookie use |
| 144 | + case "crypto-bad-ciphers": |
| 145 | + return 327; // weak encryption |
| 146 | + case "crypto-bad-mac": |
| 147 | + return 328; // weak hash |
| 148 | + case "crypto-weak-randomness": |
| 149 | + return 330; // weak random |
| 150 | + case "csrf": |
| 151 | + return 352; // csrf |
| 152 | + case "header-injection": |
| 153 | + return 113; // header injection |
| 154 | + case "hql-injection": |
| 155 | + return 564; // hql injection |
| 156 | + case "hsts": |
| 157 | + return 319; // CWE-319: Cleartext Transmission of Sensitive Information |
| 158 | + case "ldap-injection": |
| 159 | + return 90; // ldap injection |
| 160 | + case "path-traversal"://19703 |
| 161 | + return 22; // path traversal |
| 162 | + case "reflected-xss"://21290 |
| 163 | + return 79; // xss |
| 164 | + case "reflection-injection": |
| 165 | + return 0000; // reflection injection |
| 166 | + case "referrer-policy-missing": |
| 167 | + return 0000; // Don't care |
| 168 | + case "sensitive-data-flow-tracking": |
| 169 | + return 0000; // Don't care |
| 170 | + case "sensitive-data-response-tracking": |
| 171 | + return 0000; // Don't care |
| 172 | + case "sql-injection"://20501 |
| 173 | + return 89; // sql injection |
| 174 | + case "trust-boundary-violation": |
| 175 | + return 501; // trust boundary |
| 176 | + case "unsafe-readline": |
| 177 | + return 0000; // unsafe readline |
| 178 | + case "unsafe-web-service-call": |
| 179 | + return 0000; // Not sure what this is. |
| 180 | + case "weak-password-db-connection": |
| 181 | + return 0000; // Don't care |
| 182 | + case "x-xss-protection-header-disabled": |
| 183 | + return 0000; // Don't care |
| 184 | + case "xcontenttype-header-missing": |
| 185 | + return 0000; // Don't care |
| 186 | + case "xpath-injection": |
| 187 | + return 643; // xpath injection |
| 188 | + case "xxe": |
| 189 | + return 611; // xml entity |
| 190 | + default: System.out.println("WARNING: VulHunter-Unrecognized finding type: " + rule); |
| 191 | + } |
| 192 | + return 0; |
| 193 | + } |
| 194 | + |
| 195 | +} |
0 commit comments